Watch
0
0
Fork
You've already forked hyperhive
0

k8s-join: wait through a pull from a peer that fails first, and print the registry state when it keeps failing

This commit is contained in:
atlas 2026-11-26 01:31:33 +01:00 • committed by maia
commit 87349989ac
2 changed files with 43 additions and 3 deletions

View file

@ -83,8 +83,9 @@ enables for mirroring, and the upstream registry doesn't have to exist
host and not `"*"`, so the node's pulls of public images stay direct.
A pod that lands on a node without its image, a node that joined, pulls the
image from a peer that holds it (`imagePullPolicy: IfNotPresent`). If no peer
holds it, for instance because the main node is down and the node never had
image from a peer that holds it (`imagePullPolicy: IfNotPresent`). The first
pull on a node that has just joined can end in `ErrImagePull`, and the kubelet
retries a failed pull. If no peer holds it, for instance because the main node is down and the node never had
the image, the pull fails with the host's name in the error, and the pod
retries once a peer has the image. Images a node holds stay: k3s doesn't
prune imported tarball images. The mirror doesn't share a `latest` tag, and

View file

@ -260,6 +260,41 @@ pkgs.testers.runNixOSTest {
return pod(main, name)["status"].get("containerStatuses", [{}])[0]
def wait_running(name: str, timeout: int) -> None:
"""Waits until pod `name` runs. A pull can fail before the joining machine knows
which peer holds the image, and the kubelet retries it, so those errors are
waited through."""
deadline = time.monotonic() + timeout
pull_errors: set[str] = set()
while True:
p = pod(main, name)
if p["status"].get("phase") == "Running" and is_ready(p):
print(f"{name}: running after pull errors {sorted(pull_errors)}")
return
reason = first_status(name).get("state", {}).get("waiting", {}).get("reason")
if reason in ("ErrImagePull", "ImagePullBackOff"):
pull_errors.add(reason)
else:
assert reason in (None, "ContainerCreating"), (name, first_status(name))
assert time.monotonic() < deadline, (name, p["status"])
time.sleep(3)
def dump(title: str, node: QemuMachine, command: str) -> None:
print(f"--- {title}")
print(node.execute(command)[1])
def diagnose_pull() -> None:
for node in (main, joiner):
dump(f"{node.name}: containerd config", node, "cat /var/lib/rancher/k3s/agent/etc/containerd/config.toml")
dump(f"{node.name}: registries", node, "cat /etc/rancher/k3s/registries.yaml; ls /var/lib/rancher/k3s/agent/etc/containerd/certs.d/ 2>&1")
dump(f"{node.name}: images", node, "k3s ctr images ls -q")
dump(f"{node.name}: content", node, "k3s ctr content ls | head -50")
dump("main: pod events", main, "kubectl get events --sort-by=.lastTimestamp | tail -30")
dump("joiner: pull through its own mirror", joiner, "curl -sk -o /dev/null -w '%{http_code}' https://127.0.0.1:6443/v2/ ; echo; journalctl -u k3s --no-pager -n 60 | grep -i -E 'spegel|registry|pull' | tail -30")
with subtest("the main node is Ready and holds the probe image"):
main.succeed(f"install -d -m 0755 {LEAF_DIR}")
wait_node_ready(main, timeout=300)
@ -348,7 +383,11 @@ pkgs.testers.runNixOSTest {
main.succeed(f"k3s ctr images ls -q | grep -qxF '{containerd_name}'")
assert joiner.execute(f"k3s ctr images ls -q | grep -qxF '{containerd_name}'")[0] != 0, "the machine held the image already"
main.succeed("kubectl apply -f /etc/k8s-join/pod-on-joiner.json")
wait_pod(main, "on-joiner", phase="Running", ready=True, timeout=300)
try:
wait_running("on-joiner", 300)
except AssertionError:
diagnose_pull()
raise
assert pod(main, "on-joiner")["spec"]["nodeName"] == "joiner"
joiner.succeed(f"k3s ctr images ls -q | grep -qxF '{containerd_name}'")
events = kube(main, "get events --field-selector involvedObject.name=on-joiner -o json")