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:
# - "<MONValue1>"
# - "<MONValue2>"
# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net"
# rbd:
# netNamespaceFilePath: "{{ .kubeletDir }}/plugins/{{ .driverName }}/net"
csiConfig: []
# 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
# configuration as it will cause issues.
# 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
# by the CSI plugin to execute the rbd map/unmap and mount -t commands in the
# network namespace specified by the <netNamespaceFilePath#>.
# 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": "<cluster-id>",
"radosNamespace": "<rados-namespace>",
"netNamespaceFilePath": "<kubeletRootPath>/plugins/rbd.csi.ceph.com/net",
"rbd": {
"netNamespaceFilePath": "<kubeletRootPath>/plugins/rbd.csi.ceph.com/net",
},
"monitors": [
"<MONValue1>",
"<MONValue2>",

View File

@ -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)

View File

@ -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())
}

View File

@ -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
}

View File

@ -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)
}
})
}