From 2a41afcb28d8075cdf489b3577bf63f0f18dd6b6 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 8 Jul 2025 10:03:57 +0200 Subject: [PATCH] core: add clusterID to rados namespace CRD Providing an option for user to specify the clusterID they want to use in the storageclass while creating the radosnamespace. Signed-off-by: Madhu Rajanna --- Documentation/CRDs/specification.md | 28 +++++++++++++++++++ .../charts/rook-ceph/templates/resources.yaml | 12 ++++++++ deploy/examples/crds.yaml | 12 ++++++++ deploy/examples/radosnamespace.yaml | 4 +++ pkg/apis/ceph.rook.io/v1/types.go | 10 +++++++ .../ceph/pool/radosnamespace/controller.go | 3 ++ .../pool/radosnamespace/controller_test.go | 15 ++++++++++ 7 files changed, 84 insertions(+) diff --git a/Documentation/CRDs/specification.md b/Documentation/CRDs/specification.md index 90fdd0b51..642bdcc78 100644 --- a/Documentation/CRDs/specification.md +++ b/Documentation/CRDs/specification.md @@ -3286,6 +3286,20 @@ RadosNamespaceMirroring

Mirroring configuration of CephBlockPoolRadosNamespace

+ + +clusterID
+ +string + + + +(Optional) +

ClusterID to be used for this RadosNamespace in the CSI configuration. +It must be unique among all Ceph clusters managed by Rook. +If not specified, the clusterID will be generated and can be found in the CR status.

+ + @@ -3359,6 +3373,20 @@ RadosNamespaceMirroring

Mirroring configuration of CephBlockPoolRadosNamespace

+ + +clusterID
+ +string + + + +(Optional) +

ClusterID to be used for this RadosNamespace in the CSI configuration. +It must be unique among all Ceph clusters managed by Rook. +If not specified, the clusterID will be generated and can be found in the CR status.

+ +

CephBlockPoolRadosNamespaceStatus diff --git a/deploy/charts/rook-ceph/templates/resources.yaml b/deploy/charts/rook-ceph/templates/resources.yaml index 430e5534e..053d612ce 100644 --- a/deploy/charts/rook-ceph/templates/resources.yaml +++ b/deploy/charts/rook-ceph/templates/resources.yaml @@ -63,6 +63,18 @@ spec: x-kubernetes-validations: - message: blockPoolName is immutable rule: self == oldSelf + clusterID: + description: |- + ClusterID to be used for this RadosNamespace in the CSI configuration. + It must be unique among all Ceph clusters managed by Rook. + If not specified, the clusterID will be generated and can be found in the CR status. + maxLength: 36 + minLength: 1 + pattern: ^[a-zA-Z0-9_-]+$ + type: string + x-kubernetes-validations: + - message: ClusterID is immutable + rule: self == oldSelf mirroring: description: Mirroring configuration of CephBlockPoolRadosNamespace properties: diff --git a/deploy/examples/crds.yaml b/deploy/examples/crds.yaml index 0adb1cb11..65bf0cb2a 100644 --- a/deploy/examples/crds.yaml +++ b/deploy/examples/crds.yaml @@ -66,6 +66,18 @@ spec: x-kubernetes-validations: - message: blockPoolName is immutable rule: self == oldSelf + clusterID: + description: |- + ClusterID to be used for this RadosNamespace in the CSI configuration. + It must be unique among all Ceph clusters managed by Rook. + If not specified, the clusterID will be generated and can be found in the CR status. + maxLength: 36 + minLength: 1 + pattern: ^[a-zA-Z0-9_-]+$ + type: string + x-kubernetes-validations: + - message: ClusterID is immutable + rule: self == oldSelf mirroring: description: Mirroring configuration of CephBlockPoolRadosNamespace properties: diff --git a/deploy/examples/radosnamespace.yaml b/deploy/examples/radosnamespace.yaml index 80230947d..bd7ea355b 100644 --- a/deploy/examples/radosnamespace.yaml +++ b/deploy/examples/radosnamespace.yaml @@ -9,3 +9,7 @@ spec: # name: namespace-a # blockPoolName is the name of the CephBlockPool CR where the namespace will be created. blockPoolName: replicapool + # ClusterID to be used for this RadosNamespace in the CSI configuration. + # It must be unique among all Ceph clusters managed by Rook. + # If not specified, the clusterID will be generated and can be found in the CR status. + # clusterID: namespace-a diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index c63674b4b..56be7f94f 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -3685,6 +3685,16 @@ type CephBlockPoolRadosNamespaceSpec struct { // Mirroring configuration of CephBlockPoolRadosNamespace // +optional Mirroring *RadosNamespaceMirroring `json:"mirroring,omitempty"` + + // ClusterID to be used for this RadosNamespace in the CSI configuration. + // It must be unique among all Ceph clusters managed by Rook. + // If not specified, the clusterID will be generated and can be found in the CR status. + // +optional + // +kubebuilder:validation:XValidation:message="ClusterID is immutable",rule="self == oldSelf" + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=36 + // +kubebuilder:validation:Pattern=`^[a-zA-Z0-9_-]+$` + ClusterID string `json:"clusterID,omitempty"` } // CephBlockPoolRadosNamespaceStatus represents the Status of Ceph BlockPool diff --git a/pkg/operator/ceph/pool/radosnamespace/controller.go b/pkg/operator/ceph/pool/radosnamespace/controller.go index 378b6d8b9..fd55c6983 100644 --- a/pkg/operator/ceph/pool/radosnamespace/controller.go +++ b/pkg/operator/ceph/pool/radosnamespace/controller.go @@ -488,6 +488,9 @@ func (r *ReconcileCephBlockPoolRadosNamespace) updateStatus(client client.Client } func buildClusterID(cephBlockPoolRadosNamespace *cephv1.CephBlockPoolRadosNamespace) string { + if cephBlockPoolRadosNamespace.Spec.ClusterID != "" { + return cephBlockPoolRadosNamespace.Spec.ClusterID + } clusterID := fmt.Sprintf("%s-%s-block-%s", cephBlockPoolRadosNamespace.Namespace, cephBlockPoolRadosNamespace.Spec.BlockPoolName, cephv1.GetRadosNamespaceName(cephBlockPoolRadosNamespace)) return k8sutil.Hash(clusterID) } diff --git a/pkg/operator/ceph/pool/radosnamespace/controller_test.go b/pkg/operator/ceph/pool/radosnamespace/controller_test.go index e0df465a4..30dc98493 100644 --- a/pkg/operator/ceph/pool/radosnamespace/controller_test.go +++ b/pkg/operator/ceph/pool/radosnamespace/controller_test.go @@ -633,6 +633,21 @@ func Test_buildClusterID(t *testing.T) { cephBlockPoolRadosNamespace := &cephv1.CephBlockPoolRadosNamespace{ObjectMeta: metav1.ObjectMeta{Namespace: "rook-ceph", Name: longName}, Spec: cephv1.CephBlockPoolRadosNamespaceSpec{BlockPoolName: "replicapool"}} clusterID := buildClusterID(cephBlockPoolRadosNamespace) assert.Equal(t, "2a74e5201e6ff9d15916ce2109c4f868", clusterID) + + // test user provided clusterID + inputClusterID := "test-clusterID" + cephBlockPoolRadosNamespace = &cephv1.CephBlockPoolRadosNamespace{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "rook-ceph", + Name: longName, + }, + Spec: cephv1.CephBlockPoolRadosNamespaceSpec{ + BlockPoolName: "replicapool", + ClusterID: inputClusterID, + }, + } + clusterID = buildClusterID(cephBlockPoolRadosNamespace) + assert.Equal(t, inputClusterID, clusterID) } func TestGetRadosNamespaceName(t *testing.T) {