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 46e68c14e9..e300136398 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 1e6344a8b6..de70241ba1 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{ @@ -697,7 +697,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 != "" { @@ -712,6 +712,11 @@ func getMonCount(nodeCount int, arbiter bool) int { if arbiter { return defaults.ArbiterModeMonCount } + + if monCount != 0 { + return monCount + } + return defaults.DefaultMonCount } @@ -1051,17 +1056,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 59498aa040..3e089d1c2d 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 46e68c14e9..e300136398 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 ef2b0f1ed9..d8718be9a5 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