diff --git a/test/e2e/apps/statefulset.go b/test/e2e/apps/statefulset.go index deca68333df..d024688c558 100644 --- a/test/e2e/apps/statefulset.go +++ b/test/e2e/apps/statefulset.go @@ -206,7 +206,9 @@ var _ = SIGDescribe("StatefulSet", func() { ginkgo.By("Saturating stateful set " + ss.Name) e2estatefulset.Saturate(ctx, c, ss) - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + gomega.Expect(pods.Items).To(gomega.HaveLen(int(*ss.Spec.Replicas))) ginkgo.By("Checking that stateful set pods are created with ControllerRef") @@ -354,7 +356,9 @@ var _ = SIGDescribe("StatefulSet", func() { currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s", ss.Namespace, ss.Name, updateRevision, currentRevision) - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to currentRevision %s", pods.Items[i].Namespace, @@ -443,7 +447,9 @@ var _ = SIGDescribe("StatefulSet", func() { deleteStatefulPodAtIndex(ctx, c, 2, ss) e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss) ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name) - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) { gomega.Expect(pods.Items[i].Spec.Containers[0].Image).To(gomega.Equal(oldImage), "Pod %s/%s has image %s not equal to current image %s", @@ -580,7 +586,9 @@ var _ = SIGDescribe("StatefulSet", func() { currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s", ss.Namespace, ss.Name, updateRevision, currentRevision) - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s", pods.Items[i].Namespace, @@ -595,7 +603,9 @@ var _ = SIGDescribe("StatefulSet", func() { deleteStatefulPodAtIndex(ctx, c, 2, ss) e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss) ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name) - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s", pods.Items[i].Namespace, @@ -624,7 +634,9 @@ var _ = SIGDescribe("StatefulSet", func() { deleteStatefulPodAtIndex(ctx, c, 2, ss) e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss) ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name) - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Spec.Containers[0].Image).To(gomega.Equal(newImage), "Pod %s/%s has image %s not equal to new image %s", pods.Items[i].Namespace, @@ -1816,7 +1828,9 @@ var _ = SIGDescribe("StatefulSet", func() { e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2) ginkgo.By("Confirming 2 replicas, with start ordinal 0") - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + err = expectPodNames(pods, []string{"ss-0", "ss-1"}) framework.ExpectNoError(err) @@ -1851,7 +1865,9 @@ var _ = SIGDescribe("StatefulSet", func() { e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2) ginkgo.By("Confirming 2 replicas, with start ordinal 2") - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + err = expectPodNames(pods, []string{"ss-2", "ss-3"}) framework.ExpectNoError(err) @@ -1885,7 +1901,9 @@ var _ = SIGDescribe("StatefulSet", func() { e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2) ginkgo.By("Confirming 2 replicas, with start ordinal 3") - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + err = expectPodNames(pods, []string{"ss-3", "ss-4"}) framework.ExpectNoError(err) @@ -1918,7 +1936,9 @@ var _ = SIGDescribe("StatefulSet", func() { e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2) ginkgo.By("Confirming 2 replicas, with start ordinal 3") - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + err = expectPodNames(pods, []string{"ss-3", "ss-4"}) framework.ExpectNoError(err) @@ -2170,7 +2190,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s", ss.Namespace, ss.Name, updateRevision, currentRevision) - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s", pods.Items[i].Namespace, @@ -2198,7 +2220,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app gomega.Expect(currentRevision).NotTo(gomega.Equal(updateRevision), "Current revision should not equal update revision during rolling update") ginkgo.By("Updating Pods in reverse ordinal order") - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + e2estatefulset.SortStatefulPods(pods) err = restorePodHTTPProbe(ss, &pods.Items[1]) framework.ExpectNoError(err) @@ -2237,7 +2261,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app gomega.Expect(currentRevision).NotTo(gomega.Equal(updateRevision), "Current revision should not equal update revision during roll back") ginkgo.By("Rolling back update in reverse ordinal order") - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + e2estatefulset.SortStatefulPods(pods) restorePodHTTPProbe(ss, &pods.Items[1]) ss, _ = e2estatefulset.WaitForPodReady(ctx, c, ss, pods.Items[1].Name) @@ -2280,7 +2306,9 @@ func deletingPodForRollingUpdatePartitionTest(ctx context.Context, f *framework. currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), fmt.Sprintf("StatefulSet %s/%s created with update revision %s not equal to current revision %s", ss.Namespace, ss.Name, updateRevision, currentRevision)) - pods := e2estatefulset.GetPodList(ctx, c, ss) + pods, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { gomega.Expect(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel]).To(gomega.Equal(currentRevision), fmt.Sprintf("Pod %s/%s revision %s is not equal to currentRevision %s", pods.Items[i].Namespace, @@ -2372,7 +2400,9 @@ func deletingPodForRollingUpdatePartitionTest(ctx context.Context, f *framework. }) ginkgo.By("Verify pod images after pod-0 deletion and recreation") - pods = e2estatefulset.GetPodList(ctx, c, ss) + pods, err = e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + for i := range pods.Items { if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) { gomega.Expect(pods.Items[i].Spec.Containers[0].Image).To(gomega.Equal(oldImage), fmt.Sprintf("Pod %s/%s has image %s not equal to current image %s", @@ -2406,7 +2436,9 @@ func confirmStatefulPodCount(ctx context.Context, c clientset.Interface, count i start := time.Now() deadline := start.Add(timeout) for t := time.Now(); t.Before(deadline) && ctx.Err() == nil; t = time.Now() { - podList := e2estatefulset.GetPodList(ctx, c, ss) + podList, err := e2estatefulset.GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + statefulPodCount := len(podList.Items) if statefulPodCount != count { e2epod.LogPodStates(podList.Items) diff --git a/test/e2e/framework/statefulset/fixtures.go b/test/e2e/framework/statefulset/fixtures.go index bde1693df60..b7e9d5f6967 100644 --- a/test/e2e/framework/statefulset/fixtures.go +++ b/test/e2e/framework/statefulset/fixtures.go @@ -156,7 +156,9 @@ func PauseNewPods(ss *appsv1.StatefulSet) { // or if it finds more than one paused Pod existing at the same time. // This is a no-op if there are no paused pods. func ResumeNextPod(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) { - podList := GetPodList(ctx, c, ss) + podList, err := GetPodList(ctx, c, ss) + framework.ExpectNoError(err) + resumedPod := "" for _, pod := range podList.Items { if pod.Status.Phase != v1.PodRunning { diff --git a/test/e2e/framework/statefulset/rest.go b/test/e2e/framework/statefulset/rest.go index 8cdc5d1e3f1..db77cbcbb48 100644 --- a/test/e2e/framework/statefulset/rest.go +++ b/test/e2e/framework/statefulset/rest.go @@ -64,12 +64,13 @@ func CreateStatefulSet(ctx context.Context, c clientset.Interface, manifestPath, } // GetPodList gets the current Pods in ss. -func GetPodList(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) *v1.PodList { +func GetPodList(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) (*v1.PodList, error) { selector, err := metav1.LabelSelectorAsSelector(ss.Spec.Selector) - framework.ExpectNoError(err) - podList, err := c.CoreV1().Pods(ss.Namespace).List(ctx, metav1.ListOptions{LabelSelector: selector.String()}) - framework.ExpectNoError(err) - return podList + if err != nil { + return nil, err + } + + return c.CoreV1().Pods(ss.Namespace).List(ctx, metav1.ListOptions{LabelSelector: selector.String()}) } // DeleteAllStatefulSets deletes all StatefulSet API Objects in Namespace ns. @@ -154,7 +155,11 @@ func Scale(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet, c var statefulPodList *v1.PodList pollErr := wait.PollUntilContextTimeout(ctx, StatefulSetPoll, StatefulSetTimeout, true, func(ctx context.Context) (bool, error) { - statefulPodList = GetPodList(ctx, c, ss) + statefulPodList, err := GetPodList(ctx, c, ss) + if err != nil { + return false, err + } + if int32(len(statefulPodList.Items)) == count { return true, nil } @@ -193,7 +198,11 @@ func Restart(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) // CheckHostname verifies that all Pods in ss have the correct Hostname. If the returned error is not nil than verification failed. func CheckHostname(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) error { cmd := "printf $(hostname)" - podList := GetPodList(ctx, c, ss) + podList, err := GetPodList(ctx, c, ss) + if err != nil { + return err + } + for _, statefulPod := range podList.Items { hostname, err := e2epodoutput.RunHostCmdWithRetries(statefulPod.Namespace, statefulPod.Name, cmd, StatefulSetPoll, StatefulPodTimeout) if err != nil { @@ -237,7 +246,11 @@ func CheckServiceName(ss *appsv1.StatefulSet, expectedServiceName string) error // CheckPodIndexLabel asserts that the pods for ss have expected index label and values. func CheckPodIndexLabel(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) error { - pods := GetPodList(ctx, c, ss) + pods, err := GetPodList(ctx, c, ss) + if err != nil { + return err + } + labelIndices := sets.NewInt() for _, pod := range pods.Items { ix, err := strconv.Atoi(pod.Labels[appsv1.PodIndexLabel]) @@ -257,7 +270,11 @@ func CheckPodIndexLabel(ctx context.Context, c clientset.Interface, ss *appsv1.S // ExecInStatefulPods executes cmd in all Pods in ss. If a error occurs it is returned and cmd is not execute in any subsequent Pods. func ExecInStatefulPods(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet, cmd string) error { - podList := GetPodList(ctx, c, ss) + podList, err := GetPodList(ctx, c, ss) + if err != nil { + return err + } + for _, statefulPod := range podList.Items { stdout, err := e2epodoutput.RunHostCmdWithRetries(statefulPod.Namespace, statefulPod.Name, cmd, StatefulSetPoll, StatefulPodTimeout) framework.Logf("stdout of %v on %v: %v", cmd, statefulPod.Name, stdout) diff --git a/test/e2e/framework/statefulset/wait.go b/test/e2e/framework/statefulset/wait.go index 8eae83998ad..5615b58ffa0 100644 --- a/test/e2e/framework/statefulset/wait.go +++ b/test/e2e/framework/statefulset/wait.go @@ -34,7 +34,11 @@ import ( func WaitForRunning(ctx context.Context, c clientset.Interface, numPodsRunning, numPodsReady int32, ss *appsv1.StatefulSet) { pollErr := wait.PollUntilContextTimeout(ctx, StatefulSetPoll, StatefulSetTimeout, true, func(ctx context.Context) (bool, error) { - podList := GetPodList(ctx, c, ss) + podList, err := GetPodList(ctx, c, ss) + if err != nil { + return false, err + } + SortStatefulPods(podList) if int32(len(podList.Items)) < numPodsRunning { framework.Logf("Found %d stateful pods, waiting for %d", len(podList.Items), numPodsRunning) @@ -67,7 +71,11 @@ func WaitForState(ctx context.Context, c clientset.Interface, ss *appsv1.Statefu if err != nil { return false, err } - podList := GetPodList(ctx, c, ssGet) + podList, err := GetPodList(ctx, c, ssGet) + if err != nil { + return false, err + } + return until(ssGet, podList) }) if pollErr != nil { diff --git a/test/e2e/storage/persistent_volumes-local.go b/test/e2e/storage/persistent_volumes-local.go index 69cd4799cd8..d2c4275dd49 100644 --- a/test/e2e/storage/persistent_volumes-local.go +++ b/test/e2e/storage/persistent_volumes-local.go @@ -1157,7 +1157,8 @@ func createStatefulSet(ctx context.Context, config *localTestConfig, ssReplicas } func validateStatefulSet(ctx context.Context, config *localTestConfig, ss *appsv1.StatefulSet, anti bool) { - pods := e2estatefulset.GetPodList(ctx, config.client, ss) + pods, err := e2estatefulset.GetPodList(ctx, config.client, ss) + framework.ExpectNoError(err) nodes := sets.NewString() for _, pod := range pods.Items {