diff --git a/api/v2/cassandracluster_types.go b/api/v2/cassandracluster_types.go index 26586bc9..86ef633f 100644 --- a/api/v2/cassandracluster_types.go +++ b/api/v2/cassandracluster_types.go @@ -147,10 +147,16 @@ func (cc *CassandraCluster) CheckDefaults() { } // BackupRestore default config + enabled := true if ccs.BackRestSidecar == nil { - ccs.BackRestSidecar = &BackRestSidecar{Image: DefaultBackRestImage} - } else if ccs.BackRestSidecar.Image == "" { - ccs.BackRestSidecar.Image = DefaultBackRestImage + ccs.BackRestSidecar = &BackRestSidecar{Enabled: &enabled, Image: DefaultBackRestImage} + } else { + if ccs.BackRestSidecar.Enabled == nil { + ccs.BackRestSidecar.Enabled = &enabled + } + if ccs.BackRestSidecar.Image == "" { + ccs.BackRestSidecar.Image = DefaultBackRestImage + } } } @@ -199,7 +205,7 @@ func (cc *CassandraCluster) ComputeLastAppliedConfiguration() ([]byte, error) { return lastApplied, err } -//GetDCSize Return the Numbers of declared DC +// GetDCSize Return the Numbers of declared DC func (cc *CassandraCluster) GetDCSize() int { return len(cc.Spec.Topology.DC) } @@ -217,8 +223,8 @@ func (cc *CassandraCluster) GetStatusDCRackSize() int { return len(cc.Status.CassandraRackStatus) } -//GetDCName return the name of the DC a indice dc -//or defaultName +// GetDCName return the name of the DC a indice dc +// or defaultName func (cc *CassandraCluster) GetDCName(dc int) string { if dc >= cc.GetDCSize() { return DefaultCassandraDC @@ -237,7 +243,7 @@ func (cc *CassandraCluster) getDCNodesPerRacksFromIndex(dc int) int32 { return *storeDC.NodesPerRacks } -//GetRackSize return the numbers of the Rack in the DC at indice dc +// GetRackSize return the numbers of the Rack in the DC at indice dc func (cc *CassandraCluster) GetRackSize(dc int) int { if dc >= cc.GetDCSize() { return 0 @@ -245,7 +251,7 @@ func (cc *CassandraCluster) GetRackSize(dc int) int { return len(cc.Spec.Topology.DC[dc].Rack) } -//GetRackName return the Name of the rack for DC at index dc and Rack at index rack +// GetRackName return the Name of the rack for DC at index dc and Rack at index rack func (cc *CassandraCluster) GetRackName(dc int, rack int) string { if dc >= cc.GetDCSize() || rack >= cc.GetRackSize(dc) { return DefaultCassandraRack @@ -265,13 +271,13 @@ func (cc *CassandraCluster) GetDCRackName(dcName string, rackName string) string return "" } -//GetDCNameFromDCRackName send dc name from dcRackName (dc-rack) +// GetDCNameFromDCRackName send dc name from dcRackName (dc-rack) func (cc *CassandraCluster) GetDCNameFromDCRackName(dcRackName string) string { dc, _ := cc.GetDCNameAndRackNameFromDCRackName(dcRackName) return dc } -//GetDCAndRackFromDCRackName send dc and rack from dcRackName (dc-rack) +// GetDCAndRackFromDCRackName send dc and rack from dcRackName (dc-rack) func (cc *CassandraCluster) GetDCNameAndRackNameFromDCRackName(dcRackName string) (string, string) { dc := strings.Split(dcRackName, "-") return dc[0], dc[1] @@ -383,8 +389,8 @@ func (cc *CassandraCluster) IsPodInSeedList(podName string) bool { return false } -//FixCassandraRackList will remove additional rack-list that don't exists anymore in Topology -//we recalculate new dcrackStatus from actual topology and we apply diff to original +// FixCassandraRackList will remove additional rack-list that don't exists anymore in Topology +// we recalculate new dcrackStatus from actual topology and we apply diff to original func (cc *CassandraCluster) FixCassandraRackList(status *CassandraClusterStatus) []string { newcc := cc.DeepCopy() newcc.InitCassandraRackList() @@ -415,7 +421,7 @@ func (cc *CassandraCluster) GetRemovedDCName(oldCRD *CassandraCluster) string { return "" } -//InitCassandraRackList initiate the Status structure for CassandraRack +// InitCassandraRackList initiate the Status structure for CassandraRack func (cc *CassandraCluster) InitCassandraRackList() int { var dcName, rackName string var nbRack = 0 @@ -533,7 +539,7 @@ func (cc *CassandraCluster) GetNodesPerRacks(dcRackName string) int32 { return nodesPerRacks } -//GetDCNodesPerRacksFromDCRackName send NodesPerRack used for the given dcRackName +// GetDCNodesPerRacksFromDCRackName send NodesPerRack used for the given dcRackName func (cc *CassandraCluster) GetDCRackNames() []string { dcsize := cc.GetDCSize() @@ -555,7 +561,7 @@ func (cc *CassandraCluster) GetDCRackNames() []string { return dcRackNames } -//GetDCNodesPerRacksFromDCRackName send NodesPerRack used for the given dcRackName +// GetDCNodesPerRacksFromDCRackName send NodesPerRack used for the given dcRackName func (cc *CassandraCluster) GetDCNodesPerRacksFromDCRackName(dcRackName string) int32 { dcsize := cc.GetDCSize() @@ -601,8 +607,8 @@ func (cc *CassandraCluster) GetRollingPartitionPerRacks(dcRackName string) int32 return 0 } -//GetDCNodesPerRacksFromName send NodesPerRack which is applied for the specified dc name -//return true if we found, and false if not +// GetDCNodesPerRacksFromName send NodesPerRack which is applied for the specified dc name +// return true if we found, and false if not func (cc *CassandraCluster) GetDCNodesPerRacksFromName(dctarget string) (bool, int32) { dcsize := cc.GetDCSize() @@ -618,7 +624,7 @@ func (cc *CassandraCluster) GetDCNodesPerRacksFromName(dctarget string) (bool, i return false, cc.Spec.NodesPerRacks } -//FindDCWithNodesTo0 +// FindDCWithNodesTo0 func (cc *CassandraCluster) FindDCWithNodesTo0() (bool, string, int) { for dc := 0; dc < cc.GetDCSize(); dc++ { if cc.getDCNodesPerRacksFromIndex(dc) == int32(0) { @@ -629,7 +635,7 @@ func (cc *CassandraCluster) FindDCWithNodesTo0() (bool, string, int) { return false, "", 0 } -//IsValidDC returns true if dcName is known +// IsValidDC returns true if dcName is known func (cc *CassandraCluster) IsValidDC(dcName string) bool { for _, dc := range cc.Spec.Topology.DC { if dc.Name == dcName { @@ -639,12 +645,12 @@ func (cc *CassandraCluster) IsValidDC(dcName string) bool { return false } -//Remove elements from DC slice +// Remove elements from DC slice func (dc *DCSlice) Remove(idx int) { *dc = append((*dc)[:idx], (*dc)[idx+1:]...) } -//Remove elements from Rack slice +// Remove elements from Rack slice func (rack *RackSlice) Remove(idx int) { *rack = append((*rack)[:idx], (*rack)[idx+1:]...) } @@ -899,6 +905,8 @@ type ServicePolicy struct { // BackRestSidecar defines details about cassandra-sidecar to load along with each C* pod type BackRestSidecar struct { + // +kubebuilder:default:=true + Enabled *bool `json:"enabled,omitempty"` // Image of backup/restore sidecar Image string `json:"image,omitempty"` // ImagePullPolicy define the pull policy for backrest sidecar docker image @@ -908,7 +916,7 @@ type BackRestSidecar struct { VolumeMounts []v1.VolumeMount `json:"volumeMount,omitempty"` } -//CassandraRackStatus defines states of Cassandra for 1 rack (1 statefulset) +// CassandraRackStatus defines states of Cassandra for 1 rack (1 statefulset) type CassandraRackStatus struct { // Phase indicates the state this Cassandra cluster jumps in. // Phase goes as one way as below: @@ -922,7 +930,7 @@ type CassandraRackStatus struct { PodLastOperation PodLastOperation `json:"podLastOperation,omitempty"` } -//CassandraClusterStatus defines Global state of CassandraCluster +// CassandraClusterStatus defines Global state of CassandraCluster type CassandraClusterStatus struct { // Phase indicates the state this Cassandra cluster jumps in. // Phase goes as one way as below: diff --git a/api/v2/zz_generated.deepcopy.go b/api/v2/zz_generated.deepcopy.go index 08da6970..1bf9f3d2 100644 --- a/api/v2/zz_generated.deepcopy.go +++ b/api/v2/zz_generated.deepcopy.go @@ -34,6 +34,11 @@ func (in *BackRestCondition) DeepCopy() *BackRestCondition { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BackRestSidecar) DeepCopyInto(out *BackRestSidecar) { *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } if in.Resources != nil { in, out := &in.Resources, &out.Resources *out = new(v1.ResourceRequirements) diff --git a/charts/casskop/crds/db.orange.com_cassandraclusters.yaml b/charts/casskop/crds/db.orange.com_cassandraclusters.yaml index a6c985ef..442332b8 100644 --- a/charts/casskop/crds/db.orange.com_cassandraclusters.yaml +++ b/charts/casskop/crds/db.orange.com_cassandraclusters.yaml @@ -1270,6 +1270,9 @@ spec: description: BackRestSidecar defines details about cassandra-sidecar to load along with each C* pod type: object properties: + enabled: + type: boolean + default: true image: description: Image of backup/restore sidecar type: string diff --git a/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml b/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml index a6c985ef..442332b8 100644 --- a/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml +++ b/charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml @@ -1270,6 +1270,9 @@ spec: description: BackRestSidecar defines details about cassandra-sidecar to load along with each C* pod type: object properties: + enabled: + type: boolean + default: true image: description: Image of backup/restore sidecar type: string diff --git a/config/crd/bases/db.orange.com_cassandraclusters.yaml b/config/crd/bases/db.orange.com_cassandraclusters.yaml index a6c985ef..442332b8 100644 --- a/config/crd/bases/db.orange.com_cassandraclusters.yaml +++ b/config/crd/bases/db.orange.com_cassandraclusters.yaml @@ -1270,6 +1270,9 @@ spec: description: BackRestSidecar defines details about cassandra-sidecar to load along with each C* pod type: object properties: + enabled: + type: boolean + default: true image: description: Image of backup/restore sidecar type: string diff --git a/controllers/cassandracluster/generator.go b/controllers/cassandracluster/generator.go index 5e866175..b947d70b 100644 --- a/controllers/cassandracluster/generator.go +++ b/controllers/cassandracluster/generator.go @@ -894,7 +894,9 @@ func generateContainers(cc *api.CassandraCluster, status *api.CassandraClusterSt var containers []v1.Container containers = append(containers, cc.Spec.SidecarConfigs...) containers = append(containers, createCassandraContainer(cc, status, dcRackName)) - containers = append(containers, backrestSidecarContainer(cc)) + if cc.Spec.BackRestSidecar.Enabled == nil || *cc.Spec.BackRestSidecar.Enabled { + containers = append(containers, backrestSidecarContainer(cc)) + } return containers } diff --git a/controllers/cassandracluster/generator_test.go b/controllers/cassandracluster/generator_test.go index e4b77368..e3490d6d 100644 --- a/controllers/cassandracluster/generator_test.go +++ b/controllers/cassandracluster/generator_test.go @@ -769,3 +769,16 @@ func checkInitContainerVarEnv(t *testing.T, initContainerEnvVar []v1.EnvVar, var } } } + +func TestDisableBackRest(t *testing.T) { + // Check of Cassandra version detection in case of different image formats + dcName := "dc1" + rackName := "rack1" + dcRackName := fmt.Sprintf("%s-%s", dcName, rackName) + _, cc := helperInitCluster(t, "cassandracluster-disable-backrest.yaml") + cc.CheckDefaults() + labels, nodeSelector := k8s.DCRackLabelsAndNodeSelectorForStatefulSet(cc, 0, 0) + sts, _ := generateCassandraStatefulSet(cc, &cc.Status, dcName, dcRackName, labels, nodeSelector, nil) + assert := assert.New(t) + assert.Equal(1, len(sts.Spec.Template.Spec.Containers)) +} diff --git a/controllers/cassandracluster/testdata/cassandracluster-disable-backrest.yaml b/controllers/cassandracluster/testdata/cassandracluster-disable-backrest.yaml new file mode 100644 index 00000000..7be21a09 --- /dev/null +++ b/controllers/cassandracluster/testdata/cassandracluster-disable-backrest.yaml @@ -0,0 +1,24 @@ +apiVersion: db.orange.com/v2 +kind: CassandraCluster +metadata: + name: cassandra-demo + labels: + cluster: k8s.pic + namespace: ns +spec: + backRestSidecar: + enabled: false + dataCapacity: 3Gi + nodesPerRacks: 3 + deletePVC: true + autoPilot: true + resources: + limits: &limits + cpu: 1 + memory: 2Gi + requests: *limits + topology: + dc: + - name: dc1 + rack: + - name: rack1