test(eks): log pod and k3s state when the registry-hosts pod does not run (#7661)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-06 18:57:20 -04:00
1 parent 7cf443fcee
commit a489144c5a
1 file changed
+53
@@ -1,6 +1,8 @@
package io.floci.aws.services.eks;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.model.Frame;
import io.floci.aws.core.common.Digests;
import io.floci.aws.core.common.docker.ContainerExec;
import io.floci.aws.core.common.docker.DockerHostResolver;
@@ -249,10 +251,61 @@ class EksRegistryHostsDockerIntegrationTest {
}
Thread.sleep(2000);
}
if (!running) {
logPodDiagnostics(containerId);
}
assertTrue(running, "registry-hosts-pod must reach Running, pulling its image through the configured host");
execInContainerWithExitCode(containerId, new String[]{"kubectl", "delete", "pod", "registry-hosts-pod", "--now"});
}
/** Cleanup removes the k3s container, and kubelet's output reaches nothing else. */
private void logPodDiagnostics(String containerId) {
String[][] commands = {
{"kubectl", "describe", "pod", "registry-hosts-pod"},
{"kubectl", "describe", "nodes"},
{"kubectl", "get", "pods", "-A", "-o", "wide"},
{"crictl", "images"},
{"cat", "/run/flannel/subnet.env"},
// An unassigned pod on a Ready node points at the cloud controller, whose role k3s installs as an addon.
{"kubectl", "get", "crd", "addons.k3s.cattle.io", "-o", "json"},
{"kubectl", "get", "clusterrole/k3s-cloud-controller-manager",
"clusterrolebinding/k3s-cloud-controller-manager", "-o", "json"}
};
for (String[] command : commands) {
try {
ContainerExec.Result result = ContainerExec.run(dockerClient, containerId, command, 10);
LOG.warnv("{0}\n{1}", String.join(" ", command), result.summary());
} catch (RuntimeException e) {
LOG.warnv(e, "Could not run {0}", String.join(" ", command));
}
}
LOG.warnv("k3s log tail\n{0}", k3sLogTail(containerId));
}
private String k3sLogTail(String containerId) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
String problem = "";
try {
boolean completed = dockerClient.logContainerCmd(containerId).withStdOut(true).withStdErr(true)
.withTail(2000)
.exec(new ResultCallback.Adapter<Frame>() {
@Override
public void onNext(Frame frame) {
out.writeBytes(frame.getPayload());
}
}).awaitCompletion(10, TimeUnit.SECONDS);
if (!completed) {
problem = "(timed out reading logs)";
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
problem = "(interrupted while reading logs)";
} catch (Exception e) {
problem = "(could not read logs: " + e.getMessage() + ")";
}
return out.toString(StandardCharsets.UTF_8) + problem;
}
/**
* Pushes a minimal, genuinely pullable image via raw OCI Distribution calls against Floci's
* ECR data plane. The image contains a tiny static executable at {@code /bin/sleep} so kubelet