From d6ce4a1a0b22fd85dff2d6750e1d1550b879f484 Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Mon, 16 Oct 2023 16:37:44 +0530 Subject: [PATCH] Add new field 'monCount' in storagecluster CR Added a new field 'monCount' in storagecluster CR that takes in the custom mon count from user i.e, either 3 or 5. Also, updated the `getMonCount` function definition to remove the unused `nodeCount` param. Signed-off-by: Nikhil-Ladha --- api/v1/storagecluster_types.go | 2 ++ .../bases/ocs.openshift.io_storageclusters.yaml | 5 +++++ controllers/storagecluster/cephcluster.go | 15 ++++++++++----- .../storagecluster_controller_test.go | 2 +- .../ocs/ocs.openshift.io_storageclusters.yaml | 5 +++++ .../manifests/storagecluster.crd.yaml | 5 +++++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/api/v1/storagecluster_types.go b/api/v1/storagecluster_types.go index c809d32834..b56697790a 100644 --- a/api/v1/storagecluster_types.go +++ b/api/v1/storagecluster_types.go @@ -171,6 +171,8 @@ type ManagedResourcesSpec struct { // ManageCephCluster defines how to reconcile the Ceph cluster definition type ManageCephCluster struct { ReconcileStrategy string `json:"reconcileStrategy,omitempty"` + // +kubebuilder:validation:Enum=3;5 + MonCount int `json:"monCount,omitempty"` } // ManageCephConfig defines how to reconcile the Ceph configuration diff --git a/config/crd/bases/ocs.openshift.io_storageclusters.yaml b/config/crd/bases/ocs.openshift.io_storageclusters.yaml index ff6cb3c312..0e3b6b8e3d 100644 --- a/config/crd/bases/ocs.openshift.io_storageclusters.yaml +++ b/config/crd/bases/ocs.openshift.io_storageclusters.yaml @@ -655,6 +655,11 @@ spec: description: ManageCephCluster defines how to reconcile the Ceph cluster definition properties: + monCount: + enum: + - 3 + - 5 + type: integer reconcileStrategy: type: string type: object diff --git a/controllers/storagecluster/cephcluster.go b/controllers/storagecluster/cephcluster.go index 54f7e16918..11f71d8006 100644 --- a/controllers/storagecluster/cephcluster.go +++ b/controllers/storagecluster/cephcluster.go @@ -435,7 +435,7 @@ func newCephCluster(sc *ocsv1.StorageCluster, cephImage string, nodeCount int, s Image: cephImage, AllowUnsupported: allowUnsupportedCephVersion(), }, - Mon: generateMonSpec(sc, nodeCount), + Mon: generateMonSpec(sc), Mgr: generateMgrSpec(sc), DataDirHostPath: "/var/lib/rook", DisruptionManagement: rookCephv1.DisruptionManagementSpec{ @@ -696,7 +696,7 @@ func getMgrCount(arbiterMode bool) int { return defaults.DefaultMgrCount } -func getMonCount(nodeCount int, arbiter bool) int { +func getMonCount(monCount int, arbiter bool) int { // return static value if overridden override := os.Getenv(monCountOverrideEnvVar) if override != "" { @@ -711,6 +711,11 @@ func getMonCount(nodeCount int, arbiter bool) int { if arbiter { return defaults.ArbiterModeMonCount } + + if monCount != 0 { + return monCount + } + return defaults.DefaultMonCount } @@ -1050,17 +1055,17 @@ func generateStretchClusterSpec(sc *ocsv1.StorageCluster) *rookCephv1.StretchClu return &stretchClusterSpec } -func generateMonSpec(sc *ocsv1.StorageCluster, nodeCount int) rookCephv1.MonSpec { +func generateMonSpec(sc *ocsv1.StorageCluster) rookCephv1.MonSpec { if arbiterEnabled(sc) { return rookCephv1.MonSpec{ - Count: getMonCount(nodeCount, true), + Count: getMonCount(sc.Spec.ManagedResources.CephCluster.MonCount, true), AllowMultiplePerNode: false, StretchCluster: generateStretchClusterSpec(sc), } } return rookCephv1.MonSpec{ - Count: getMonCount(nodeCount, false), + Count: getMonCount(sc.Spec.ManagedResources.CephCluster.MonCount, false), AllowMultiplePerNode: statusutil.IsSingleNodeDeployment(), } } diff --git a/controllers/storagecluster/storagecluster_controller_test.go b/controllers/storagecluster/storagecluster_controller_test.go index d369dc6e36..6d6ec52c9b 100644 --- a/controllers/storagecluster/storagecluster_controller_test.go +++ b/controllers/storagecluster/storagecluster_controller_test.go @@ -1054,7 +1054,7 @@ func createFakeScheme(t *testing.T) *runtime.Scheme { func TestMonCountChange(t *testing.T) { for nodeCount := 0; nodeCount <= 10; nodeCount++ { monCountExpected := defaults.DefaultMonCount - monCountActual := getMonCount(nodeCount, false) + monCountActual := getMonCount(0, false) assert.Equal(t, monCountExpected, monCountActual) } } diff --git a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml index ff6cb3c312..0e3b6b8e3d 100644 --- a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml +++ b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml @@ -655,6 +655,11 @@ spec: description: ManageCephCluster defines how to reconcile the Ceph cluster definition properties: + monCount: + enum: + - 3 + - 5 + type: integer reconcileStrategy: type: string type: object diff --git a/deploy/ocs-operator/manifests/storagecluster.crd.yaml b/deploy/ocs-operator/manifests/storagecluster.crd.yaml index f6685f033e..558c879cdd 100644 --- a/deploy/ocs-operator/manifests/storagecluster.crd.yaml +++ b/deploy/ocs-operator/manifests/storagecluster.crd.yaml @@ -654,6 +654,11 @@ spec: description: ManageCephCluster defines how to reconcile the Ceph cluster definition properties: + monCount: + enum: + - 3 + - 5 + type: integer reconcileStrategy: type: string type: object