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:
parent
052b559196
commit
f7696a59c1
1 changed files with 43 additions and 3 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue