mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Merge pull request #136981 from soltysh/simplify_logs_e2e
Add slight timeout after pods are running, and drop duplicate log lines checks
This commit is contained in:
@@ -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,42 @@ 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")
|
||||
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"))
|
||||
}
|
||||
ginkgo.By("sleep 1s to wait for log generator produce data after pods get ready")
|
||||
time.Sleep(time.Second)
|
||||
|
||||
}
|
||||
gomega.Expect(logFound).To(gomega.BeTrueBecause("log should be present"))
|
||||
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)
|
||||
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("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")
|
||||
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())
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user