diff --git a/test/e2e/apps/statefulset.go b/test/e2e/apps/statefulset.go index 74703ab491c..d14695b6064 100644 --- a/test/e2e/apps/statefulset.go +++ b/test/e2e/apps/statefulset.go @@ -20,12 +20,14 @@ import ( "context" "encoding/json" "fmt" + "reflect" "regexp" "strconv" "strings" "sync" "time" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -1498,7 +1500,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 0") pods := e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-0", "ss-1"}) ginkgo.By("Setting .spec.replicas = 3 .spec.ordinals.start = 2") @@ -1514,7 +1515,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 3 replicas, with start ordinal 2") pods = e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-2", "ss-3", "ss-4"}) }) @@ -1532,7 +1532,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 2") pods := e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-2", "ss-3"}) ginkgo.By("Increasing .spec.ordinals.start = 4") @@ -1548,7 +1547,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 4") pods = e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-4", "ss-5"}) }) @@ -1566,7 +1564,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 3") pods := e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-3", "ss-4"}) ginkgo.By("Decreasing .spec.ordinals.start = 2") @@ -1582,7 +1579,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 2") pods = e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-2", "ss-3"}) }) @@ -1599,7 +1595,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 3") pods := e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-3", "ss-4"}) ginkgo.By("Removing .spec.ordinals") @@ -1612,7 +1607,6 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Confirming 2 replicas, with start ordinal 0") pods = e2estatefulset.GetPodList(ctx, c, ss) - e2estatefulset.SortStatefulPods(pods) expectPodNames(pods, []string{"ss-0", "ss-1"}) }) }) @@ -2177,9 +2171,21 @@ func verifyStatefulSetPVCsExistWithOwnerRefs(ctx context.Context, c clientset.In }) } -func expectPodNames(pods *v1.PodList, expectedPodNames []string) { - framework.ExpectEqual(len(pods.Items), len(expectedPodNames), "unexpected number of pods") - for i, pod := range pods.Items { - framework.ExpectEqual(pod.Name, expectedPodNames[i], "unexpected pod name") +// expectPodNames compares the names of the pods from actualPods with expectedPodNames. +// actualPods can be in any list, since we'll sort by their ordinals and filter +// active ones. expectedPodNames should be ordered by statefulset ordinals. +func expectPodNames(actualPods *v1.PodList, expectedPodNames []string) { + e2estatefulset.SortStatefulPods(actualPods) + pods := []string{} + for _, pod := range actualPods.Items { + // ignore terminating pods, similarly to how the controller does it + // when calculating status information + if e2epod.IsPodActive(&pod) { + pods = append(pods, pod.Name) + } + } + if !reflect.DeepEqual(expectedPodNames, pods) { + diff := cmp.Diff(expectedPodNames, pods) + framework.Failf("Pod names don't match. Diff (- for expected, + for actual):\n%s", diff) } } diff --git a/test/e2e/framework/statefulset/wait.go b/test/e2e/framework/statefulset/wait.go index f05c50dc353..554aa11407b 100644 --- a/test/e2e/framework/statefulset/wait.go +++ b/test/e2e/framework/statefulset/wait.go @@ -98,7 +98,7 @@ func WaitForPodReady(ctx context.Context, c clientset.Interface, set *appsv1.Sta // WaitForStatusReadyReplicas waits for the ss.Status.ReadyReplicas to be equal to expectedReplicas func WaitForStatusReadyReplicas(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet, expectedReplicas int32) { - framework.Logf("Waiting for statefulset status.replicas updated to %d", expectedReplicas) + framework.Logf("Waiting for statefulset status.readyReplicas updated to %d", expectedReplicas) ns, name := ss.Namespace, ss.Name pollErr := wait.PollImmediateWithContext(ctx, StatefulSetPoll, StatefulSetTimeout, @@ -111,13 +111,13 @@ func WaitForStatusReadyReplicas(ctx context.Context, c clientset.Interface, ss * return false, nil } if ssGet.Status.ReadyReplicas != expectedReplicas { - framework.Logf("Waiting for stateful set status.readyReplicas to become %d, currently %d", expectedReplicas, ssGet.Status.ReadyReplicas) + framework.Logf("Waiting for statefulset status.readyReplicas to become %d, currently %d", expectedReplicas, ssGet.Status.ReadyReplicas) return false, nil } return true, nil }) if pollErr != nil { - framework.Failf("Failed waiting for stateful set status.readyReplicas updated to %d: %v", expectedReplicas, pollErr) + framework.Failf("Failed waiting for statefulset status.readyReplicas updated to %d: %v", expectedReplicas, pollErr) } } @@ -136,13 +136,13 @@ func WaitForStatusAvailableReplicas(ctx context.Context, c clientset.Interface, return false, nil } if ssGet.Status.AvailableReplicas != expectedReplicas { - framework.Logf("Waiting for stateful set status.AvailableReplicas to become %d, currently %d", expectedReplicas, ssGet.Status.AvailableReplicas) + framework.Logf("Waiting for statefulset status.AvailableReplicas to become %d, currently %d", expectedReplicas, ssGet.Status.AvailableReplicas) return false, nil } return true, nil }) if pollErr != nil { - framework.Failf("Failed waiting for stateful set status.AvailableReplicas updated to %d: %v", expectedReplicas, pollErr) + framework.Failf("Failed waiting for statefulset status.AvailableReplicas updated to %d: %v", expectedReplicas, pollErr) } } @@ -161,13 +161,13 @@ func WaitForStatusReplicas(ctx context.Context, c clientset.Interface, ss *appsv return false, nil } if ssGet.Status.Replicas != expectedReplicas { - framework.Logf("Waiting for stateful set status.replicas to become %d, currently %d", expectedReplicas, ssGet.Status.Replicas) + framework.Logf("Waiting for statefulset status.replicas to become %d, currently %d", expectedReplicas, ssGet.Status.Replicas) return false, nil } return true, nil }) if pollErr != nil { - framework.Failf("Failed waiting for stateful set status.replicas updated to %d: %v", expectedReplicas, pollErr) + framework.Failf("Failed waiting for statefulset status.replicas updated to %d: %v", expectedReplicas, pollErr) } }