forked from IBM/mr-cassop
-
Notifications
You must be signed in to change notification settings - Fork 0
579 lines (502 loc) · 19.3 KB
/
pull_request.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
name: Pull Request Workflow
on:
pull_request:
env:
GO_VERSION: 1.18
HELM_VERSION: v3.9.2
ICARUS_VERSION: 2.0.4
PYTHON_VERSION: 3.7 # required for helm tester
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
IBM_CLOUD_REGION: us-south
IBM_CLOUD_RG: icm
IKS_CLUSTER: icm-cassandra-ci
IKS_NAMESPACE: cassandra-operator-ci
ICR_NAMESPACE: cassandra-operator
ICR_USERNAME: ${{ secrets.ICR_USERNAME }}
ICR_PASSWORD: ${{ secrets.ICR_PASSWORD }}
IMAGE_PULL_SECRET: icm-coreeng-pull-secret
TRIVY_SEVERITY: CRITICAL
jobs:
run-unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Go Lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=5m --enable exportloopref
skip-pkg-cache: true
skip-build-cache: true
- name: Get dependencies
run: go mod download
- name: Run operator unit tests
run: go test ./controllers/... -v -coverprofile=operator_unit.out -coverpkg=./...
- name: Run prober unit tests
run: |
cd ./prober
go test ./... -v -coverprofile=prober_unit.out -coverpkg=./...
- name: Get tests coverage
run: |
go tool cover -func=operator_unit.out | tail -n1 | awk "{print \"Operator unit tests coverage: \" \$3}"
go tool cover -func=prober_unit.out | tail -n1 | awk "{print \"Prober unit tests coverage: \" \$3}"
run-integration-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
k8s: [1.20.2, 1.21.2, 1.22.1, 1.23.1, 1.24.2]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup Kubebuilder assets
run: |
curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-$k8s-linux-amd64.tar.gz"
mkdir kubebuilder-$k8s
tar -C kubebuilder-$k8s/ --strip-components=1 -zvxf envtest-bins.tar.gz && rm -f envtest-bins.tar.gz
echo "KUBEBUILDER_ASSETS=$(pwd)/kubebuilder-$k8s/bin" >> $GITHUB_ENV
$(pwd)/kubebuilder-$k8s/bin/kube-apiserver --version
env:
k8s: ${{ matrix.k8s }}
- name: Get dependencies
run: go mod download
- name: Run integration tests
run: go test ./tests/integration -v -coverprofile=integration.out -coverpkg=./...
- name: Get tests coverage
run: |
go tool cover -func=integration.out | tail -n1 | awk "{print \"Integration tests coverage: \" \$3}"
build-operator:
runs-on: ubuntu-latest
needs: [run-unit-tests, run-integration-tests, validate-helm-charts]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Docker Proxy Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_PROXY_REGISTRY }}
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_PASS }}
- name: Build operator image
uses: docker/build-push-action@v4
with:
file: Dockerfile
build-args: |
VERSION=${{ env.GITHUB_REF_SLUG }}
DOCKER_PROXY_REGISTRY=${{ secrets.DOCKER_PROXY_REGISTRY }}/
tags: us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra-operator:${{ env.GITHUB_REF_SLUG }}
outputs: type=docker,dest=cassandra-operator.tar
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
input: "cassandra-operator.tar"
exit-code: "1"
ignore-unfixed: true
severity: ${{ env.TRIVY_SEVERITY }}
- name: Upload cassandra operator image artifact
uses: actions/upload-artifact@v3
with:
name: cassandra-operator
path: cassandra-operator.tar
retention-days: 1
build-cassandra:
runs-on: ubuntu-latest
needs: [run-unit-tests, run-integration-tests, validate-helm-charts]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Docker Proxy Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_PROXY_REGISTRY }}
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_PASS }}
- name: Build cassandra image
uses: docker/build-push-action@v4
with:
file: ./cassandra/Dockerfile
context: ./cassandra
tags: us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra:${{ env.GITHUB_REF_SLUG }}
build-args: DOCKER_PROXY_REGISTRY=${{ secrets.DOCKER_PROXY_REGISTRY }}/
outputs: type=docker,dest=cassandra.tar
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
input: "cassandra.tar"
exit-code: "1"
ignore-unfixed: true
severity: ${{ env.TRIVY_SEVERITY }}
- name: Upload cassandra image artifact
uses: actions/upload-artifact@v3
with:
name: cassandra
path: cassandra.tar
retention-days: 1
build-prober:
runs-on: ubuntu-latest
needs: [run-unit-tests, run-integration-tests, validate-helm-charts]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Docker Proxy Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_PROXY_REGISTRY }}
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_PASS }}
- name: Build prober image
uses: docker/build-push-action@v4
with:
file: ./prober/Dockerfile
context: ./prober
build-args: |
VERSION=${{ env.GITHUB_REF_SLUG }}
DOCKER_PROXY_REGISTRY=${{ secrets.DOCKER_PROXY_REGISTRY }}/
tags: us.icr.io/${{ env.ICR_NAMESPACE }}/prober:${{ env.GITHUB_REF_SLUG }}
outputs: type=docker,dest=prober.tar
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
input: "prober.tar"
exit-code: "1"
ignore-unfixed: true
severity: ${{ env.TRIVY_SEVERITY }}
- name: Upload prober image artifact
uses: actions/upload-artifact@v3
with:
name: prober
path: prober.tar
retention-days: 1
build-jolokia:
runs-on: ubuntu-latest
needs: [run-unit-tests, run-integration-tests, validate-helm-charts]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Docker Proxy Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_PROXY_REGISTRY }}
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_PASS }}
- name: Build jolokia image
uses: docker/build-push-action@v4
with:
file: ./jolokia/Dockerfile
context: ./jolokia
build-args: DOCKER_PROXY_REGISTRY=${{ secrets.DOCKER_PROXY_REGISTRY }}/
tags: us.icr.io/${{ env.ICR_NAMESPACE }}/jolokia:${{ env.GITHUB_REF_SLUG }}
outputs: type=docker,dest=jolokia.tar
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
input: "jolokia.tar"
exit-code: "1"
ignore-unfixed: true
severity: ${{ env.TRIVY_SEVERITY }}
- name: Upload jolokia image artifact
uses: actions/upload-artifact@v3
with:
name: jolokia
path: jolokia.tar
retention-days: 1
build-icarus:
runs-on: ubuntu-latest
needs: [run-unit-tests, run-integration-tests, validate-helm-charts]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Docker Proxy Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_PROXY_REGISTRY }}
username: ${{ secrets.ARTIFACTORY_USER }}
password: ${{ secrets.ARTIFACTORY_PASS }}
- name: Build icarus image
uses: docker/build-push-action@v4
with:
file: ./icarus/Dockerfile
context: ./icarus
build-args: |
ICARUS_VERSION: ${{ env.ICARUS_VERSION }}
DOCKER_PROXY_REGISTRY=${{ secrets.DOCKER_PROXY_REGISTRY }}/
tags: us.icr.io/${{ env.ICR_NAMESPACE }}/icarus:${{ env.GITHUB_REF_SLUG }}
outputs: type=docker,dest=icarus.tar
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
input: "icarus.tar"
exit-code: "1"
ignore-unfixed: true
severity: ${{ env.TRIVY_SEVERITY }}
- name: Upload jolokia image artifact
uses: actions/upload-artifact@v3
with:
name: icarus
path: icarus.tar
retention-days: 1
validate-helm-charts:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # ct needs history to compare
- name: Setup Helm
uses: azure/[email protected]
with:
version: ${{ env.HELM_VERSION }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup chart-testing
uses: helm/[email protected]
- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch=main)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Run chart-testing (lint)
run: ct lint --target-branch=main --check-version-increment=false
- name: Download Pluto
uses: FairwindsOps/pluto/[email protected]
- name: Scan for deprecated k8s APIs
run: helm template cassandra-operator/ | pluto detect -
check-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Build docs website
run: |
npm -v
node -v
cd docs
npm ci
npm run build
push-images-for-e2e:
if: "!contains(github.event.head_commit.message, 'e2e skip')"
needs: [build-operator, build-cassandra, build-prober, build-jolokia, build-icarus, validate-helm-charts]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
# We have below variable value replacement to prevent re-push of the image within branch during parallel workflows run
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Install IBM Cloud CLI
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud --version
ibmcloud config --check-version=false
ibmcloud plugin install -f container-registry
- name: Authenticate with IBM Cloud CLI
uses: nick-fields/retry@v2
id: retry
continue-on-error: false
with:
timeout_seconds: 60
max_attempts: 3
retry_on: error
command: |
ibmcloud login --apikey "$IBM_CLOUD_API_KEY" -r "$IBM_CLOUD_REGION" -g "$IBM_CLOUD_RG" --quiet
ibmcloud cr region-set "$IBM_CLOUD_REGION"
ibmcloud cr login
- name: Download operator image artifact
uses: actions/download-artifact@v3
with:
name: cassandra-operator
- name: Download cassandra image artifact
uses: actions/download-artifact@v3
with:
name: cassandra
- name: Download prober image artifact
uses: actions/download-artifact@v3
with:
name: prober
- name: Download jolokia image artifact
uses: actions/download-artifact@v3
with:
name: jolokia
- name: Download icarus image artifact
uses: actions/download-artifact@v3
with:
name: icarus
- name: Load container images
run: |
docker load -i cassandra-operator.tar
docker load -i cassandra.tar
docker load -i prober.tar
docker load -i jolokia.tar
docker load -i icarus.tar
- name: Push Images to ICR
run: |
docker push "us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra-operator:$GITHUB_REF_SLUG"
docker push "us.icr.io/${{ env.ICR_NAMESPACE }}/prober:$GITHUB_REF_SLUG"
docker push "us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra:$GITHUB_REF_SLUG"
docker push "us.icr.io/${{ env.ICR_NAMESPACE }}/jolokia:$GITHUB_REF_SLUG"
docker push "us.icr.io/${{ env.ICR_NAMESPACE }}/icarus:$GITHUB_REF_SLUG"
run-e2e-tests:
needs: [push-images-for-e2e]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Block Concurrent Executions for the Deployment
uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 10
abort-after-seconds: 7200
same-branch-only: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Modify GITHUB_REF_SLUG
run: echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG-${{ github.run_id }}" >> $GITHUB_ENV
- name: Install IBM Cloud CLI
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud --version
ibmcloud config --check-version=false
ibmcloud plugin install -f kubernetes-service
ibmcloud plugin install -f container-registry
- name: Authenticate with IBM Cloud CLI
uses: nick-fields/retry@v2
id: retry
continue-on-error: false
with:
timeout_seconds: 60
max_attempts: 3
retry_on: error
command: |
ibmcloud login --apikey "$IBM_CLOUD_API_KEY" -r "$IBM_CLOUD_REGION" -g "$IBM_CLOUD_RG" --quiet
ibmcloud cr region-set "$IBM_CLOUD_REGION"
ibmcloud cr login
ibmcloud ks cluster config --cluster $IKS_CLUSTER
kubectl config current-context
kubectl config set-context --current --namespace $IKS_NAMESPACE
- name: Setup k8s namespace
run: |
kubectl create namespace $IKS_NAMESPACE || true
kubectl create secret docker-registry icm-coreeng-pull-secret \
--docker-username="$ICR_USERNAME" \
--docker-password="$ICR_PASSWORD" \
--docker-server=us.icr.io || true
- name: Deploy C* operator helm chart
uses: nick-fields/retry@v2
with:
timeout_seconds: 60
max_attempts: 3
retry_on: error
command: |
helm install cassandra-operator cassandra-operator \
--set "container.image=us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra-operator:$GITHUB_REF_SLUG" \
--set "proberImage=us.icr.io/${{ env.ICR_NAMESPACE }}/prober:$GITHUB_REF_SLUG" \
--set "cassandraImage=us.icr.io/${{ env.ICR_NAMESPACE }}/cassandra:$GITHUB_REF_SLUG" \
--set "jolokiaImage=us.icr.io/${{ env.ICR_NAMESPACE }}/jolokia:$GITHUB_REF_SLUG" \
--set "icarusImage=us.icr.io/${{ env.ICR_NAMESPACE }}/icarus:$GITHUB_REF_SLUG" \
--set "logFormat=console" \
--set "logLevel=debug" \
--set "container.imagePullSecret=$IMAGE_PULL_SECRET"
kubectl rollout status deployment cassandra-operator
- name: C* operator deployment has failed, showing debug...
if: ${{ failure() }}
run: |
kubectl get deployments,po
kubectl describe pod -l operator=cassandra-operator
kubectl logs deployment/cassandra-operator --tail=20
- name: Set up Go with latest minor version 1.x
uses: actions/setup-go@v4
with:
go-version: ^1.18
- name: Get go dependencies
run: go mod download
- name: Install Ginkgo
run: go install github.com/onsi/ginkgo/v2/[email protected]
- name: Run e2e tests
id: e2e
run: make e2e-tests
- name: Upload logs artifact
if: ${{ always() && steps.e2e.outcome == 'failure' }}
uses: actions/upload-artifact@v3
with:
name: logs
path: /tmp/debug-logs/
retention-days: 7
- name: Uninstall C* operator helm chart
if: ${{ always() }}
run: helm uninstall cassandra-operator
- name: Remove CassandraCluster CRD
if: ${{ always() }}
run: kubectl delete -f cassandra-operator/crds/db.ibm.com_cassandraclusters.yaml
- name: Remove CassandraBackup CRD
if: ${{ always() }}
run: kubectl delete -f cassandra-operator/crds/db.ibm.com_cassandrabackups.yaml
- name: Remove CassandraRestore CRD
if: ${{ always() }}
run: kubectl delete -f cassandra-operator/crds/db.ibm.com_cassandrarestores.yaml
# We have below logic bc when multiple tags exist for the same image digest within a repository, the ibmcloud cr image-rm command removes the underlying image and all its tags. See details: https://cloud.ibm.com/docs/container-registry-cli-plugin?topic=container-registry-cli-plugin-containerregcli#bx_cr_image_rm
# We can also add a check if commit message contains `no_image_del` then skip the image deletion step
- name: Cleanup k8s namespace
if: ${{ always() }}
run: kubectl delete namespace $IKS_NAMESPACE
- name: Cleanup Images
if: ${{ always() }}
run: |
for image_name in cassandra-operator prober cassandra jolokia icarus; do
image_digest=$(ibmcloud cr image-list --restrict ${{ env.ICR_NAMESPACE }} --format "{{if and (eq .Repository \"us.icr.io/cassandra-operator/$image_name\") (eq .Tag \"$GITHUB_REF_SLUG\")}}{{.Digest}}{{end}}" --no-trunc)
image_tags=$(ibmcloud cr image-digests --restrict ${{ env.ICR_NAMESPACE }} --format "{{if and (eq .Digest \"$image_digest\")}}{{.Tags}}{{end}}" | sed -e 's/\[//g' -e 's/\]//g')
image_tags_arr=($image_tags)
echo "image tags: ${image_tags_arr[@]}, number: ${#image_tags_arr[@]}"
if (( ${#image_tags_arr[@]} > 1 )); then
ibmcloud cr image-untag "us.icr.io/${{ env.ICR_NAMESPACE }}/$image_name:$GITHUB_REF_SLUG"
else
ibmcloud cr image-rm "us.icr.io/${{ env.ICR_NAMESPACE }}/$image_name:$GITHUB_REF_SLUG"
fi
done