harness: containerlab lab, vm:e2e on a 3-server cluster, k3s-reset node/cluster modes (#31 step 3) #32

Merged
ginjiruu merged 20 commits from clab-harness into main 2026-11-15 04:39:26 +00:00
Owner

Refs #31, #14, #11.

task vm:e2e now runs the full test suite on a containerlab copy of the home network, against a three-server k3s cluster. The old raw-QEMU harness is gone.

Lab

  • lab/lab.clab.yml defines two RouterOS CHR routers in place of the RB5009s, a Linux bridge in place of the CRS309, a CHR acting as the PPPoE ISP, three NixOS VMs (test-01 to test-03) and a client.
  • scripts/harness-ceremony.sh creates a throwaway root CA, and a test OpenBao issues certificates from it.
  • task lab:router-check tests HTTPS, VRRP, PPPoE, WAN, DHCP, firewall zones and IPv6.
  • docs/vm-testing.md explains how to run it.

Bugs the lab found

  • Joining through the VIP fails unless the root CA is in the system trust store.
  • Every host name has to be in pki/clusters/<cluster>.domains. task gate now checks this.
  • The CRS309 trunk has to carry every VLAN. VRRP split on the VLANs it was missing.
  • CA rotation breaks the cluster if you skip step 3, which restarts the other servers. The rotated server fails with Unauthorized on its next reboot. vm:rotate-check now runs step 3, and docs/k3s-ca-rotation.md warns about it.
  • SSH checks could hang forever when they hit a VM mid-reboot. They now time out.

k3s-reset.sh

The script now takes a mode, and old command lines fail with a usage message.

  • --node HOST rebuilds one node and keeps the cluster's data. Another server removes the node, then the script wipes it, reboots it and lets it rejoin.
  • --cluster HOST... wipes every server and starts the cluster again with no data. It refuses unless you list every server.
  • --no-reboot is gone.

vm:reset-check tests both modes.

Tested

task vm:e2e passes in full at e25c820.

On merge

The secrets are re-keyed for test-02 and test-03, so c1 redeploys once with no change.

Refs #31, #14, #11. `task vm:e2e` now runs the full test suite on a containerlab copy of the home network, against a three-server k3s cluster. The old raw-QEMU harness is gone. ## Lab - `lab/lab.clab.yml` defines two RouterOS CHR routers in place of the RB5009s, a Linux bridge in place of the CRS309, a CHR acting as the PPPoE ISP, three NixOS VMs (test-01 to test-03) and a client. - `scripts/harness-ceremony.sh` creates a throwaway root CA, and a test OpenBao issues certificates from it. - `task lab:router-check` tests HTTPS, VRRP, PPPoE, WAN, DHCP, firewall zones and IPv6. - `docs/vm-testing.md` explains how to run it. ## Bugs the lab found - Joining through the VIP fails unless the root CA is in the system trust store. - Every host name has to be in `pki/clusters/<cluster>.domains`. `task gate` now checks this. - The CRS309 trunk has to carry every VLAN. VRRP split on the VLANs it was missing. - CA rotation breaks the cluster if you skip step 3, which restarts the other servers. The rotated server fails with `Unauthorized` on its next reboot. `vm:rotate-check` now runs step 3, and `docs/k3s-ca-rotation.md` warns about it. - SSH checks could hang forever when they hit a VM mid-reboot. They now time out. ## k3s-reset.sh The script now takes a mode, and old command lines fail with a usage message. - `--node HOST` rebuilds one node and keeps the cluster's data. Another server removes the node, then the script wipes it, reboots it and lets it rejoin. - `--cluster HOST...` wipes every server and starts the cluster again with no data. It refuses unless you list every server. - `--no-reboot` is gone. `vm:reset-check` tests both modes. ## Tested `task vm:e2e` passes in full at e25c820. ## On merge The secrets are re-keyed for test-02 and test-03, so c1 redeploys once with no change.
lab: containerlab harness prototype (node image, launcher, lab:* tasks) (#31)
Some checks failed
Validate Nix Flake / validate-nix (push) Has been cancelled
30f949d856
ginjiruu left a comment

Questions on lines the lab can't fully test.

Questions on lines the lab can't fully test.
@ -1 +1 @@
{"creation_rules":[{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq","path_regex":"(^|/)secrets/game\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq","path_regex":"(^|/)secrets/mini\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age126uz65ujpwsjnyzs5yqdrellnylrv3cr470ucqxuyatf4rjngqpq3fk9jr,age12euz3gyut2n0fden44n09yr888euav4p45lw4uz900lslkzejdjq4lc69s,age18jclu24g46l0ltxnjc9q6pfknr6eez9ts54qf2zglfyncmx5js5qnxv25w,age1cft0r0n46zts3cn3n4vswkaauf33xgaemhhs886xnr2yycgcjpcq0r06c9,age1ehr8hm6yrzev8h8u8wx6ufspjftp55kt3wv274g7vvnusyr9kcqsyrya0j,age1qp0cuyzkp6qgvy2hns2hc09yx6gtqlwj56rczd4uv5s3jsr9nqjs856cnh,age1s744yl9q5nkleuxeaxq4a2mc4u3mgk76yt0zvujev8xh4dun7u2s0p230u","path_regex":"(^|/)secrets/c1\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age1r00t88s0u3z0t2gphjl2z8zwx66apfwtj63ucywghkz4xp75x4xqzlalnu","path_regex":"(^|/)secrets/test\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age12euz3gyut2n0fden44n09yr888euav4p45lw4uz900lslkzejdjq4lc69s,age1cft0r0n46zts3cn3n4vswkaauf33xgaemhhs886xnr2yycgcjpcq0r06c9,age1r00t88s0u3z0t2gphjl2z8zwx66apfwtj63ucywghkz4xp75x4xqzlalnu,age1s744yl9q5nkleuxeaxq4a2mc4u3mgk76yt0zvujev8xh4dun7u2s0p230u","path_regex":"(^|/)secrets/flux\\.sops\\.yaml$"}]}
{"creation_rules":[{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq","path_regex":"(^|/)secrets/game\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq","path_regex":"(^|/)secrets/mini\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age126uz65ujpwsjnyzs5yqdrellnylrv3cr470ucqxuyatf4rjngqpq3fk9jr,age12euz3gyut2n0fden44n09yr888euav4p45lw4uz900lslkzejdjq4lc69s,age18jclu24g46l0ltxnjc9q6pfknr6eez9ts54qf2zglfyncmx5js5qnxv25w,age1cft0r0n46zts3cn3n4vswkaauf33xgaemhhs886xnr2yycgcjpcq0r06c9,age1ehr8hm6yrzev8h8u8wx6ufspjftp55kt3wv274g7vvnusyr9kcqsyrya0j,age1qp0cuyzkp6qgvy2hns2hc09yx6gtqlwj56rczd4uv5s3jsr9nqjs856cnh,age1s744yl9q5nkleuxeaxq4a2mc4u3mgk76yt0zvujev8xh4dun7u2s0p230u","path_regex":"(^|/)secrets/c1\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age1pdqwjsnw9ny7e52nsu5m5psp45sanngmnrjpgnteh3pxhjtdremskvfjhd,age1r00t88s0u3z0t2gphjl2z8zwx66apfwtj63ucywghkz4xp75x4xqzlalnu,age1w2n7n7tfch3tkdx20f83fcspfzezjsek42tyn8j22gmdk9d7tv9shpkkex","path_regex":"(^|/)secrets/test\\.sops\\.yaml$"},{"age":"age16fc0q3a4ht2w2mslcyc8hckm7un3yuv70q49mcf7ftj6wvs9gf5qd4g3uq,age12euz3gyut2n0fden44n09yr888euav4p45lw4uz900lslkzejdjq4lc69s,age1cft0r0n46zts3cn3n4vswkaauf33xgaemhhs886xnr2yycgcjpcq0r06c9,age1pdqwjsnw9ny7e52nsu5m5psp45sanngmnrjpgnteh3pxhjtdremskvfjhd,age1r00t88s0u3z0t2gphjl2z8zwx66apfwtj63ucywghkz4xp75x4xqzlalnu,age1s744yl9q5nkleuxeaxq4a2mc4u3mgk76yt0zvujev8xh4dun7u2s0p230u,age1w2n7n7tfch3tkdx20f83fcspfzezjsek42tyn8j22gmdk9d7tv9shpkkex","path_regex":"(^|/)secrets/flux\\.sops\\.yaml$"}]}
Author
Owner

The new keys are for test-02 and test-03. Merging re-encrypts secrets/flux.sops.yaml with the same contents, so c1 redeploys with no change.

The new keys are for test-02 and test-03. Merging re-encrypts `secrets/flux.sops.yaml` with the same contents, so c1 redeploys with no change.
ginjiruu marked this conversation as resolved
@ -44,0 +36,4 @@
# machine-configs checkout (found via git's common dir), so this also works
# from a worktree under ~/.worktrees. Override with FLUX_REPO=...
FLUX_REPO:
sh: echo "${FLUX_REPO:-$(cd "$(git rev-parse --path-format=absolute --git-common-dir)/../.." && pwd)/flux-clusters}"
Author
Owner

vm:push force-pushes the commit checked out in ~/Projects/Personal/lab/flux-clusters to its dev branch. test-01 runs whatever that commit contains.

`vm:push` force-pushes the commit checked out in `~/Projects/Personal/lab/flux-clusters` to its `dev` branch. test-01 runs whatever that commit contains.
ginjiruu marked this conversation as resolved
@ -449,6 +336,26 @@ tasks:
{{.SSH}} "curl -sf -o /dev/null -k -H 'Authorization: Bearer $sat' https://127.0.0.1:6443/api" \
|| { echo "a service-account token from before the rotation no longer authenticates"; exit 1; }
echo "[vm] CAs rotated ($old -> $new), pre-rotation service-account token still accepted"
# Runbook step 3: restart k3s on every OTHER server, one at a time.
Author
Owner

The test restarts the other servers only, because the test cluster has no agents. On c1 you also restart the Pis, and the lab never runs that step.

The test restarts the other servers only, because the test cluster has no agents. On c1 you also restart the Pis, and the lab never runs that step.
Author
Owner

This comment makes no sense, rewrite it with more detail

This comment makes no sense, rewrite it with more detail
ginjiruu marked this conversation as resolved
@ -121,0 +131,4 @@
# cluster. Point it at the VIP for this one join; the driver removes the
# drop-in once the node is back.
if [ -n "${REJOIN_URL:-}" ]; then
run install -D -m 0644 /dev/null /etc/rancher/k3s/config.yaml.d/50-rejoin.yaml
Author
Owner

This file lets a wiped bootstrap leader join the running cluster instead of starting a new one. Line 244 removes it. If the script stops in between, the file stays, and the next full cluster start fails on this host. I can add a trap that removes it on error.

This file lets a wiped bootstrap leader join the running cluster instead of starting a new one. Line 244 removes it. If the script stops in between, the file stays, and the next full cluster start fails on this host. I can add a trap that removes it on error.
Author
Owner

This comment makes no sense and is some of the worst claudeslop I've ever seen, rewrite it with more context

This comment makes no sense and is some of the worst claudeslop I've ever seen, rewrite it with more context
@ -148,0 +170,4 @@
wipe() {
local h=$1
echo "== $h (${IP[$h]}) ${ROLE[$h]} data=${DATA[$h]:-none} openbao=${BAO[$h]} mode=$mode apply=$apply"
remote | RESET_SSH_TIMEOUT=3600 to "$h" "sudo env MODE=$mode APPLY=$apply REBOOT=$2 HOST=$h MARKER=${MARKER[$h]} DATA_DISK=${DATA[$h]} POOL=${POOL[$h]} REJOIN_URL=${3:-} bash -s"
Author
Owner

The wipe gets a one hour timeout. Is that long enough for your largest data disk?

The wipe gets a one hour timeout. Is that long enough for your largest data disk?
ginjiruu marked this conversation as resolved
@ -160,0 +230,4 @@
node=$(on "$peer" "$K get nodes -o name | sed 's|^node/||' | grep -E '^$h(\\.|\$)'" || true)
if [ -n "$node" ]; then
echo "[$h] $peer deletes node $node (k3s removes its etcd member)"
on "$peer" "$K delete node $node --wait=true" >/dev/null
Author
Owner

This deletes the node without draining it first. On c1 that node runs Ceph OSDs and LINSTOR volumes, and the test cluster has neither. Should it drain first?

This deletes the node without draining it first. On c1 that node runs Ceph OSDs and LINSTOR volumes, and the test cluster has neither. Should it drain first?
Author
Owner

Does it matter if it drains first, this is for destroying a node?
I supposed if a node had to be reset to rejoin the cluster.

Does it matter if it drains first, this is for destroying a node? I supposed if a node had to be reset to rejoin the cluster.
ginjiruu marked this conversation as resolved
@ -160,0 +248,4 @@
# --cluster
for s in "${all_servers[@]}"; do
printf '%s\n' "${hosts[@]}" | grep -qx "$s" || { echo "--cluster needs every server of $c; $s is missing" >&2; exit 1; }
Author
Owner

--cluster wipes the data disk on every server, so all Ceph and LINSTOR data is lost. The only check is that you listed every server. Should it also make you type the cluster name?

`--cluster` wipes the data disk on every server, so all Ceph and LINSTOR data is lost. The only check is that you listed every server. Should it also make you type the cluster name?
Author
Owner

No, every node name is probably good enough

No, every node name is probably good enough
@ -160,0 +266,4 @@
for h in "$leader" "${servers[@]}"; do
on "$h" "systemd-run --on-active=5 --unit=k3s-reset-reboot systemctl reboot" >/dev/null
wait_reboot "$h" "${B0[$h]}"
wait_bao "$h"
Author
Owner

The script waits for OpenBao to unseal before it reboots the next server. The test VMs don't run OpenBao, so the lab never runs this wait.

The script waits for OpenBao to unseal before it reboots the next server. The test VMs don't run OpenBao, so the lab never runs this wait.
Author
Owner

Why shouldn't the test vms run openbao?

Why shouldn't the test vms run openbao?
ginjiruu left a comment

Replies.

Replies.
@ -449,6 +336,26 @@ tasks:
{{.SSH}} "curl -sf -o /dev/null -k -H 'Authorization: Bearer $sat' https://127.0.0.1:6443/api" \
Author
Owner

More detail. Step 3 of docs/k3s-ca-rotation.md says to restart k3s on every other server, then on every agent, one node at a time. Agents are nodes that run workloads but not the control plane. On c1 those are the Pis.

The test cluster has three servers and no agents. So this test restarts test-02 and test-03, then checks that all three servers hold the same CAs. The agent half of step 3 never runs in the lab, so we haven't seen a Pi pick up rotated CAs after a restart. Adding one agent VM to the lab would cover it.

More detail. Step 3 of `docs/k3s-ca-rotation.md` says to restart k3s on every other server, then on every agent, one node at a time. Agents are nodes that run workloads but not the control plane. On c1 those are the Pis. The test cluster has three servers and no agents. So this test restarts test-02 and test-03, then checks that all three servers hold the same CAs. The agent half of step 3 never runs in the lab, so we haven't seen a Pi pick up rotated CAs after a restart. Adding one agent VM to the lab would cover it.
ginjiruu marked this conversation as resolved
@ -121,0 +131,4 @@
# cluster. Point it at the VIP for this one join; the driver removes the
# drop-in once the node is back.
if [ -n "${REJOIN_URL:-}" ]; then
run install -D -m 0644 /dev/null /etc/rancher/k3s/config.yaml.d/50-rejoin.yaml
Author
Owner

More context. The first server in each cluster, the bootstrap leader (test-01 here, think-01 on c1), has no server: line in its k3s config. On a cold start it has to create the cluster, so it can't point at anyone. Every other server joins through the VIP.

When --node wipes the leader and reboots it, k3s would read that config and create a new, empty cluster beside the real one. To stop that, the script writes /etc/rancher/k3s/config.yaml.d/50-rejoin.yaml with server: https://<VIP>:6443 before the reboot, so the leader joins the existing cluster. Once the node is Ready, line 244 deletes the file.

The risk is a run that dies between the reboot and line 244, for example your laptop losing its connection. The file then stays on the leader. Nothing breaks right away. It matters the next time the whole cluster is down at once, because the leader would try to join a VIP that nobody holds and k3s would never start.

A trap in the script won't help if the laptop is what died. Two options. node-health could flag the file if it's still there an hour after boot. Or we accept it and you remove it by hand if a reset run gets interrupted. Which do you prefer?

More context. The first server in each cluster, the bootstrap leader (test-01 here, think-01 on c1), has no `server:` line in its k3s config. On a cold start it has to create the cluster, so it can't point at anyone. Every other server joins through the VIP. When `--node` wipes the leader and reboots it, k3s would read that config and create a new, empty cluster beside the real one. To stop that, the script writes `/etc/rancher/k3s/config.yaml.d/50-rejoin.yaml` with `server: https://<VIP>:6443` before the reboot, so the leader joins the existing cluster. Once the node is Ready, line 244 deletes the file. The risk is a run that dies between the reboot and line 244, for example your laptop losing its connection. The file then stays on the leader. Nothing breaks right away. It matters the next time the whole cluster is down at once, because the leader would try to join a VIP that nobody holds and k3s would never start. A trap in the script won't help if the laptop is what died. Two options. node-health could flag the file if it's still there an hour after boot. Or we accept it and you remove it by hand if a reset run gets interrupted. Which do you prefer?
@ -160,0 +230,4 @@
node=$(on "$peer" "$K get nodes -o name | sed 's|^node/||' | grep -E '^$h(\\.|\$)'" || true)
if [ -n "$node" ]; then
echo "[$h] $peer deletes node $node (k3s removes its etcd member)"
on "$peer" "$K delete node $node --wait=true" >/dev/null
Author
Owner

Agreed, no drain. --node is only used on a node you're wiping anyway. Deleting the node object makes Kubernetes reschedule its pods on other nodes, and the reset wipes the OSD and volume data on that node regardless. Leaving it as is.

Agreed, no drain. `--node` is only used on a node you're wiping anyway. Deleting the node object makes Kubernetes reschedule its pods on other nodes, and the reset wipes the OSD and volume data on that node regardless. Leaving it as is.
ginjiruu marked this conversation as resolved
@ -160,0 +248,4 @@
# --cluster
for s in "${all_servers[@]}"; do
printf '%s\n' "${hosts[@]}" | grep -qx "$s" || { echo "--cluster needs every server of $c; $s is missing" >&2; exit 1; }
Author
Owner

OK, keeping the every-server check as the only guard.

OK, keeping the every-server check as the only guard.
@ -160,0 +266,4 @@
for h in "$leader" "${servers[@]}"; do
on "$h" "systemd-run --on-active=5 --unit=k3s-reset-reboot systemctl reboot" >/dev/null
wait_reboot "$h" "${B0[$h]}"
wait_bao "$h"
Author
Owner

No good reason. The harness runs a single OpenBao on the host machine, which was simpler to set up. On c1, OpenBao runs on the three thinks next to k3s. Running it on test-01 to test-03 as a three-node Raft cluster would match that, and it would exercise this wait and the same quorum guard in --cluster.

It's a sizeable harness change, covering unseal, Raft join and host enrollment against the in-cluster OpenBao. Do you want it in this PR or a follow-up?

No good reason. The harness runs a single OpenBao on the host machine, which was simpler to set up. On c1, OpenBao runs on the three thinks next to k3s. Running it on test-01 to test-03 as a three-node Raft cluster would match that, and it would exercise this wait and the same quorum guard in `--cluster`. It's a sizeable harness change, covering unseal, Raft join and host enrollment against the in-cluster OpenBao. Do you want it in this PR or a follow-up?
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/machine-configs!32
No description provided.