From 5ffb997471bb9ea7dc3df517f83583e16186b594 Mon Sep 17 00:00:00 2001 From: "Dan P." Date: Fri, 14 Feb 2025 12:38:37 -0500 Subject: [PATCH] fix(ci): Correct k3s version used for e2e testing (#172) * Add min/max k3s version used for testing I'm adding both so in the future we can test both extremes, but for now I'm going to PR just using 1 of them. * go generate * Add helper script to grab K3S versions as ENVs and use that in local-e2e * Make debug output actually create envs that should work in GHA instead of just human debug output * Source k3s version from `build.yaml` for GHA too * Fix job step ordering so yq will be installed when k3s version env is set * remove conflicting and unused ids * Fix helm-locker yq step * Export tag style of k3s versions * Use tags directly in GHA --- .github/workflows/hl-e2e.yaml | 9 ++++++++- .github/workflows/hpo-e2e-ci.yaml | 9 +++++---- .github/workflows/prom-fed-e2e-ci.yaml | 9 +++++---- build.yaml | 4 +++- pkg/buildconfig/constants.go | 2 ++ scripts/k3s-version | 17 +++++++++++++++++ scripts/local-e2e | 22 +++++++++++++--------- 7 files changed, 53 insertions(+), 19 deletions(-) create mode 100755 scripts/k3s-version diff --git a/.github/workflows/hl-e2e.yaml b/.github/workflows/hl-e2e.yaml index ac143090..bb5d1cee 100644 --- a/.github/workflows/hl-e2e.yaml +++ b/.github/workflows/hl-e2e.yaml @@ -23,7 +23,7 @@ on: env: CLUSTER_NAME : e2e-ci-helm-locker - K3S_VERSION : v1.27.9-k3s1 + YQ_VERSION: v4.25.1 jobs: build: @@ -45,6 +45,13 @@ jobs: - uses: azure/setup-helm@v3 with: token: ${{ secrets.GITHUB_TOKEN }} + - name: Install mikefarah/yq + run: | + sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; + - name: Set K3S Min/Max Versions + run: bash ./scripts/k3s-version >> $GITHUB_ENV + - name: Set K3S_VERSION + run: echo "K3S_VERSION=$K3S_MIN_VERSION_TAG" >> $GITHUB_ENV - name: build run: BUILD_TARGET=helm-locker make build - name : Install k3d diff --git a/.github/workflows/hpo-e2e-ci.yaml b/.github/workflows/hpo-e2e-ci.yaml index 2db59cc2..db86b0dd 100644 --- a/.github/workflows/hpo-e2e-ci.yaml +++ b/.github/workflows/hpo-e2e-ci.yaml @@ -43,9 +43,6 @@ jobs: arch: - x64 - arm64 - k3s_version: - # k3d version list k3s | sed 's/+/-/' | sort -h - - ${{ github.event.inputs.k3s_version || 'v1.27.9-k3s1' }} runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }} env: K3S_VERSION: ${{ matrix.k3s_version }} @@ -60,6 +57,10 @@ jobs: - name: Install mikefarah/yq run: | sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; + - name: Set K3S Min/Max Versions + run: bash ./scripts/k3s-version >> $GITHUB_ENV + - name: Set K3S_VERSION + run: echo "K3S_VERSION=${{ inputs.k3s_version || env.K3S_MIN_VERSION_TAG }}" >> $GITHUB_ENV - name: Perform pre-e2e image build run: | BUILD_TARGET=helm-project-operator REPO=${REPO} TAG=${TAG} ./scripts/build; @@ -67,7 +68,7 @@ jobs: - name : Install k3d run : ./.github/workflows/e2e/scripts/install-k3d.sh - name : Setup k3d cluster - run : K3S_VERSION=${{ env.K3S_VERSION }} ./.github/workflows/e2e/scripts/setup-cluster.sh + run : ./.github/workflows/e2e/scripts/setup-cluster.sh - name: Import Images Into k3d run: | k3d image import ${REPO}/helm-project-operator:${TAG} -c "$CLUSTER_NAME"; diff --git a/.github/workflows/prom-fed-e2e-ci.yaml b/.github/workflows/prom-fed-e2e-ci.yaml index 5ba18712..cb953e42 100644 --- a/.github/workflows/prom-fed-e2e-ci.yaml +++ b/.github/workflows/prom-fed-e2e-ci.yaml @@ -52,9 +52,6 @@ jobs: arch: - x64 - arm64 - k3s_version: - # k3d version list k3s | sed 's/+/-/' | sort -h - - ${{ github.event.inputs.k3s_version || 'v1.28.14-k3s1' }} runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }} steps: - @@ -77,6 +74,10 @@ jobs: source ./scripts/version echo TAG=$TAG >> $GITHUB_ENV echo IMAGE=$IMAGE >> $GITHUB_ENV + - name: Set K3S Min/Max Versions + run: bash ./scripts/k3s-version >> $GITHUB_ENV + - name: Set K3S_VERSION + run: echo "K3S_VERSION=${{ inputs.k3s_version || env.K3S_MIN_VERSION_TAG }}" >> $GITHUB_ENV - name: Perform pre-e2e image build run: | @@ -87,7 +88,7 @@ jobs: run : ./.github/workflows/e2e/scripts/install-k3d.sh - name : Setup k3d cluster - run : K3S_VERSION=${{ matrix.k3s_version }} ./.github/workflows/e2e/scripts/setup-cluster.sh + run : ./.github/workflows/e2e/scripts/setup-cluster.sh - name: Import Images Into k3d run: | diff --git a/build.yaml b/build.yaml index b2c5e549..261cbdac 100644 --- a/build.yaml +++ b/build.yaml @@ -1 +1,3 @@ -rancherProjectMonitoringVersion: 0.3.4 \ No newline at end of file +rancherProjectMonitoringVersion: 0.3.4 +k3sTestingMaxVersion: v1.32.1+k3s1 +k3sTestingMinVersion: v1.30.9+k3s1 \ No newline at end of file diff --git a/pkg/buildconfig/constants.go b/pkg/buildconfig/constants.go index 6cb27939..ab950139 100644 --- a/pkg/buildconfig/constants.go +++ b/pkg/buildconfig/constants.go @@ -3,5 +3,7 @@ package buildconfig const ( + K3sTestingMaxVersion = "v1.32.1+k3s1" + K3sTestingMinVersion = "v1.30.9+k3s1" RancherProjectMonitoringVersion = "0.3.4" ) diff --git a/scripts/k3s-version b/scripts/k3s-version new file mode 100755 index 00000000..dd20982e --- /dev/null +++ b/scripts/k3s-version @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + + +SCRIPT_PATH="$(realpath ${BASH_SOURCE[0]})" +PROJECT_ROOT="$(dirname $(dirname $SCRIPT_PATH))" +BUILD_YAML="$PROJECT_ROOT/build.yaml" + +export K3S_MAX_VERSION=$(yq '.k3sTestingMaxVersion' $BUILD_YAML) +export K3S_MIN_VERSION=$(yq '.k3sTestingMinVersion' $BUILD_YAML) + +function print_version_debug() { + echo "K3S_MAX_VERSION=$K3S_MAX_VERSION" + echo "K3S_MAX_VERSION_TAG=${K3S_MAX_VERSION/+/-}" + echo "K3S_MIN_VERSION=$K3S_MIN_VERSION" + echo "K3S_MIN_VERSION_TAG=${K3S_MIN_VERSION/+/-}" +} +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then print_version_debug "$1"; fi \ No newline at end of file diff --git a/scripts/local-e2e b/scripts/local-e2e index 461dc36d..7fab27cb 100755 --- a/scripts/local-e2e +++ b/scripts/local-e2e @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -DONT_CLEAN=false +DONT_CLEAN=${DONT_CLEAN:-false} header() { local text="$1" @@ -22,7 +22,7 @@ cleanupTest() { } onExit() { - if [[ "$?" -eq 0 ]]; then + if [[ "$?" -eq 0 ]] || [ "$DONT_CLEAN" == true ]; then exit 0 fi @@ -30,14 +30,15 @@ onExit() { } trap onExit EXIT -source $(dirname $0)/version +source "$(dirname "$0")/version" +source "$(dirname "$0")/k3s-version" -cd $(dirname $0)/.. +cd "$(dirname "$0")/.." # Setup CI specific Vars export CLUSTER_NAME='e2e-ci-prometheus-federator' export E2E_CI=true -export K3S_VERSION=${K3S_VERSION:-v1.28.14-k3s1} +export K3S_VERSION=${K3S_VERSION:-$K3S_MIN_VERSION_TAG} if k3d cluster list $CLUSTER_NAME 2> /dev/null; then echo "The test cluster '$CLUSTER_NAME' already exists for some reason" @@ -128,6 +129,13 @@ header "Validate Project Prometheus Alerts" header "Validate Project Alertmanager" ./.github/workflows/e2e/scripts/validate-project-alertmanager.sh; +### ALL LOGIC ABOVE THIS +if [ "$DONT_CLEAN" == true ]; then + header "Local e2e testing was a SUCCESS" + header "Exiting early, to leave cluster for testing" + exit; +fi + # Delete Project Prometheus Stack header "Delete Project Prometheus Stack" ./.github/workflows/e2e/scripts/delete-projecthelmchart.sh; @@ -137,8 +145,4 @@ header "Uninstall Prometheus Federator" ./.github/workflows/e2e/scripts/uninstall-federator.sh; header "Local e2e testing was a SUCCESS" -### ALL LOGIC ABOVE THIS -if [ "$DONT_CLEAN" = true ]; then - exit; -fi cleanupTest \ No newline at end of file