Skip to content

Commit

Permalink
Merge pull request #132 from AKamyshnikova/disable-baskrest
Browse files Browse the repository at this point in the history
Allow to disable backrest container
  • Loading branch information
AKamyshnikova authored Nov 30, 2023
2 parents 661d1d3 + 282ba56 commit c62502d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
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 c62502d

Please sign in to comment.