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 b74c4a2 commit 282ba56
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
14 changes: 11 additions & 3 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 @@ -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 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 282ba56

Please sign in to comment.