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
2e1f037f25
commit
032aa2e59a
2 changed files with 43 additions and 3 deletions
|
|
@ -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.
|
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
|
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
|
image from a peer that holds it (`imagePullPolicy: IfNotPresent`). The first
|
||||||
holds it, for instance because the main node is down and the node never had
|
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
|
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
|
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
|
prune imported tarball images. The mirror doesn't share a `latest` tag, and
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,41 @@ pkgs.testers.runNixOSTest {
|
||||||
return pod(main, name)["status"].get("containerStatuses", [{}])[0]
|
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"):
|
with subtest("the main node is Ready and holds the probe image"):
|
||||||
main.succeed(f"install -d -m 0755 {LEAF_DIR}")
|
main.succeed(f"install -d -m 0755 {LEAF_DIR}")
|
||||||
wait_node_ready(main, timeout=300)
|
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}'")
|
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"
|
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")
|
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"
|
assert pod(main, "on-joiner")["spec"]["nodeName"] == "joiner"
|
||||||
joiner.succeed(f"k3s ctr images ls -q | grep -qxF '{containerd_name}'")
|
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")
|
events = kube(main, "get events --field-selector involvedObject.name=on-joiner -o json")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue