# ============================================================================= # L3 FAULT-INJECTION — VM disk survives rebuild (R-STATE-01) [RUNNABLE / self-skips] # *SAFETY-CRITICAL* # Catalog: docs/14 "Data survival (R-STATE-01, L3)" — the IaaS partner of the # container `data-survival` test. Spec: docs/04, docs/06, ADR-0005. # # GIVEN a VM that writes data to a Longhorn-backed disk, # WHEN the VM is DESTROYED entirely (kept: the Longhorn PVC/DataVolume), # THEN the data is intact and readable by a fresh workload bound to that PVC — # exactly the container proof (data-survival), now for a KubeVirt VM # (R-STATE-01 covers PaaS + IaaS). # # METHOD (virtctl-free, filesystem-agnostic, deterministic): a containerDisk-root # VM (ephemeral) with a Longhorn BLOCK data disk. cloud-init writes a unique canary # to the raw block device and powers the guest off; runStrategy RerunOnFailure means # a clean shutdown STAYS down (VMI -> Succeeded), so the write is known-complete and # the disk is released. We then DELETE the VM (keeping the PVC) and bind a throwaway # busybox reader pod to the SAME Longhorn PVC as a raw block device — if the bytes # match, the data survived the VM's destruction. No SSH/console scraping, no guest # filesystem parsing. # # RUNNABLE / SELF-SKIPPING: skips cleanly (green) until BOTH KubeVirt and a # `longhorn` StorageClass exist; runs the full destroy/rebuild survival check once # they do. Hermetic: everything lives in the chainsaw per-test namespace. # ============================================================================= apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: name: vm-data-survival labels: conformance.home.k3s/R-STATE-01: "true" annotations: conformance.home.k3s/requirements: "R-STATE-01" conformance.home.k3s/layer: "L3" conformance.home.k3s/safety-critical: "true" conformance.home.k3s/executable: "true" conformance.home.k3s/intent: >- Destroy a VM entirely, keep its Longhorn PVC, and a fresh workload re-bound to that PVC still reads the VM-written data. Skips cleanly until KubeVirt + longhorn exist. spec: # Boot a guest + run cloud-init + power off, then reattach a Longhorn RWO volume — far beyond 180s. timeouts: exec: 20m steps: - name: vm-data-survives-destroy-and-rebuild try: - script: content: | set -euo pipefail NS="$NAMESPACE" # -- Gate: skip cleanly (green) until BOTH KubeVirt and longhorn are present. -- if ! kubectl get crd virtualmachineinstances.kubevirt.io >/dev/null 2>&1; then echo "SKIP: KubeVirt CRDs absent — vm-data-survival not applicable yet" echo VM_DATA_SURVIVAL_SKIPPED_OK; exit 0 fi if ! kubectl get storageclass longhorn >/dev/null 2>&1; then echo "SKIP: 'longhorn' StorageClass absent — vm-data-survival not applicable yet" echo VM_DATA_SURVIVAL_SKIPPED_OK; exit 0 fi CANARY="vm-canary-$(date +%s%N)" # fixed-length, unique per run LEN=${#CANARY} # -- GIVEN: a Longhorn BLOCK PVC for the VM's data disk. -- kubectl -n "$NS" apply -f - < a clean poweroff STAYS Succeeded (not restarted), so the write is # known-complete and the disk released. Only $CANARY expands (no other '$' in the body). kubectl -n "$NS" apply -f - </dev/null || true)" if [ "$phase" = "Succeeded" ] || { [ -z "$phase" ] && [ "$i" -gt 3 ]; }; then ok=1; break; fi sleep 10 done [ -n "$ok" ] || { echo "FAIL: guest never completed the write+poweroff (last phase='$phase')" >&2; exit 1; } echo "guest wrote canary and powered off" # -- FAULT INJECTION: destroy the VM ENTIRELY; KEEP the Longhorn PVC. -- kubectl -n "$NS" delete vm survivor --wait=true --timeout=180s kubectl -n "$NS" get pvc vm-survivor # must still exist # -- THEN: a fresh workload re-bound to the SAME Longhorn PVC still sees the bytes. -- kubectl -n "$NS" apply -f - </dev/null")" echo "recovered='$GOT' expected='$CANARY'" [ "$GOT" = "$CANARY" ] && echo VM_DATA_SURVIVED_OK check: (contains($stdout, 'VM_DATA_SURVIVED_OK') || contains($stdout, 'VM_DATA_SURVIVAL_SKIPPED_OK')): true finally: - script: content: | kubectl -n "$NAMESPACE" delete vm survivor --ignore-not-found --wait=false || true kubectl -n "$NAMESPACE" delete pod reader --ignore-not-found --wait=false || true kubectl -n "$NAMESPACE" delete pvc vm-survivor --ignore-not-found --wait=false || true echo "cleanup best-effort; chainsaw namespace teardown finalizes"