util: Add RBD specific options in clusterInfo

As the netNamespaceFilePath can be separate for
both cephfs and rbd adding the netNamespaceFilePath
path for RBD, This will help us to keep RBD and
CephFS specific options separately.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit 766346868e)
This commit is contained in:
Madhu Rajanna 2022-04-18 11:27:04 +05:30 committed by mergify[bot]
parent 61ca06148e
commit 76398d6887
6 changed files with 38 additions and 28 deletions

View File

@ -25,7 +25,8 @@ serviceAccounts:
# monitors: # monitors:
# - "<MONValue1>" # - "<MONValue1>"
# - "<MONValue2>" # - "<MONValue2>"
# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net" # rbd:
# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net"
csiConfig: [] csiConfig: []
# Configuration details of clusterID,PoolID and FscID mapping # Configuration details of clusterID,PoolID and FscID mapping

View File

@ -20,10 +20,10 @@ kind: ConfigMap
# NOTE: Make sure you don't add radosNamespace option to a currently in use # NOTE: Make sure you don't add radosNamespace option to a currently in use
# configuration as it will cause issues. # configuration as it will cause issues.
# The field "cephFS.subvolumeGroup" is optional and defaults to "csi". # The field "cephFS.subvolumeGroup" is optional and defaults to "csi".
# The <netNamespaceFilePath#> fields are the various network namespace # The "rbd.netNamespaceFilePath" fields are the various network namespace
# path for the Ceph cluster identified by the <cluster-id>, This will be used # path for the Ceph cluster identified by the <cluster-id>, This will be used
# by the CSI plugin to execute the rbd map/unmap and mount -t commands in the # by the RBD CSI plugin to execute the rbd map/unmap in the
# network namespace specified by the <netNamespaceFilePath#>. # network namespace specified by the "rbd.netNamespaceFilePath".
# If a CSI plugin is using more than one Ceph cluster, repeat the section for # If a CSI plugin is using more than one Ceph cluster, repeat the section for
# each such cluster in use. # each such cluster in use.
# NOTE: Changes to the configmap is automatically updated in the running pods, # NOTE: Changes to the configmap is automatically updated in the running pods,
@ -43,7 +43,9 @@ data:
{ {
"clusterID": "<cluster-id>", "clusterID": "<cluster-id>",
"radosNamespace": "<rados-namespace>", "radosNamespace": "<rados-namespace>",
"netNamespaceFilePath": "<kubeletRootPath>/plugins/rbd.csi.ceph.com/net", "rbd": {
"netNamespaceFilePath": "<kubeletRootPath>/plugins/rbd.csi.ceph.com/net",
},
"monitors": [ "monitors": [
"<MONValue1>", "<MONValue1>",
"<MONValue2>", "<MONValue2>",

View File

@ -126,11 +126,6 @@ func (ns *NodeServer) NodeStageVolume(
} }
defer volOptions.Destroy() defer volOptions.Destroy()
volOptions.NetNamespaceFilePath, err = util.GetNetNamespaceFilePath(util.CsiConfigFile, volOptions.ClusterID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
mnt, err := mounter.New(volOptions) mnt, err := mounter.New(volOptions)
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed to create mounter for volume %s: %v", volID, err) log.ErrorLog(ctx, "failed to create mounter for volume %s: %v", volID, err)

View File

@ -332,7 +332,7 @@ func (ns *NodeServer) NodeStageVolume(
} }
defer rv.Destroy() defer rv.Destroy()
rv.NetNamespaceFilePath, err = util.GetNetNamespaceFilePath(util.CsiConfigFile, rv.ClusterID) rv.NetNamespaceFilePath, err = util.GetRBDNetNamespaceFilePath(util.CsiConfigFile, rv.ClusterID)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }

View File

@ -49,8 +49,12 @@ type ClusterInfo struct {
// SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes // SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes
SubvolumeGroup string `json:"subvolumeGroup"` SubvolumeGroup string `json:"subvolumeGroup"`
} `json:"cephFS"` } `json:"cephFS"`
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string `json:"netNamespaceFilePath"` // RBD Contains RBD specific options
RBD struct {
// symlink filepath for the network namespace where we need to execute commands.
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
} `json:"rbd"`
} }
// Expected JSON structure in the passed in config file is, // Expected JSON structure in the passed in config file is,
@ -164,11 +168,11 @@ func GetClusterID(options map[string]string) (string, error) {
return clusterID, nil return clusterID, nil
} }
func GetNetNamespaceFilePath(pathToConfig, clusterID string) (string, error) { func GetRBDNetNamespaceFilePath(pathToConfig, clusterID string) (string, error) {
cluster, err := readClusterInfo(pathToConfig, clusterID) cluster, err := readClusterInfo(pathToConfig, clusterID)
if err != nil { if err != nil {
return "", err return "", err
} }
return cluster.NetNamespaceFilePath, nil return cluster.RBD.NetNamespaceFilePath, nil
} }

View File

@ -140,7 +140,7 @@ func TestCSIConfig(t *testing.T) {
} }
} }
func TestGetNetNamespaceFilePath(t *testing.T) { func TestGetRBDNetNamespaceFilePath(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []struct {
name string name string
@ -148,17 +148,17 @@ func TestGetNetNamespaceFilePath(t *testing.T) {
want string want string
}{ }{
{ {
name: "get NetNamespaceFilePath for cluster-1", name: "get RBD NetNamespaceFilePath for cluster-1",
clusterID: "cluster-1", clusterID: "cluster-1",
want: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net", want: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net",
}, },
{ {
name: "get NetNamespaceFilePath for cluster-2", name: "get RBD NetNamespaceFilePath for cluster-2",
clusterID: "cluster-2", clusterID: "cluster-2",
want: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net", want: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net",
}, },
{ {
name: "when NetNamespaceFilePath is empty", name: "when RBD NetNamespaceFilePath is empty",
clusterID: "cluster-3", clusterID: "cluster-3",
want: "", want: "",
}, },
@ -166,14 +166,22 @@ func TestGetNetNamespaceFilePath(t *testing.T) {
csiConfig := []ClusterInfo{ csiConfig := []ClusterInfo{
{ {
ClusterID: "cluster-1", ClusterID: "cluster-1",
Monitors: []string{"ip-1", "ip-2"}, Monitors: []string{"ip-1", "ip-2"},
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net", RBD: struct {
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
}{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net",
},
}, },
{ {
ClusterID: "cluster-2", ClusterID: "cluster-2",
Monitors: []string{"ip-3", "ip-4"}, Monitors: []string{"ip-3", "ip-4"},
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net", RBD: struct {
NetNamespaceFilePath string `json:"netNamespaceFilePath"`
}{
NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net",
},
}, },
{ {
ClusterID: "cluster-3", ClusterID: "cluster-3",
@ -193,14 +201,14 @@ func TestGetNetNamespaceFilePath(t *testing.T) {
ts := tt ts := tt
t.Run(ts.name, func(t *testing.T) { t.Run(ts.name, func(t *testing.T) {
t.Parallel() t.Parallel()
got, err := GetNetNamespaceFilePath(tmpConfPath, ts.clusterID) got, err := GetRBDNetNamespaceFilePath(tmpConfPath, ts.clusterID)
if err != nil { if err != nil {
t.Errorf("GetNetNamespaceFilePath() error = %v", err) t.Errorf("GetRBDNetNamespaceFilePath() error = %v", err)
return return
} }
if got != ts.want { if got != ts.want {
t.Errorf("GetNetNamespaceFilePath() = %v, want %v", got, ts.want) t.Errorf("GetRBDNetNamespaceFilePath() = %v, want %v", got, ts.want)
} }
}) })
} }