From 05c7844a158164b873a36fe6907a5f0689561175 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Mon, 23 Sep 2024 16:45:03 -0700 Subject: [PATCH] ci(test): add upgrade strategy matrix for helm tests Signed-off-by: Thuan Vo --- .github/helm | 15 +++++++++++ .github/workflows/chart-test.yml | 27 ++++++++++++++----- .../templates/cryostat_deployment.yaml | 2 +- .../tests/cryostat_deployment_test.yaml | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 .github/helm diff --git a/.github/helm b/.github/helm new file mode 100644 index 00000000..42f41f2c --- /dev/null +++ b/.github/helm @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# A wrapper script to overwrite or pass in additional helm arguments + +HELM_LOCATION=${HELM_LOCATION:-"/usr/local/bin/helm"} + +UPGRADE_STRATEGY_OVERWRITE=${UPGRADE_STRATEGY_OVERWRITE:-reuse-values} +UPGRADE_FORCE=${UPGRADE_FORCE:-false} + +ARGS="$@" +if [[ "$1" == "upgrade " ]]; then + ARGS="${ARGS//--reuse-values/--${UPGRADE_STRATEGY_OVERWRITE}}" + ARGS="--force=${UPGRADE_FORCE} $ARGS" +fi + +exec "${HELM_LOCATION}" "$ARGS" diff --git a/.github/workflows/chart-test.yml b/.github/workflows/chart-test.yml index 977e8211..e5451e15 100644 --- a/.github/workflows/chart-test.yml +++ b/.github/workflows/chart-test.yml @@ -24,6 +24,8 @@ on: - v[0-9]+ - v[0-9]+.[0-9]+ - cryostat-v[0-9]+.[0-9]+ + # TODO: Remove after approval + - separate-db-storage jobs: helm-test: @@ -31,6 +33,12 @@ jobs: env: TARGET_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }} TEST_NAMESPACE: helm-test + WRAPPER_LOCATION: .github/helm + strategy: + matrix: + # Supported strategies + upgrade-strategy: ["reset-values", "reset-then-reuse-values"] + upgrade-force: [true, false] steps: - name: Fail if safe-to-test label NOT applied if: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'safe-to-test') }} @@ -51,16 +59,21 @@ jobs: uses: helm/kind-action@v1 with: cluster_name: ci-${{ github.run_id }} - - name: Install and test chart + - name: Wrap Helm in Wrapper Command run: | - # FIXME: Remove when chart-testing fixes the issue https://github.com/helm/chart-testing/issues/525 - + # FIXME: Remvove after https://github.com/helm/chart-testing/issues/525 HELM_LOCATION="$(which helm)" - sudo mv $HELM_LOCATION "$(dirname $HELM_LOCATION)/.helm" - cat <(echo '#!/usr/bin/env bash') <(echo 'exec .helm "${@//--reuse-values/--reset-then-reuse-values}"') | sudo tee $HELM_LOCATION - sudo chmod +x $HELM_LOCATION + HELM_NEW_LOCATION="$(dirname $HELM_LOCATION)/.helm" + + sudo mv "$HELM_LOCATION" "$HELM_NEW_LOCATION" + chmod +x "$WRAPPER_LOCATION" && sudo mv "$WRAPPER_LOCATION" "$HELM_LOCATION" - bash ct.bash --upgrade + # Export env var + echo "HELM_LOCATION=$HELM_LOCATION" >> $GITHUB_ENV + echo "UPGRADE_STRATEGY_OVERWRITE=${{ matrix.upgrade-strategy }}" >> $GITHUB_ENV + echo "UPGRADE_FORCE=${{ matrix.upgrade-force }}" >> $GITHUB_ENV + - name: Install and test chart + run: bash ct.bash --upgrade helm-unittest: runs-on: ubuntu-latest diff --git a/charts/cryostat/templates/cryostat_deployment.yaml b/charts/cryostat/templates/cryostat_deployment.yaml index 66ed91fd..5d0ba356 100644 --- a/charts/cryostat/templates/cryostat_deployment.yaml +++ b/charts/cryostat/templates/cryostat_deployment.yaml @@ -3,7 +3,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "cryostat.fullname" . }} + name: {{ include "cryostat.fullname" . }}-main labels: {{- include "cryostat.labels" . | nindent 4 }} app.kubernetes.io/component: cryostat diff --git a/charts/cryostat/tests/cryostat_deployment_test.yaml b/charts/cryostat/tests/cryostat_deployment_test.yaml index 33a9b00a..b108c877 100644 --- a/charts/cryostat/tests/cryostat_deployment_test.yaml +++ b/charts/cryostat/tests/cryostat_deployment_test.yaml @@ -10,7 +10,7 @@ tests: value: Deployment - equal: path: metadata.name - value: RELEASE-NAME-cryostat + value: RELEASE-NAME-cryostat-main - equal: path: spec.replicas value: 1