From 6e6107c9e9bd6387cd68759fa5590b7862eb7f8f Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Thu, 12 Feb 2026 13:32:49 +0100 Subject: [PATCH 1/2] Cleans up the test, removing duplicate checks and making code more readable Signed-off-by: Maciej Szulik --- test/e2e/kubectl/logs.go | 62 +++++++++------------------------------- 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/test/e2e/kubectl/logs.go b/test/e2e/kubectl/logs.go index a7730a03942..52b7b4ab9b5 100644 --- a/test/e2e/kubectl/logs.go +++ b/test/e2e/kubectl/logs.go @@ -274,17 +274,12 @@ var _ = SIGDescribe("Kubectl logs", func() { ginkgo.By("creating the Deployment") var err error deploy, err = deployClient.Create(ctx, deploy, metav1.CreateOptions{}) - if err != nil { - framework.Failf("Failed to create Deployment: %v", err) - } + framework.ExpectNoError(err, "failed to create deployment") - if err = e2edeployment.WaitForDeploymentComplete(c, deploy); err != nil { - framework.Failf("Failed to wait for Deployment to complete: %v", err) - } - - if err = e2epod.WaitForPodsRunningReady(ctx, c, ns, 2, framework.PodStartTimeout); err != nil { - framework.Failf("Failed to wait for Pods are running: %v", err) - } + framework.ExpectNoError(e2edeployment.WaitForDeploymentComplete(c, deploy), + "failed to wait for deployment to complete") + framework.ExpectNoError(e2epod.WaitForPodsRunningReady(ctx, c, ns, 2, framework.PodStartTimeout), + "failed to wait for pods are running") }) ginkgo.AfterEach(func() { @@ -296,65 +291,36 @@ var _ = SIGDescribe("Kubectl logs", func() { // get the pod names pods, err := e2edeployment.GetPodsForDeployment(ctx, c, deploy) - if err != nil { - framework.Failf("Failed to get pods for Deployment: %v", err) - } + framework.ExpectNoError(err, "failed to get pods for deployment") podOne := pods.Items[0].GetName() podTwo := pods.Items[1].GetName() - ginkgo.By("expecting logs from both replicas in Deployment") + ginkgo.By("expecting logs from the default container from both pods in a deployment") out := e2ekubectl.RunKubectlOrDie(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods") - framework.Logf("got output %q", out) - logLines := strings.Split(out, "\n") - logFound := false - for _, line := range logLines { - var deployPod bool - if line != "" { - if strings.Contains(line, fmt.Sprintf("[pod/%s/container-2]", podOne)) || strings.Contains(line, fmt.Sprintf("[pod/%s/container-2]", podTwo)) { - logFound = true - deployPod = true - } - gomega.Expect(deployPod).To(gomega.BeTrueBecause("each log should be from the default container from each pod in the Deployment")) - } + gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podOne))).To(gomega.BeTrueBecause("pod 1 container 2 log should be present")) + gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podTwo))).To(gomega.BeTrueBecause("pod 2 container 2 log should be present")) - } - gomega.Expect(logFound).To(gomega.BeTrueBecause("log should be present")) + ginkgo.By("logs should NOT contain data from the non-default container from both pods in a deployment") + gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-1]", podOne))).To(gomega.BeFalseBecause("pod 1 container 1 log should NOT be present")) + gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-1]", podTwo))).To(gomega.BeFalseBecause("pod 2 container 1 log should NOT be present")) }) ginkgo.It("should get logs from each pod and each container in Deployment", func(ctx context.Context) { ginkgo.By("Waiting for Deployment pods to be running.") pods, err := e2edeployment.GetPodsForDeployment(ctx, c, deploy) - if err != nil { - framework.Failf("Failed to get pods for Deployment: %v", err) - } + framework.ExpectNoError(err, "failed to get pods for deployment") podOne := pods.Items[0].GetName() podTwo := pods.Items[1].GetName() - ginkgo.By("all containers and all containers") + ginkgo.By("expecting logs from all containers from both pods in a deployment") out := e2ekubectl.RunKubectlOrDie(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods", "--all-containers") - framework.Logf("got output %q", out) - logLines := strings.Split(out, "\n") - logFound := false - for _, line := range logLines { - if line != "" { - var deployPodContainer bool - if strings.Contains(line, fmt.Sprintf("[pod/%s/container-1]", podOne)) || strings.Contains(line, fmt.Sprintf("[pod/%s/container-1]", podTwo)) || strings.Contains(line, fmt.Sprintf("[pod/%s/container-2]", podOne)) || strings.Contains(line, fmt.Sprintf("[pod/%s/container-2]", podTwo)) { - logFound = true - deployPodContainer = true - } - gomega.Expect(deployPodContainer).To(gomega.BeTrueBecause("each log should be from all containers from all pods in the Deployment")) - } - } - gomega.Expect(logFound).To(gomega.BeTrueBecause("log should be present")) gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-1]", podOne))).To(gomega.BeTrueBecause("pod 1 container 1 log should be present")) gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podOne))).To(gomega.BeTrueBecause("pod 1 container 2 log should be present")) gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-1]", podTwo))).To(gomega.BeTrueBecause("pod 2 container 1 log should be present")) gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podTwo))).To(gomega.BeTrueBecause("pod 2 container 2 log should be present")) - gomega.Expect(out).NotTo(gomega.BeEmpty()) - }) }) From c2bf995e96d11e164cc2e4898c1a706f60f41e0a Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Thu, 12 Feb 2026 13:36:27 +0100 Subject: [PATCH 2/2] Add 1s timeout after pods get ready, to ensure log generator produces output Signed-off-by: Maciej Szulik --- test/e2e/kubectl/logs.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/e2e/kubectl/logs.go b/test/e2e/kubectl/logs.go index 52b7b4ab9b5..681da4aec46 100644 --- a/test/e2e/kubectl/logs.go +++ b/test/e2e/kubectl/logs.go @@ -296,6 +296,9 @@ var _ = SIGDescribe("Kubectl logs", func() { podOne := pods.Items[0].GetName() podTwo := pods.Items[1].GetName() + ginkgo.By("sleep 1s to wait for log generator produce data after pods get ready") + time.Sleep(time.Second) + ginkgo.By("expecting logs from the default container from both pods in a deployment") out := e2ekubectl.RunKubectlOrDie(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods") gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podOne))).To(gomega.BeTrueBecause("pod 1 container 2 log should be present")) @@ -315,6 +318,9 @@ var _ = SIGDescribe("Kubectl logs", func() { podOne := pods.Items[0].GetName() podTwo := pods.Items[1].GetName() + ginkgo.By("sleep 1s to wait for log generator produce data after pods get ready") + time.Sleep(time.Second) + ginkgo.By("expecting logs from all containers from both pods in a deployment") out := e2ekubectl.RunKubectlOrDie(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods", "--all-containers") gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-1]", podOne))).To(gomega.BeTrueBecause("pod 1 container 1 log should be present"))