From a4fc58cc9872a5a1b7d0be6c992d81198b95469e Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 19 Nov 2018 14:55:10 +0100 Subject: [PATCH] e2e/framework: capture logs only from pods that actually started Attempting to retrieve logs for a container that hasn't started yet may have been the reason for the "the server does not allow this method on the requested resource" error that showed up on the GCE CI test cluster (issue #70888). If we wait with retrieving logs until the pod is running or has terminated, then we might be able to avoid that error. It's the right thing to do either way and not complicated to implement. --- test/e2e/framework/podlogs/podlogs.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/podlogs/podlogs.go b/test/e2e/framework/podlogs/podlogs.go index 77fae293af0..cf24571d963 100644 --- a/test/e2e/framework/podlogs/podlogs.go +++ b/test/e2e/framework/podlogs/podlogs.go @@ -99,9 +99,15 @@ func CopyAllLogs(ctx context.Context, cs clientset.Interface, ns string, to LogO } for _, pod := range pods.Items { - for _, c := range pod.Spec.Containers { + for i, c := range pod.Spec.Containers { name := pod.ObjectMeta.Name + "/" + c.Name - if logging[name] { + if logging[name] || + // sanity check, array should have entry for each container + len(pod.Status.ContainerStatuses) <= i || + // Don't attempt to get logs for a container unless it is running or has terminated. + // Trying to get a log would just end up with an error that we would have to suppress. + (pod.Status.ContainerStatuses[i].State.Running == nil && + pod.Status.ContainerStatuses[i].State.Terminated == nil) { continue } readCloser, err := LogsForPod(ctx, cs, ns, pod.ObjectMeta.Name,