Files
cozystack/hack/e2e-prepull-images.sh
Myasnikov Daniil 186547d835 test(e2e): run the merge-gating lanes on Talos containers
The srv1-srv3 nodes of both lanes that gate a merge -- the same-repo one
in pull-requests.yaml and the fork one in e2e-fork.yaml -- run as Talos
containers instead of QEMU guests, so a tenant worker sits at L2 rather
than L3. Measured in CI on commits where both substrates ran the same
tree: whole-job wall clock down 24-49 minutes, essentially all of it in
Chainsaw, while the two tenant-Kubernetes suites go from 1143-2040s to
466-809s and stop depending on the runner's vgif flag.

The node-join soft-red gate goes with the substrate, which is what it
was for. It existed because nested virtualisation on the shared runners
degraded far enough that a worker registering in minutes elsewhere could
miss any deadline this test could afford; #3513 established that the
discriminator was the host's kvm_amd vgif flag, and removing a nesting
level removes what it acted on. So hack/e2e-node-join-soft-red.sh, the
SOFT-RED-node-join.txt marker and the soft_red job outputs are gone from
all four workflows, and a missed deadline is an ordinary red again. The
::warning annotation survives, because the reason a run went red should
be legible without opening the log, and so does the 124-versus-everything
-else test, because "the workers were slow" and "the wait never ran"
send a reader to different places.

Done by swapping the substrate inside the existing e2e jobs rather than
by promoting a separate container job. Those jobs carry more than a
substrate -- the GitHub App token, the report-overrun guard, the images
list, the SSH breakpoint -- and promoting a job that never had them
would have dropped four features without saying so.

Three properties of container mode drive the design, and each fails
quietly rather than loudly. machine.kernel.modules is a silent no-op --
kernel_module_spec.go returns early on ModeContainer with no error and
no event -- so the host loads openvswitch and zfs before the nodes start
and the workflow step asserts both rather than trusting them; a missing
module surfaces an hour later looking like a CNI or a storage
regression. Docker gives a privileged container its own tmpfs /dev
seeded once at creation, so /dev/kvm works but ZFS zvols created later
never appear and linstor-csi fails ControllerPublishVolume; the compose
file binds the host devtmpfs, which is also why talosctl cluster create
docker can never carry LINSTOR. And there is no ARP VIP, so
192.168.123.11 stands in for the QEMU lane's .10.

The QEMU machinery stays in the tree and keeps running: nightly.yaml and
e2e-tag.yaml still call `make prepare-env`, so DRBD, the replicated
StorageClass, its Immediate binding mode, the tenant StorageClass
propagation that only applies to remotely-accessible classes, and the
Cozystack Talos node image with its extensions all keep nightly and
release-candidate coverage. None of them is exercised per pull request
any more. That is the trade.

Nothing on the PR path builds or downloads a nocloud disk now, so
build-talos drops the talos-nocloud step and the talos-image artifact.
build-talos itself stays: finalize consumes its digest fragment.

One property this does not fix, recorded beside the runner class because
it will be read off a red run eventually: a container node reports the
HOST's CPU and memory as capacity, and hack/e2e-container-up.sh counters
that with kubelet systemReserved. That corrects the scheduler and not
what a pod reads from /proc, so a workload sizing itself from
/proc/cpuinfo or /proc/meminfo is configured for the whole runner.

Also carried here because the same files carry them: the ghcr.io
pull-through mirror removal (see #4007 -- whichever lands first makes the
other a no-op), the authoritative HelmRelease readiness gate, the
backup-credential preflight, the prepull guard against an image-less
container fragment, and folding the two standalone OIDC suites into the
latest-version tenant cluster.

Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-09-05 13:19:17 +05:00

113 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Pre-pull images to all cluster nodes.
#
# Reads image references from stdin, one per line. Empty lines and lines
# starting with '#' are ignored.
#
# Some workloads (OVN raft, LINSTOR, cert-manager) are sensitive to slow or
# staggered pulls at install time: a HelmRelease can time out while one node
# is still pulling. Pre-pulling eliminates the stagger.
#
# Distroless images (cert-manager, etc.) ship no shell or `sleep`, so we
# can't just `command: ["sleep", "infinity"]`. Trick: an initContainer copies
# busybox (a static binary) into a shared emptyDir, then every prepull
# container execs /shared/sleep — the kernel execve's the binary from the
# volume, the container's filesystem doesn't need to provide it.
set -euo pipefail
cleanup() {
kubectl delete daemonset e2e-image-prepuller -n kube-system --ignore-not-found
}
trap cleanup EXIT
mapfile -t images < <(grep -Ev '^[[:space:]]*(#|$)' | sort -u)
if [[ ${#images[@]} -eq 0 ]]; then
echo "e2e-prepull-images: no images on stdin, nothing to do" >&2
exit 0
fi
echo "Pre-pulling ${#images[@]} image(s):"
printf ' %s\n' "${images[@]}"
# A literal `null` means the caller's yq filter matched a container that has
# no `image:` field -- typically a strategic-merge pod-template fragment
# inside a CR, which overrides a few fields and pulls nothing. Catch it here:
# passed through, it becomes a container with an empty image and `kubectl
# apply` rejects the DaemonSet by container index, naming neither the filter
# nor the chart that produced it.
for image in "${images[@]}"; do
if [[ "$image" == "null" ]]; then
echo "e2e-prepull-images: refusing a literal 'null' image reference." >&2
echo " Some container in the caller's yq filter has no 'image:' field." >&2
echo " Drop nulls at the source (see hack/e2e-install-cozystack.bats)." >&2
exit 1
fi
done
containers=""
i=0
for image in "${images[@]}"; do
containers+="
- name: pull-${i}
image: ${image}
command: [\"/shared/sleep\", \"infinity\"]
imagePullPolicy: IfNotPresent
volumeMounts:
- name: bin
mountPath: /shared
resources:
requests:
cpu: 1m
memory: 1Mi"
i=$((i + 1))
done
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: e2e-image-prepuller
namespace: kube-system
labels:
app: e2e-image-prepuller
spec:
selector:
matchLabels:
app: e2e-image-prepuller
template:
metadata:
labels:
app: e2e-image-prepuller
spec:
# hostNetwork bypasses the CNI: this script runs BEFORE Cozystack
# installs kube-ovn, so a normal pod would stay ContainerCreating with
# NetworkPluginNotReady.
hostNetwork: true
automountServiceAccountToken: false
tolerations:
- operator: Exists
initContainers:
# Stage a static \`sleep\` into the shared volume so distroless images
# (no shell, no /bin/sleep) can still keep their container alive.
# musl tag = statically linked; the glibc default needs an ELF
# interpreter that distroless images don't ship, so execve fails with
# "no such file or directory" even though the binary is right there.
- name: stage-sleep
image: busybox:musl
command: ["cp", "/bin/busybox", "/shared/sleep"]
volumeMounts:
- name: bin
mountPath: /shared
volumes:
- name: bin
emptyDir: {}
containers:${containers}
EOF
echo "Waiting for e2e-image-prepuller DaemonSet to become ready..."
kubectl rollout status daemonset/e2e-image-prepuller -n kube-system --timeout=10m
echo "Image pre-pull complete."