Skip to content

Commit

Permalink
Add new field 'monCount' in storagecluster CR
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Nikhil-Ladha committed Oct 17, 2023
1 parent 70fe874 commit 7d07158
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/v1/storagecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/ocs.openshift.io_storageclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions controllers/storagecluster/cephcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -696,7 +696,7 @@ func getMgrCount(arbiterMode bool) int {
return defaults.DefaultMgrCount
}

func getMonCount(nodeCount int, arbiter bool) int {
func getMonCount(sc *ocsv1.StorageCluster, arbiter bool) int {
// return static value if overridden
override := os.Getenv(monCountOverrideEnvVar)
if override != "" {
Expand All @@ -708,6 +708,10 @@ func getMonCount(nodeCount int, arbiter bool) int {
}
}

if sc != nil && sc.Spec.ManagedResources.CephCluster.MonCount != 0 {
return sc.Spec.ManagedResources.CephCluster.MonCount
}

if arbiter {
return defaults.ArbiterModeMonCount
}
Expand Down Expand Up @@ -1050,17 +1054,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, true),
AllowMultiplePerNode: false,
StretchCluster: generateStretchClusterSpec(sc),
}
}

return rookCephv1.MonSpec{
Count: getMonCount(nodeCount, false),
Count: getMonCount(sc, false),
AllowMultiplePerNode: statusutil.IsSingleNodeDeployment(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(nil, false)
assert.Equal(t, monCountExpected, monCountActual)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions deploy/ocs-operator/manifests/storagecluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d07158

Please sign in to comment.