Repository: kubernetes/kubernetes
File: test/e2e/kubectl/logs.go (Go)

Code before:
				var err error
				deploy, err = deployClient.Create(ctx, deploy, metav1.CreateOptions{})
				if err != nil {
					framework.Failf("Failed to create Deployment: %v", err)
				}

				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)
				}
			})

			ginkgo.AfterEach(func() {
				e2ekubectl.RunKubectlOrDie(ns, "delete", "deploy", deployName)
			})

			ginkgo.It("should get logs from all pods based on default container", func(ctx context.Context) {
				ginkgo.By("Waiting for Deployment pods to be running.")

				// get the pod names
				pods, err := e2edeployment.GetPodsForDeployment(ctx, c, deploy)
				if err != nil {
					framework.Failf("Failed to get pods for Deployment: %v", err)
				}

				podOne := pods.Items[0].GetName()
				podTwo := pods.Items[1].GetName()

				ginkgo.By("expecting logs from both replicas in 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(logFound).To(gomega.BeTrueBecause("log should be present"))
			})

			ginkgo.It("should get logs from each pod and each container in Deployment", func(ctx context.Context) {

Review comment (suggestion):
I suggested 3 seconds in https://github.com/kubernetes/kubernetes/pull/133931#discussion_r2362385631 to align with `run-duration` flag. But 1 seconds should be sufficient.

Code after:
				var err error
				deploy, err = deployClient.Create(ctx, deploy, metav1.CreateOptions{})
				framework.ExpectNoError(err, "failed to create deployment")

				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() {
				e2ekubectl.RunKubectlOrDie(ns, "delete", "deploy", deployName)
			})

			ginkgo.It("should get logs from all pods based on default container", func(ctx context.Context) {
				ginkgo.By("Waiting for Deployment pods to be running.")

				// get the pod names
				pods, err := e2edeployment.GetPodsForDeployment(ctx, c, deploy)
				framework.ExpectNoError(err, "failed to get pods for deployment")

				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"))
				gomega.Expect(strings.Contains(out, fmt.Sprintf("[pod/%s/container-2]", podTwo))).To(gomega.BeTrueBecause("pod 2 container 2 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)
				framework.ExpectNoError(err, "failed to get pods for deployment")

				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")