From 76398d688702e1e8fb3e8530a0bea61f5d2ba1b9 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 18 Apr 2022 11:27:04 +0530 Subject: [PATCH] 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 (cherry picked from commit 766346868e61db4639d80494cc3f2fb2ed2fc6c2) --- charts/ceph-csi-rbd/values.yaml | 3 ++- examples/csi-config-map-sample.yaml | 10 +++++---- internal/cephfs/nodeserver.go | 5 ----- internal/rbd/nodeserver.go | 2 +- internal/util/csiconfig.go | 12 ++++++---- internal/util/csiconfig_test.go | 34 ++++++++++++++++++----------- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/charts/ceph-csi-rbd/values.yaml b/charts/ceph-csi-rbd/values.yaml index d00238448..825412459 100644 --- a/charts/ceph-csi-rbd/values.yaml +++ b/charts/ceph-csi-rbd/values.yaml @@ -25,7 +25,8 @@ serviceAccounts: # monitors: # - "" # - "" -# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net" +# rbd: +# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net" csiConfig: [] # Configuration details of clusterID,PoolID and FscID mapping diff --git a/examples/csi-config-map-sample.yaml b/examples/csi-config-map-sample.yaml index eddab8f9a..2e59ab6b2 100644 --- a/examples/csi-config-map-sample.yaml +++ b/examples/csi-config-map-sample.yaml @@ -20,10 +20,10 @@ kind: ConfigMap # NOTE: Make sure you don't add radosNamespace option to a currently in use # configuration as it will cause issues. # The field "cephFS.subvolumeGroup" is optional and defaults to "csi". -# The fields are the various network namespace +# The "rbd.netNamespaceFilePath" fields are the various network namespace # path for the Ceph cluster identified by the , This will be used -# by the CSI plugin to execute the rbd map/unmap and mount -t commands in the -# network namespace specified by the . +# by the RBD CSI plugin to execute the rbd map/unmap in the +# network namespace specified by the "rbd.netNamespaceFilePath". # If a CSI plugin is using more than one Ceph cluster, repeat the section for # each such cluster in use. # NOTE: Changes to the configmap is automatically updated in the running pods, @@ -43,7 +43,9 @@ data: { "clusterID": "", "radosNamespace": "", - "netNamespaceFilePath": "/plugins/rbd.csi.ceph.com/net", + "rbd": { + "netNamespaceFilePath": "/plugins/rbd.csi.ceph.com/net", + }, "monitors": [ "", "", diff --git a/internal/cephfs/nodeserver.go b/internal/cephfs/nodeserver.go index b7c10db55..21457ff38 100644 --- a/internal/cephfs/nodeserver.go +++ b/internal/cephfs/nodeserver.go @@ -126,11 +126,6 @@ func (ns *NodeServer) NodeStageVolume( } 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) if err != nil { log.ErrorLog(ctx, "failed to create mounter for volume %s: %v", volID, err) diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index 579f2c211..3ac153f44 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -332,7 +332,7 @@ func (ns *NodeServer) NodeStageVolume( } defer rv.Destroy() - rv.NetNamespaceFilePath, err = util.GetNetNamespaceFilePath(util.CsiConfigFile, rv.ClusterID) + rv.NetNamespaceFilePath, err = util.GetRBDNetNamespaceFilePath(util.CsiConfigFile, rv.ClusterID) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/internal/util/csiconfig.go b/internal/util/csiconfig.go index a6e3dd534..0eb3c021b 100644 --- a/internal/util/csiconfig.go +++ b/internal/util/csiconfig.go @@ -49,8 +49,12 @@ type ClusterInfo struct { // SubvolumeGroup contains the name of the SubvolumeGroup for CSI volumes SubvolumeGroup string `json:"subvolumeGroup"` } `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, @@ -164,11 +168,11 @@ func GetClusterID(options map[string]string) (string, error) { return clusterID, nil } -func GetNetNamespaceFilePath(pathToConfig, clusterID string) (string, error) { +func GetRBDNetNamespaceFilePath(pathToConfig, clusterID string) (string, error) { cluster, err := readClusterInfo(pathToConfig, clusterID) if err != nil { return "", err } - return cluster.NetNamespaceFilePath, nil + return cluster.RBD.NetNamespaceFilePath, nil } diff --git a/internal/util/csiconfig_test.go b/internal/util/csiconfig_test.go index 22ceadef2..edecc83d9 100644 --- a/internal/util/csiconfig_test.go +++ b/internal/util/csiconfig_test.go @@ -140,7 +140,7 @@ func TestCSIConfig(t *testing.T) { } } -func TestGetNetNamespaceFilePath(t *testing.T) { +func TestGetRBDNetNamespaceFilePath(t *testing.T) { t.Parallel() tests := []struct { name string @@ -148,17 +148,17 @@ func TestGetNetNamespaceFilePath(t *testing.T) { want string }{ { - name: "get NetNamespaceFilePath for cluster-1", + name: "get RBD NetNamespaceFilePath for cluster-1", clusterID: "cluster-1", 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", 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", want: "", }, @@ -166,14 +166,22 @@ func TestGetNetNamespaceFilePath(t *testing.T) { csiConfig := []ClusterInfo{ { - ClusterID: "cluster-1", - Monitors: []string{"ip-1", "ip-2"}, - NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net", + ClusterID: "cluster-1", + Monitors: []string{"ip-1", "ip-2"}, + RBD: struct { + NetNamespaceFilePath string `json:"netNamespaceFilePath"` + }{ + NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster1-net", + }, }, { - ClusterID: "cluster-2", - Monitors: []string{"ip-3", "ip-4"}, - NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net", + ClusterID: "cluster-2", + Monitors: []string{"ip-3", "ip-4"}, + RBD: struct { + NetNamespaceFilePath string `json:"netNamespaceFilePath"` + }{ + NetNamespaceFilePath: "/var/lib/kubelet/plugins/rbd.ceph.csi.com/cluster2-net", + }, }, { ClusterID: "cluster-3", @@ -193,14 +201,14 @@ func TestGetNetNamespaceFilePath(t *testing.T) { ts := tt t.Run(ts.name, func(t *testing.T) { t.Parallel() - got, err := GetNetNamespaceFilePath(tmpConfPath, ts.clusterID) + got, err := GetRBDNetNamespaceFilePath(tmpConfPath, ts.clusterID) if err != nil { - t.Errorf("GetNetNamespaceFilePath() error = %v", err) + t.Errorf("GetRBDNetNamespaceFilePath() error = %v", err) return } if got != ts.want { - t.Errorf("GetNetNamespaceFilePath() = %v, want %v", got, ts.want) + t.Errorf("GetRBDNetNamespaceFilePath() = %v, want %v", got, ts.want) } }) }