Skip to content

Commit

Permalink
fix(ci): Correct k3s version used for e2e testing (#172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mallardduck authored Feb 14, 2025
1 parent d84ee5f commit 5ffb997
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 19 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/hl-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/hpo-e2e-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -60,14 +57,18 @@ 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;
BUILD_TARGET=helm-project-operator REPO=${REPO} TAG=${TAG} ./scripts/package;
- 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";
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/prom-fed-e2e-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
Expand All @@ -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: |
Expand All @@ -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: |
Expand Down
4 changes: 3 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rancherProjectMonitoringVersion: 0.3.4
rancherProjectMonitoringVersion: 0.3.4
k3sTestingMaxVersion: v1.32.1+k3s1
k3sTestingMinVersion: v1.30.9+k3s1
2 changes: 2 additions & 0 deletions pkg/buildconfig/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions scripts/k3s-version
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions scripts/local-e2e
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

DONT_CLEAN=false
DONT_CLEAN=${DONT_CLEAN:-false}

header() {
local text="$1"
Expand All @@ -22,22 +22,23 @@ cleanupTest() {
}

onExit() {
if [[ "$?" -eq 0 ]]; then
if [[ "$?" -eq 0 ]] || [ "$DONT_CLEAN" == true ]; then
exit 0
fi

cleanupTest
}
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"
Expand Down Expand Up @@ -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;
Expand All @@ -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

0 comments on commit 5ffb997

Please sign in to comment.