From 809f53cb84512c405cb5aef796b19cf9d73a47d3 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Wed, 5 Jun 2024 11:04:58 +0530 Subject: [PATCH] util: add GetCephFSRadosNamespace method This commit adds `GetCephFSRadosNamespace` util method that returns the `RadosNamespace` specified in ceph-csi-config ConfigMap under cephFS.radosNamespace. If not specified, the method returns the default RadosNamespace i.e, csi. Signed-off-by: Praveen M --- deploy/csi-config-map-sample.yaml | 4 ++++ internal/rbd/group/volume_group.go | 2 +- internal/rbd/manager.go | 2 +- internal/rbd/rbd_util.go | 6 +++--- internal/util/csiconfig.go | 20 ++++++++++++++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/deploy/csi-config-map-sample.yaml b/deploy/csi-config-map-sample.yaml index e0263a0d8..059804ec3 100644 --- a/deploy/csi-config-map-sample.yaml +++ b/deploy/csi-config-map-sample.yaml @@ -32,6 +32,9 @@ kind: ConfigMap # The "cephFS.fuseMountOptions" fields are common separated mount options # for `Ceph FUSE driver`. Setting this will override the fusemountoptions # command line flag. +# The "cephFS.radosNamespace" is optional and represents a radosNamespace in the +# metadata pool. If any given, the omap data of cephFS will be stored within +# this radosNamespace. # network namespace specified by the "cephFS.netNamespaceFilePath". # The "nfs.netNamespaceFilePath" fields are the various network namespace # path for the Ceph cluster identified by the , This will be used @@ -79,6 +82,7 @@ data: "netNamespaceFilePath": "/plugins/cephfs.csi.ceph.com/net", "kernelMountOptions": "", "fuseMountOptions": "" + "radosNamespace": "" } "nfs": { "netNamespaceFilePath": "/plugins/nfs.csi.ceph.com/net", diff --git a/internal/rbd/group/volume_group.go b/internal/rbd/group/volume_group.go index 6e6e59019..984369a08 100644 --- a/internal/rbd/group/volume_group.go +++ b/internal/rbd/group/volume_group.go @@ -98,7 +98,7 @@ func GetVolumeGroup( return nil, fmt.Errorf("failed to get MONs for cluster id %q: %w", csiID.ClusterID, err) } - namespace, err := util.GetRadosNamespace(util.CsiConfigFile, csiID.ClusterID) + namespace, err := util.GetRBDRadosNamespace(util.CsiConfigFile, csiID.ClusterID) if err != nil { return nil, fmt.Errorf("failed to get RADOS namespace for cluster id %q: %w", csiID.ClusterID, err) } diff --git a/internal/rbd/manager.go b/internal/rbd/manager.go index 3c41afdc6..144e6f282 100644 --- a/internal/rbd/manager.go +++ b/internal/rbd/manager.go @@ -99,7 +99,7 @@ func (mgr *rbdManager) getVolumeGroupJournal(clusterID string) (journal.VolumeGr return nil, fmt.Errorf("failed to find MONs for cluster %q: %w", clusterID, err) } - ns, err := util.GetRadosNamespace(util.CsiConfigFile, clusterID) + ns, err := util.GetRBDRadosNamespace(util.CsiConfigFile, clusterID) if err != nil { return nil, fmt.Errorf("failed to find the RADOS namespace for cluster %q: %w", clusterID, err) } diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index a69b0e632..67ffcaf8b 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -1013,7 +1013,7 @@ func genSnapFromSnapID( } rbdSnap.JournalPool = rbdSnap.Pool - rbdSnap.RadosNamespace, err = util.GetRadosNamespace(util.CsiConfigFile, rbdSnap.ClusterID) + rbdSnap.RadosNamespace, err = util.GetRBDRadosNamespace(util.CsiConfigFile, rbdSnap.ClusterID) if err != nil { return nil, err } @@ -1124,7 +1124,7 @@ func generateVolumeFromVolumeID( return rbdVol, err } - rbdVol.RadosNamespace, err = util.GetRadosNamespace(util.CsiConfigFile, rbdVol.ClusterID) + rbdVol.RadosNamespace, err = util.GetRBDRadosNamespace(util.CsiConfigFile, rbdVol.ClusterID) if err != nil { return rbdVol, err } @@ -1323,7 +1323,7 @@ func genVolFromVolumeOptions( return nil, err } - rbdVol.RadosNamespace, err = util.GetRadosNamespace(util.CsiConfigFile, rbdVol.ClusterID) + rbdVol.RadosNamespace, err = util.GetRBDRadosNamespace(util.CsiConfigFile, rbdVol.ClusterID) if err != nil { return nil, err } diff --git a/internal/util/csiconfig.go b/internal/util/csiconfig.go index 6d3e7109a..afe910cfa 100644 --- a/internal/util/csiconfig.go +++ b/internal/util/csiconfig.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/ceph/ceph-csi/api/deploy/kubernetes" + fsutil "github.com/ceph/ceph-csi/internal/cephfs/util" ) const ( @@ -96,8 +97,8 @@ func Mons(pathToConfig, clusterID string) (string, error) { return strings.Join(cluster.Monitors, ","), nil } -// GetRadosNamespace returns the namespace for the given clusterID. -func GetRadosNamespace(pathToConfig, clusterID string) (string, error) { +// GetRBDRadosNamespace returns the namespace for the given clusterID. +func GetRBDRadosNamespace(pathToConfig, clusterID string) (string, error) { cluster, err := readClusterInfo(pathToConfig, clusterID) if err != nil { return "", err @@ -106,6 +107,21 @@ func GetRadosNamespace(pathToConfig, clusterID string) (string, error) { return cluster.RBD.RadosNamespace, nil } +// GetCephFSRadosNamespace returns the namespace for the given clusterID. +// If not set, it returns the default value "csi". +func GetCephFSRadosNamespace(pathToConfig, clusterID string) (string, error) { + cluster, err := readClusterInfo(pathToConfig, clusterID) + if err != nil { + return "", err + } + + if cluster.CephFS.RadosNamespace == "" { + return fsutil.RadosNamespace, nil + } + + return cluster.CephFS.RadosNamespace, nil +} + // GetRBDMirrorDaemonCount returns the number of mirror daemon count for the // given clusterID. func GetRBDMirrorDaemonCount(pathToConfig, clusterID string) (int, error) {