Skip to content

Commit

Permalink
Allow to disable backrest container
Browse files Browse the repository at this point in the history
Add enabled field for BackRestSidecar spec.
By default enabled is true (original behaviour).
Setting to false will drop back-rest container deployment.
  • Loading branch information
AKamyshnikova committed Nov 9, 2023
1 parent fd96920 commit b29b31d
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 24 deletions.
54 changes: 31 additions & 23 deletions api/v2/cassandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -237,15 +243,15 @@ 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
}
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
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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:]...)
}
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions charts/casskop/crds/db.orange.com_cassandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/db.orange.com_cassandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion controllers/cassandracluster/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions controllers/cassandracluster/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b29b31d

Please sign in to comment.