mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 13:57:38 +00:00
fix flaky logs test by retrying logs fetch
Signed-off-by: bishal7679 <bishalhnj127@gmail.com>
This commit is contained in:
@@ -75,13 +75,13 @@ func testingDeployment(name, ns string, numberOfPods int32) appsv1.Deployment {
|
||||
Name: "container-1",
|
||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{"/agnhost logs-generator --log-lines-total 10 --run-duration 3s && /agnhost pause"},
|
||||
Args: []string{"/agnhost logs-generator --log-lines-total 10 --run-duration 30s && /agnhost pause"},
|
||||
},
|
||||
{
|
||||
Name: "container-2",
|
||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{"/agnhost logs-generator --log-lines-total 20 --run-duration 3s && /agnhost pause"},
|
||||
Args: []string{"/agnhost logs-generator --log-lines-total 20 --run-duration 30s && /agnhost pause"},
|
||||
},
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
@@ -289,20 +289,24 @@ var _ = SIGDescribe("Kubectl logs", func() {
|
||||
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 3s to wait for log generator produce data after pods get ready")
|
||||
time.Sleep(3 * 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"))
|
||||
var out string
|
||||
gomega.Eventually(func() (string, error) {
|
||||
var runErr error
|
||||
out, runErr = e2ekubectl.RunKubectl(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods")
|
||||
return out, runErr
|
||||
}, framework.PodStartTimeout, 5*time.Second).Should(
|
||||
gomega.SatisfyAll(
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-2]", podOne)),
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-2]", podTwo)),
|
||||
),
|
||||
)
|
||||
|
||||
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"))
|
||||
@@ -318,15 +322,17 @@ var _ = SIGDescribe("Kubectl logs", func() {
|
||||
podOne := pods.Items[0].GetName()
|
||||
podTwo := pods.Items[1].GetName()
|
||||
|
||||
ginkgo.By("sleep 3s to wait for log generator produce data after pods get ready")
|
||||
time.Sleep(3 * 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"))
|
||||
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.Eventually(func() (string, error) {
|
||||
return e2ekubectl.RunKubectl(ns, "logs", fmt.Sprintf("deploy/%s", deployName), "--all-pods", "--all-containers")
|
||||
}, framework.PodStartTimeout, 5*time.Second).Should(
|
||||
gomega.SatisfyAll(
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-1]", podOne)),
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-2]", podOne)),
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-1]", podTwo)),
|
||||
gomega.ContainSubstring(fmt.Sprintf("[pod/%s/container-2]", podTwo)),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user