diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 0d198ee0..5b872bb0 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -22,6 +22,10 @@ jobs: permissions: packages: write steps: + - id: lower-repo + shell: pwsh + run: | + "::set-output name=repository::$($env:GITHUB_REPOSITORY.ToLowerInvariant())" - name: Checkout repository uses: actions/checkout@v3 @@ -50,7 +54,7 @@ jobs: with: context: . file: docker/casskop/Dockerfile - tags: ghcr.io/cscetbon/casskop:${{ steps.get-branch.outputs.branch }} + tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:${{ steps.get-branch.outputs.branch }} push: true install-kuttl: @@ -77,6 +81,11 @@ jobs: matrix: test-name: [operations, sidecars, scaling, multi-dcs, backup-restore] steps: + - id: lower-repo + shell: pwsh + run: | + "::set-output name=repository::$($env:GITHUB_REPOSITORY.ToLowerInvariant())" + - name: Get PR branch name id: get-branch env: @@ -140,6 +149,6 @@ jobs: run: | chmod u+x kuttl PATH=$PWD:$PATH - helm install casskop charts/casskop --set image.tag=${{ steps.get-branch.outputs.branch }} + helm install casskop charts/casskop --set image.tag=${{ steps.get-branch.outputs.branch }} --set image.repository=ghcr.io/${{ steps.lower-repo.outputs.repository }} cd test/kuttl/ kuttl test --test ${{ matrix.test-name }} --namespace default --skip-delete diff --git a/api/v2/cassandracluster_types.go b/api/v2/cassandracluster_types.go index 8c2ea789..f40b0b22 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 + } } } @@ -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 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