Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable backrest container #132

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use github.event.repository.name ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will give an error if the repository name has some uppercase letters (exactly what AKamyshnikova has).
The is a discussion here https://github.com/orgs/community/discussions/10553 and I used one of the suggested options to workaround this.

- 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