Skip to content

Commit 9ae0b45

Browse files
committed
wait for status eventually consistent
Signed-off-by: Abner-1 <yuanyuxing.yyx@alibaba-inc.com>
1 parent e149b48 commit 9ae0b45

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

test/e2e/apps/inplace_vpa.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,23 @@ var _ = SIGDescribe("InplaceVPA", func() {
429429
return cs.Status.UpdatedAvailableReplicas
430430
}, 600*time.Second, 3*time.Second).Should(gomega.Equal(int32(1)))
431431

432+
// add this to avoid the situation where the pod status keeps changing
433+
// TODO: Remove this for status change optimization, maybe in Kubernetes 1.33.
434+
ginkgo.By("Wait for the pod status to be consistent")
435+
gomega.Eventually(func() string {
436+
pods, err = tester.ListPodsForCloneSet(cs.Name)
437+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
438+
a1, b1, c1 := getResourcesInfo(pods[0])
439+
if a1 != a || b1 != b || c1 != c {
440+
framework.Logf("updateSpec %v", a1)
441+
framework.Logf("spec %v", b1)
442+
framework.Logf("container status %v ", c1)
443+
a, b, c = a1, b1, c1
444+
}
445+
SkipTestWhenCgroupError(pods[0])
446+
return pods[0].Status.ContainerStatuses[0].ContainerID
447+
}, 120*time.Second, 3*time.Second).Should(gomega.Not(gomega.Equal(oldContainerStatus.ContainerID)))
448+
432449
ginkgo.By("Verify the containerID changed and restartCount should not be 0")
433450
pods, err = tester.ListPodsForCloneSet(cs.Name)
434451
gomega.Expect(err).NotTo(gomega.HaveOccurred())
@@ -588,6 +605,23 @@ var _ = SIGDescribe("InplaceVPA", func() {
588605
return cs.Status.UpdatedAvailableReplicas
589606
}, 600*time.Second, 3*time.Second).Should(gomega.Equal(int32(1)))
590607

608+
// add this to avoid the situation where the pod status keeps changing
609+
// TODO: Remove this for status change optimization, maybe in Kubernetes 1.33.
610+
ginkgo.By("Wait for the pod status to be consistent")
611+
gomega.Eventually(func() string {
612+
pods, err = tester.ListPodsForCloneSet(cs.Name)
613+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
614+
a1, b1, c1 := getResourcesInfo(pods[0])
615+
if a1 != a || b1 != b || c1 != c {
616+
framework.Logf("updateSpec %v", a1)
617+
framework.Logf("spec %v", b1)
618+
framework.Logf("container status %v ", c1)
619+
a, b, c = a1, b1, c1
620+
}
621+
SkipTestWhenCgroupError(pods[0])
622+
return pods[0].Status.ContainerStatuses[0].ContainerID
623+
}, 120*time.Second, 3*time.Second).Should(gomega.Not(gomega.Equal(oldContainerStatus.ContainerID)))
624+
591625
ginkgo.By("Verify the containerID changed and restartCount should be 1")
592626
pods, err = tester.ListPodsForCloneSet(cs.Name)
593627
gomega.Expect(err).NotTo(gomega.HaveOccurred())
@@ -899,7 +933,14 @@ var _ = SIGDescribe("InplaceVPA", func() {
899933
gomega.Expect(redisContainerStatus.RestartCount).Should(gomega.Equal(int32(1)))
900934

901935
ginkgo.By("Verify nginx should be stopped after new redis has started")
902-
gomega.Expect(nginxContainerStatus.LastTerminationState.Terminated.FinishedAt.After(redisContainerStatus.State.Running.StartedAt.Time.Add(time.Second*10))).
936+
var t time.Time
937+
if nginxContainerStatus.LastTerminationState.Terminated != nil {
938+
t = nginxContainerStatus.LastTerminationState.Terminated.FinishedAt.Time
939+
} else {
940+
// fix https://github.com/openkruise/kruise/issues/1925
941+
t = nginxContainerStatus.State.Running.StartedAt.Time
942+
}
943+
gomega.Expect(t.After(redisContainerStatus.State.Running.StartedAt.Time.Add(time.Second*10))).
903944
Should(gomega.Equal(true), fmt.Sprintf("nginx finish at %v is not after redis start %v + 10s",
904945
nginxContainerStatus.LastTerminationState.Terminated.FinishedAt,
905946
redisContainerStatus.State.Running.StartedAt))

0 commit comments

Comments
 (0)