Skip to content

Commit fa03b93

Browse files
authored
Merge pull request kubernetes#130326 from elizabeth-dev/statefulset-framework-return-errors
test(statefulset): return errors in framework function GetPodList for upstream handling
2 parents de7708f + a49b336 commit fa03b93

File tree

5 files changed

+89
-29
lines changed

5 files changed

+89
-29
lines changed

test/e2e/apps/statefulset.go

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ var _ = SIGDescribe("StatefulSet", func() {
206206

207207
ginkgo.By("Saturating stateful set " + ss.Name)
208208
e2estatefulset.Saturate(ctx, c, ss)
209-
pods := e2estatefulset.GetPodList(ctx, c, ss)
209+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
210+
framework.ExpectNoError(err)
211+
210212
gomega.Expect(pods.Items).To(gomega.HaveLen(int(*ss.Spec.Replicas)))
211213

212214
ginkgo.By("Checking that stateful set pods are created with ControllerRef")
@@ -354,7 +356,9 @@ var _ = SIGDescribe("StatefulSet", func() {
354356
currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
355357
gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s",
356358
ss.Namespace, ss.Name, updateRevision, currentRevision)
357-
pods := e2estatefulset.GetPodList(ctx, c, ss)
359+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
360+
framework.ExpectNoError(err)
361+
358362
for i := range pods.Items {
359363
gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to currentRevision %s",
360364
pods.Items[i].Namespace,
@@ -443,7 +447,9 @@ var _ = SIGDescribe("StatefulSet", func() {
443447
deleteStatefulPodAtIndex(ctx, c, 2, ss)
444448
e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss)
445449
ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name)
446-
pods = e2estatefulset.GetPodList(ctx, c, ss)
450+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
451+
framework.ExpectNoError(err)
452+
447453
for i := range pods.Items {
448454
if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) {
449455
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() {
580586
currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
581587
gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s",
582588
ss.Namespace, ss.Name, updateRevision, currentRevision)
583-
pods := e2estatefulset.GetPodList(ctx, c, ss)
589+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
590+
framework.ExpectNoError(err)
591+
584592
for i := range pods.Items {
585593
gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s",
586594
pods.Items[i].Namespace,
@@ -595,7 +603,9 @@ var _ = SIGDescribe("StatefulSet", func() {
595603
deleteStatefulPodAtIndex(ctx, c, 2, ss)
596604
e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss)
597605
ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name)
598-
pods = e2estatefulset.GetPodList(ctx, c, ss)
606+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
607+
framework.ExpectNoError(err)
608+
599609
for i := range pods.Items {
600610
gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s",
601611
pods.Items[i].Namespace,
@@ -624,7 +634,9 @@ var _ = SIGDescribe("StatefulSet", func() {
624634
deleteStatefulPodAtIndex(ctx, c, 2, ss)
625635
e2estatefulset.WaitForRunningAndReady(ctx, c, 3, ss)
626636
ss = getStatefulSet(ctx, c, ss.Namespace, ss.Name)
627-
pods = e2estatefulset.GetPodList(ctx, c, ss)
637+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
638+
framework.ExpectNoError(err)
639+
628640
for i := range pods.Items {
629641
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",
630642
pods.Items[i].Namespace,
@@ -1816,7 +1828,9 @@ var _ = SIGDescribe("StatefulSet", func() {
18161828
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2)
18171829

18181830
ginkgo.By("Confirming 2 replicas, with start ordinal 0")
1819-
pods := e2estatefulset.GetPodList(ctx, c, ss)
1831+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
1832+
framework.ExpectNoError(err)
1833+
18201834
err = expectPodNames(pods, []string{"ss-0", "ss-1"})
18211835
framework.ExpectNoError(err)
18221836

@@ -1851,7 +1865,9 @@ var _ = SIGDescribe("StatefulSet", func() {
18511865
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2)
18521866

18531867
ginkgo.By("Confirming 2 replicas, with start ordinal 2")
1854-
pods := e2estatefulset.GetPodList(ctx, c, ss)
1868+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
1869+
framework.ExpectNoError(err)
1870+
18551871
err = expectPodNames(pods, []string{"ss-2", "ss-3"})
18561872
framework.ExpectNoError(err)
18571873

@@ -1885,7 +1901,9 @@ var _ = SIGDescribe("StatefulSet", func() {
18851901
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2)
18861902

18871903
ginkgo.By("Confirming 2 replicas, with start ordinal 3")
1888-
pods := e2estatefulset.GetPodList(ctx, c, ss)
1904+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
1905+
framework.ExpectNoError(err)
1906+
18891907
err = expectPodNames(pods, []string{"ss-3", "ss-4"})
18901908
framework.ExpectNoError(err)
18911909

@@ -1918,7 +1936,9 @@ var _ = SIGDescribe("StatefulSet", func() {
19181936
e2estatefulset.WaitForStatusReadyReplicas(ctx, c, ss, 2)
19191937

19201938
ginkgo.By("Confirming 2 replicas, with start ordinal 3")
1921-
pods := e2estatefulset.GetPodList(ctx, c, ss)
1939+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
1940+
framework.ExpectNoError(err)
1941+
19221942
err = expectPodNames(pods, []string{"ss-3", "ss-4"})
19231943
framework.ExpectNoError(err)
19241944

@@ -2170,7 +2190,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app
21702190
currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
21712191
gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), "StatefulSet %s/%s created with update revision %s not equal to current revision %s",
21722192
ss.Namespace, ss.Name, updateRevision, currentRevision)
2173-
pods := e2estatefulset.GetPodList(ctx, c, ss)
2193+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
2194+
framework.ExpectNoError(err)
2195+
21742196
for i := range pods.Items {
21752197
gomega.Expect(pods.Items[i].Labels).To(gomega.HaveKeyWithValue(appsv1.StatefulSetRevisionLabel, currentRevision), "Pod %s/%s revision %s is not equal to current revision %s",
21762198
pods.Items[i].Namespace,
@@ -2198,7 +2220,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app
21982220
gomega.Expect(currentRevision).NotTo(gomega.Equal(updateRevision), "Current revision should not equal update revision during rolling update")
21992221

22002222
ginkgo.By("Updating Pods in reverse ordinal order")
2201-
pods = e2estatefulset.GetPodList(ctx, c, ss)
2223+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
2224+
framework.ExpectNoError(err)
2225+
22022226
e2estatefulset.SortStatefulPods(pods)
22032227
err = restorePodHTTPProbe(ss, &pods.Items[1])
22042228
framework.ExpectNoError(err)
@@ -2237,7 +2261,9 @@ func rollbackTest(ctx context.Context, c clientset.Interface, ns string, ss *app
22372261
gomega.Expect(currentRevision).NotTo(gomega.Equal(updateRevision), "Current revision should not equal update revision during roll back")
22382262

22392263
ginkgo.By("Rolling back update in reverse ordinal order")
2240-
pods = e2estatefulset.GetPodList(ctx, c, ss)
2264+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
2265+
framework.ExpectNoError(err)
2266+
22412267
e2estatefulset.SortStatefulPods(pods)
22422268
restorePodHTTPProbe(ss, &pods.Items[1])
22432269
ss, _ = e2estatefulset.WaitForPodReady(ctx, c, ss, pods.Items[1].Name)
@@ -2280,7 +2306,9 @@ func deletingPodForRollingUpdatePartitionTest(ctx context.Context, f *framework.
22802306
currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
22812307
gomega.Expect(currentRevision).To(gomega.Equal(updateRevision), fmt.Sprintf("StatefulSet %s/%s created with update revision %s not equal to current revision %s",
22822308
ss.Namespace, ss.Name, updateRevision, currentRevision))
2283-
pods := e2estatefulset.GetPodList(ctx, c, ss)
2309+
pods, err := e2estatefulset.GetPodList(ctx, c, ss)
2310+
framework.ExpectNoError(err)
2311+
22842312
for i := range pods.Items {
22852313
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",
22862314
pods.Items[i].Namespace,
@@ -2372,7 +2400,9 @@ func deletingPodForRollingUpdatePartitionTest(ctx context.Context, f *framework.
23722400
})
23732401

23742402
ginkgo.By("Verify pod images after pod-0 deletion and recreation")
2375-
pods = e2estatefulset.GetPodList(ctx, c, ss)
2403+
pods, err = e2estatefulset.GetPodList(ctx, c, ss)
2404+
framework.ExpectNoError(err)
2405+
23762406
for i := range pods.Items {
23772407
if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) {
23782408
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
24062436
start := time.Now()
24072437
deadline := start.Add(timeout)
24082438
for t := time.Now(); t.Before(deadline) && ctx.Err() == nil; t = time.Now() {
2409-
podList := e2estatefulset.GetPodList(ctx, c, ss)
2439+
podList, err := e2estatefulset.GetPodList(ctx, c, ss)
2440+
framework.ExpectNoError(err)
2441+
24102442
statefulPodCount := len(podList.Items)
24112443
if statefulPodCount != count {
24122444
e2epod.LogPodStates(podList.Items)

test/e2e/framework/statefulset/fixtures.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ func PauseNewPods(ss *appsv1.StatefulSet) {
156156
// or if it finds more than one paused Pod existing at the same time.
157157
// This is a no-op if there are no paused pods.
158158
func ResumeNextPod(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) {
159-
podList := GetPodList(ctx, c, ss)
159+
podList, err := GetPodList(ctx, c, ss)
160+
framework.ExpectNoError(err)
161+
160162
resumedPod := ""
161163
for _, pod := range podList.Items {
162164
if pod.Status.Phase != v1.PodRunning {

test/e2e/framework/statefulset/rest.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ func CreateStatefulSet(ctx context.Context, c clientset.Interface, manifestPath,
6464
}
6565

6666
// GetPodList gets the current Pods in ss.
67-
func GetPodList(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) *v1.PodList {
67+
func GetPodList(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) (*v1.PodList, error) {
6868
selector, err := metav1.LabelSelectorAsSelector(ss.Spec.Selector)
69-
framework.ExpectNoError(err)
70-
podList, err := c.CoreV1().Pods(ss.Namespace).List(ctx, metav1.ListOptions{LabelSelector: selector.String()})
71-
framework.ExpectNoError(err)
72-
return podList
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
return c.CoreV1().Pods(ss.Namespace).List(ctx, metav1.ListOptions{LabelSelector: selector.String()})
7374
}
7475

7576
// 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
154155

155156
var statefulPodList *v1.PodList
156157
pollErr := wait.PollUntilContextTimeout(ctx, StatefulSetPoll, StatefulSetTimeout, true, func(ctx context.Context) (bool, error) {
157-
statefulPodList = GetPodList(ctx, c, ss)
158+
statefulPodList, err := GetPodList(ctx, c, ss)
159+
if err != nil {
160+
return false, err
161+
}
162+
158163
if int32(len(statefulPodList.Items)) == count {
159164
return true, nil
160165
}
@@ -193,7 +198,11 @@ func Restart(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet)
193198
// CheckHostname verifies that all Pods in ss have the correct Hostname. If the returned error is not nil than verification failed.
194199
func CheckHostname(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) error {
195200
cmd := "printf $(hostname)"
196-
podList := GetPodList(ctx, c, ss)
201+
podList, err := GetPodList(ctx, c, ss)
202+
if err != nil {
203+
return err
204+
}
205+
197206
for _, statefulPod := range podList.Items {
198207
hostname, err := e2epodoutput.RunHostCmdWithRetries(statefulPod.Namespace, statefulPod.Name, cmd, StatefulSetPoll, StatefulPodTimeout)
199208
if err != nil {
@@ -237,7 +246,11 @@ func CheckServiceName(ss *appsv1.StatefulSet, expectedServiceName string) error
237246

238247
// CheckPodIndexLabel asserts that the pods for ss have expected index label and values.
239248
func CheckPodIndexLabel(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet) error {
240-
pods := GetPodList(ctx, c, ss)
249+
pods, err := GetPodList(ctx, c, ss)
250+
if err != nil {
251+
return err
252+
}
253+
241254
labelIndices := sets.NewInt()
242255
for _, pod := range pods.Items {
243256
ix, err := strconv.Atoi(pod.Labels[appsv1.PodIndexLabel])
@@ -257,7 +270,11 @@ func CheckPodIndexLabel(ctx context.Context, c clientset.Interface, ss *appsv1.S
257270

258271
// ExecInStatefulPods executes cmd in all Pods in ss. If a error occurs it is returned and cmd is not execute in any subsequent Pods.
259272
func ExecInStatefulPods(ctx context.Context, c clientset.Interface, ss *appsv1.StatefulSet, cmd string) error {
260-
podList := GetPodList(ctx, c, ss)
273+
podList, err := GetPodList(ctx, c, ss)
274+
if err != nil {
275+
return err
276+
}
277+
261278
for _, statefulPod := range podList.Items {
262279
stdout, err := e2epodoutput.RunHostCmdWithRetries(statefulPod.Namespace, statefulPod.Name, cmd, StatefulSetPoll, StatefulPodTimeout)
263280
framework.Logf("stdout of %v on %v: %v", cmd, statefulPod.Name, stdout)

test/e2e/framework/statefulset/wait.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ import (
3434
func WaitForRunning(ctx context.Context, c clientset.Interface, numPodsRunning, numPodsReady int32, ss *appsv1.StatefulSet) {
3535
pollErr := wait.PollUntilContextTimeout(ctx, StatefulSetPoll, StatefulSetTimeout, true,
3636
func(ctx context.Context) (bool, error) {
37-
podList := GetPodList(ctx, c, ss)
37+
podList, err := GetPodList(ctx, c, ss)
38+
if err != nil {
39+
return false, err
40+
}
41+
3842
SortStatefulPods(podList)
3943
if int32(len(podList.Items)) < numPodsRunning {
4044
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
6771
if err != nil {
6872
return false, err
6973
}
70-
podList := GetPodList(ctx, c, ssGet)
74+
podList, err := GetPodList(ctx, c, ssGet)
75+
if err != nil {
76+
return false, err
77+
}
78+
7179
return until(ssGet, podList)
7280
})
7381
if pollErr != nil {

test/e2e/storage/persistent_volumes-local.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,8 @@ func createStatefulSet(ctx context.Context, config *localTestConfig, ssReplicas
11571157
}
11581158

11591159
func validateStatefulSet(ctx context.Context, config *localTestConfig, ss *appsv1.StatefulSet, anti bool) {
1160-
pods := e2estatefulset.GetPodList(ctx, config.client, ss)
1160+
pods, err := e2estatefulset.GetPodList(ctx, config.client, ss)
1161+
framework.ExpectNoError(err)
11611162

11621163
nodes := sets.NewString()
11631164
for _, pod := range pods.Items {

0 commit comments

Comments
 (0)