Skip to content

Commit 302e08d

Browse files
committed
test(kairos): run component canaries
1 parent 0aa288d commit 302e08d

6 files changed

Lines changed: 90 additions & 9 deletions

File tree

.github/workflows/image-kairos-fedora.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,33 @@ on: # yamllint disable-line rule:truthy
66
branches:
77
- main
88
paths:
9-
- .devcontainer/Dockerfile
9+
- .devcontainer/**
1010
- .github/workflows/image-kairos-fedora.yml
11+
- ansible/**
1112
- images/kairos-fedora/**
1213
- justfile
14+
- kustomization/**
1315
tags:
1416
- kairos-fedora-*
1517
pull_request:
1618
branches:
1719
- main
1820
paths:
19-
- .devcontainer/Dockerfile
21+
- .devcontainer/**
2022
- .github/workflows/image-kairos-fedora.yml
23+
- ansible/**
2124
- images/kairos-fedora/**
2225
- justfile
26+
- kustomization/**
2327

2428
jobs:
2529
build-container:
30+
name: E2E (${{ matrix.component }})
2631
runs-on: ubuntu-24.04
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
component: ${{ github.ref_type == 'tag' && fromJSON('["priorityclass"]') || fromJSON('["kube-vip", "priorityclass"]') }}
2736
timeout-minutes: 90
2837
permissions:
2938
contents: read
@@ -63,7 +72,19 @@ jobs:
6372
- name: Install E2E Dependencies
6473
run: |
6574
sudo apt-get update
66-
sudo apt-get install --no-install-recommends --yes curl openssh-client ovmf qemu-system-x86 qemu-utils
75+
sudo apt-get install --no-install-recommends --yes curl openssh-client ovmf python3-venv qemu-system-x86 qemu-utils
76+
77+
python3 -m venv "${RUNNER_TEMP}/kairos-e2e-venv"
78+
"${RUNNER_TEMP}/kairos-e2e-venv/bin/pip" install --requirement ansible/requirements.txt
79+
"${RUNNER_TEMP}/kairos-e2e-venv/bin/ansible-galaxy" collection install --force ansible
80+
echo "${RUNNER_TEMP}/kairos-e2e-venv/bin" >> "$GITHUB_PATH"
81+
82+
mkdir -p "${RUNNER_TEMP}/kustomize-bin"
83+
kustomize_container="$(docker create registry.k8s.io/kustomize/kustomize:v5.8.1@sha256:899fcd3bc898160e62bcaf82932b0cb29ba38d16272353db2e7acbba82129429)"
84+
trap 'docker rm --force "$kustomize_container" >/dev/null' EXIT
85+
docker cp "${kustomize_container}:/app/kustomize" "${RUNNER_TEMP}/kustomize-bin/kustomize"
86+
chmod 0755 "${RUNNER_TEMP}/kustomize-bin/kustomize"
87+
echo "${RUNNER_TEMP}/kustomize-bin" >> "$GITHUB_PATH"
6788
- name: Enable KVM Access
6889
run: |
6990
test -e /dev/kvm
@@ -73,13 +94,14 @@ jobs:
7394
ls -l /dev/kvm
7495
- name: Run Kairos Fedora E2E
7596
env:
97+
E2E_KUSTOMIZATION_TEST: ${{ matrix.component }}
7698
KAIROS_IMAGE: ghcr.io/${{ github.repository_owner }}/kairos-fedora:${{ steps.version_tag.outputs.tag }}
7799
run: bash images/kairos-fedora/e2e.sh
78100
- name: Upload E2E Logs
79101
if: always()
80102
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
81103
with:
82-
name: kairos-fedora-e2e
104+
name: kairos-fedora-e2e-${{ matrix.component }}
83105
path: |
84106
build/e2e/kairos-fedora/install-cloud-config.yaml
85107
build/e2e/kairos-fedora/id_ed25519.pub

ansible/roles/minikube_test/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
# https://minikube.sigs.k8s.io/docs/tutorials/local_path_provisioner/
66
minikube_test__enable_local_path_storage: false
77

8+
# If this role should provision a minikube cluster. Disable this to apply the
9+
# kustomization to an existing Kubernetes context.
10+
minikube_test__provision_cluster: true
11+
812
# renovate: datasource=github-releases depName=kubernetes/kubernetes
913
minikube_test__kubernetes_version: v1.36.2
1014

ansible/roles/minikube_test/tasks/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
# tasks file for minikube_test
33
- name: Start minikube
4+
when: minikube_test__provision_cluster | bool
45
ansible.builtin.command:
56
argv:
67
- minikube
@@ -13,7 +14,9 @@
1314
changed_when: true
1415
notify: stop minikube
1516
- name: Setup local path provisioner
16-
when: minikube_test__enable_local_path_storage | bool
17+
when:
18+
- minikube_test__provision_cluster | bool
19+
- minikube_test__enable_local_path_storage | bool
1720
block:
1821
- name: Enable local path provisioner
1922
ansible.builtin.command:

images/kairos-fedora/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,32 @@ The harness validates the same path a bare-metal install uses:
1919
3. Boot the installer ISO in QEMU.
2020
4. Submit the install through the Kairos WebUI on port 8080.
2121
5. Power off, detach the ISO, boot from the installed disk, and verify the OS over SSH.
22+
6. Reboot into the immutable system and verify SSH and K3s again.
23+
24+
Pass a component name to apply its existing kustomization test to K3s after the immutable reboot:
25+
26+
```sh
27+
just e2e-kairos-fedora priorityclass
28+
```
2229

2330
By default, `just e2e-kairos-fedora` builds `images/kairos-fedora/Containerfile` locally as `kairos-fedora:0.0.0-e2e`. Set `KAIROS_IMAGE` to test a specific image ref that already exists in Docker or can be pulled by AuroraBoot:
2431

2532
```sh
2633
KAIROS_IMAGE=ghcr.io/marinatedconcrete/kairos-fedora:0.8.1 just e2e-kairos-fedora
2734
```
2835

36+
When iterating on a component, reuse an existing installer ISO to skip both the image and ISO builds:
37+
38+
```sh
39+
KAIROS_ISO=/path/to/kairos-fedora.iso just e2e-kairos-fedora priorityclass
40+
```
41+
2942
Useful overrides:
3043

3144
- `KAIROS_IMAGE`: OCI image ref to convert into an installer ISO.
3245
- `KAIROS_ISO`: existing ISO path for debugging the boot/install path without regenerating media.
3346
- `E2E_WORKDIR`: artifact and log directory, default `build/e2e/kairos-fedora`.
47+
- `E2E_K3S_PORT`: host port forwarded to the guest K3s API, default `16443`.
3448
- `E2E_INSTALL_TIMEOUT`, `E2E_BOOT_TIMEOUT`, `E2E_K3S_TIMEOUT`: timeout overrides.
3549

3650
The CI workflow runs the same script after building the image into the local Docker daemon. On release tags, the workflow pushes the image only after the e2e test passes.

images/kairos-fedora/e2e.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ E2E_BOOT_TIMEOUT="${E2E_BOOT_TIMEOUT:-15m}"
4242
E2E_K3S_TIMEOUT="${E2E_K3S_TIMEOUT:-10m}"
4343
E2E_WEBUI_PORT="${E2E_WEBUI_PORT:-18080}"
4444
E2E_SSH_PORT="${E2E_SSH_PORT:-10022}"
45+
E2E_K3S_PORT="${E2E_K3S_PORT:-16443}"
46+
E2E_KUSTOMIZATION_TEST="${E2E_KUSTOMIZATION_TEST:-}"
4547
KAIROS_E2E_VERSION="${KAIROS_E2E_VERSION:-0.0.0-e2e}"
4648
# renovate: datasource=docker depName=quay.io/kairos/auroraboot
4749
AURORABOOT_IMAGE="${AURORABOOT_IMAGE:-quay.io/kairos/auroraboot:v0.20.1}"
@@ -50,6 +52,7 @@ logs_dir="${E2E_WORKDIR}/logs"
5052
disk_path="${E2E_WORKDIR}/kairos-fedora.qcow2"
5153
ssh_key="${E2E_WORKDIR}/id_ed25519"
5254
cloud_config="${E2E_WORKDIR}/install-cloud-config.yaml"
55+
kubeconfig="${E2E_WORKDIR}/kubeconfig"
5356
qemu_pid=""
5457
ssh_ready=0
5558
phase="host"
@@ -192,7 +195,7 @@ start_qemu() {
192195
else
193196
qemu_args+=(
194197
-boot "order=c,menu=off"
195-
-netdev "user,id=net0,hostfwd=tcp:127.0.0.1:${E2E_SSH_PORT}-:22"
198+
-netdev "user,id=net0,hostfwd=tcp:127.0.0.1:${E2E_SSH_PORT}-:22,hostfwd=tcp:127.0.0.1:${E2E_K3S_PORT}-:6443"
196199
-device "virtio-net-pci,netdev=net0"
197200
)
198201
fi
@@ -358,6 +361,29 @@ reboot_and_wait_for_ssh() {
358361
die "SSH did not become reachable after reboot before ${E2E_BOOT_TIMEOUT}"
359362
}
360363

364+
write_kubeconfig() {
365+
log "Writing host kubeconfig for K3s on localhost:${E2E_K3S_PORT}"
366+
ssh_cmd 'sudo -n cat /etc/rancher/k3s/k3s.yaml' >"$kubeconfig"
367+
sed -i "s#server: https://127.0.0.1:6443#server: https://127.0.0.1:${E2E_K3S_PORT}#" "$kubeconfig"
368+
chmod 0600 "$kubeconfig"
369+
grep -q "server: https://127.0.0.1:${E2E_K3S_PORT}" "$kubeconfig" || die "failed to rewrite K3s server in ${kubeconfig}"
370+
}
371+
372+
run_kustomization_test() {
373+
local component="$1"
374+
local playbook="${repo_root}/kustomization/tests/${component}/test.yml"
375+
local test_log="${logs_dir}/kustomization-${component}.log"
376+
377+
[[ "$component" =~ ^[a-z0-9][a-z0-9-]*$ ]] || die "invalid kustomization test name: ${component}"
378+
[[ -f "$playbook" ]] || die "kustomization test does not exist: ${component}"
379+
380+
log "Running ${component} kustomization test against Kairos K3s"
381+
KUBECONFIG="$kubeconfig" ansible-playbook "$playbook" \
382+
--extra-vars minikube_test__provision_cluster=false \
383+
--extra-vars kubernetes_core_k8s__context=default \
384+
2>&1 | tee "$test_log"
385+
}
386+
361387
collect_ssh_diagnostics() {
362388
[[ "$ssh_ready" == 1 ]] || return 0
363389

@@ -386,6 +412,7 @@ on_exit() {
386412
fi
387413

388414
cleanup_qemu
415+
rm -f -- "$kubeconfig"
389416
exit "$status"
390417
}
391418

@@ -429,11 +456,16 @@ main() {
429456
require_cmd ssh
430457
require_cmd ssh-keygen
431458

459+
if [[ -n "$E2E_KUSTOMIZATION_TEST" ]]; then
460+
require_cmd ansible-playbook
461+
require_cmd kustomize
462+
fi
463+
432464
[[ -e /dev/kvm ]] || die "/dev/kvm is unavailable; enable KVM before running this test"
433465
[[ -r /dev/kvm && -w /dev/kvm ]] || die "/dev/kvm exists but is not readable and writable by this user"
434466

435467
mkdir -p "$logs_dir"
436-
if [[ -z "${KAIROS_IMAGE:-}" ]]; then
468+
if [[ -z "${KAIROS_IMAGE:-}" && -z "${KAIROS_ISO:-}" ]]; then
437469
build_default_image "$kairos_image"
438470
fi
439471

@@ -466,6 +498,12 @@ main() {
466498
reboot_and_wait_for_ssh
467499
run_guest_checks
468500

501+
if [[ -n "$E2E_KUSTOMIZATION_TEST" ]]; then
502+
phase="kustomization-${E2E_KUSTOMIZATION_TEST}"
503+
write_kubeconfig
504+
run_kustomization_test "$E2E_KUSTOMIZATION_TEST"
505+
fi
506+
469507
phase="complete"
470508
log "Kairos Fedora e2e completed successfully"
471509
}

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ lint: ansible-lint hado-lint kustomize-lint renovate-lint shellcheck-lint
221221

222222
# Run the Kairos Fedora boot/install end-to-end test
223223
[group('test')]
224-
e2e-kairos-fedora:
224+
e2e-kairos-fedora component="":
225225
#!/usr/bin/env bash
226226
set -euo pipefail
227-
bash images/kairos-fedora/e2e.sh
227+
E2E_KUSTOMIZATION_TEST="{{ component }}" bash images/kairos-fedora/e2e.sh
228228
229229
# Run a single test
230230
[group('test')]

0 commit comments

Comments
 (0)