Skip to content

Commit a5a23d2

Browse files
author
Kenichi Omichi
committed
Move ConfirmStatefulPodCount to e2e test
ConfirmStatefulPodCount() was used at e2e statefulset test only, and that added dependency on another sub framework to statefulset sub framework. This moves ConfirmStatefulPodCount() to the e2e test for clean dependency.
1 parent 32dc42e commit a5a23d2

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

test/e2e/apps/statefulset.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ var _ = SIGDescribe("StatefulSet", func() {
571571
e2esset.WaitForRunningAndNotReady(c, *ss.Spec.Replicas, ss)
572572
e2esset.WaitForStatusReadyReplicas(c, ss, 0)
573573
e2esset.UpdateReplicas(c, ss, 3)
574-
e2esset.ConfirmStatefulPodCount(c, 1, ss, 10*time.Second, true)
574+
confirmStatefulPodCount(c, 1, ss, 10*time.Second, true)
575575

576576
ginkgo.By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns)
577577
e2esset.RestoreHTTPProbe(c, ss)
@@ -604,7 +604,7 @@ var _ = SIGDescribe("StatefulSet", func() {
604604
e2esset.WaitForStatusReadyReplicas(c, ss, 0)
605605
e2esset.WaitForRunningAndNotReady(c, 3, ss)
606606
e2esset.UpdateReplicas(c, ss, 0)
607-
e2esset.ConfirmStatefulPodCount(c, 3, ss, 10*time.Second, true)
607+
confirmStatefulPodCount(c, 3, ss, 10*time.Second, true)
608608

609609
ginkgo.By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns)
610610
e2esset.RestoreHTTPProbe(c, ss)
@@ -651,7 +651,7 @@ var _ = SIGDescribe("StatefulSet", func() {
651651
e2esset.WaitForRunningAndNotReady(c, *ss.Spec.Replicas, ss)
652652
e2esset.WaitForStatusReadyReplicas(c, ss, 0)
653653
e2esset.UpdateReplicas(c, ss, 3)
654-
e2esset.ConfirmStatefulPodCount(c, 3, ss, 10*time.Second, false)
654+
confirmStatefulPodCount(c, 3, ss, 10*time.Second, false)
655655

656656
ginkgo.By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns)
657657
e2esset.RestoreHTTPProbe(c, ss)
@@ -662,7 +662,7 @@ var _ = SIGDescribe("StatefulSet", func() {
662662
e2esset.WaitForStatusReadyReplicas(c, ss, 0)
663663
e2esset.WaitForRunningAndNotReady(c, 3, ss)
664664
e2esset.UpdateReplicas(c, ss, 0)
665-
e2esset.ConfirmStatefulPodCount(c, 0, ss, 10*time.Second, false)
665+
confirmStatefulPodCount(c, 0, ss, 10*time.Second, false)
666666

667667
ginkgo.By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns)
668668
e2esset.RestoreHTTPProbe(c, ss)
@@ -1163,3 +1163,26 @@ func rollbackTest(c clientset.Interface, ns string, ss *appsv1.StatefulSet) {
11631163
priorRevision))
11641164
}
11651165
}
1166+
1167+
// confirmStatefulPodCount asserts that the current number of Pods in ss is count, waiting up to timeout for ss to
1168+
// to scale to count.
1169+
func confirmStatefulPodCount(c clientset.Interface, count int, ss *appsv1.StatefulSet, timeout time.Duration, hard bool) {
1170+
start := time.Now()
1171+
deadline := start.Add(timeout)
1172+
for t := time.Now(); t.Before(deadline); t = time.Now() {
1173+
podList := e2esset.GetPodList(c, ss)
1174+
statefulPodCount := len(podList.Items)
1175+
if statefulPodCount != count {
1176+
e2epod.LogPodStates(podList.Items)
1177+
if hard {
1178+
e2elog.Failf("StatefulSet %v scaled unexpectedly scaled to %d -> %d replicas", ss.Name, count, len(podList.Items))
1179+
} else {
1180+
e2elog.Logf("StatefulSet %v has not reached scale %d, at %d", ss.Name, count, statefulPodCount)
1181+
}
1182+
time.Sleep(1 * time.Second)
1183+
continue
1184+
}
1185+
e2elog.Logf("Verifying statefulset %v doesn't scale past %d for another %+v", ss.Name, count, deadline.Sub(t))
1186+
time.Sleep(1 * time.Second)
1187+
}
1188+
}

test/e2e/framework/statefulset/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ go_library(
2424
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
2525
"//test/e2e/framework:go_default_library",
2626
"//test/e2e/framework/log:go_default_library",
27-
"//test/e2e/framework/pod:go_default_library",
2827
"//test/e2e/manifest:go_default_library",
2928
"//test/utils/image:go_default_library",
3029
],

test/e2e/framework/statefulset/rest.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3434
e2efwk "k8s.io/kubernetes/test/e2e/framework"
3535
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
36-
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3736
"k8s.io/kubernetes/test/e2e/manifest"
3837
)
3938

@@ -220,29 +219,6 @@ func Restart(c clientset.Interface, ss *appsv1.StatefulSet) {
220219
update(c, ss.Namespace, ss.Name, func(ss *appsv1.StatefulSet) { *(ss.Spec.Replicas) = oldReplicas })
221220
}
222221

223-
// ConfirmStatefulPodCount asserts that the current number of Pods in ss is count, waiting up to timeout for ss to
224-
// to scale to count.
225-
func ConfirmStatefulPodCount(c clientset.Interface, count int, ss *appsv1.StatefulSet, timeout time.Duration, hard bool) {
226-
start := time.Now()
227-
deadline := start.Add(timeout)
228-
for t := time.Now(); t.Before(deadline); t = time.Now() {
229-
podList := GetPodList(c, ss)
230-
statefulPodCount := len(podList.Items)
231-
if statefulPodCount != count {
232-
e2epod.LogPodStates(podList.Items)
233-
if hard {
234-
e2elog.Failf("StatefulSet %v scaled unexpectedly scaled to %d -> %d replicas", ss.Name, count, len(podList.Items))
235-
} else {
236-
e2elog.Logf("StatefulSet %v has not reached scale %d, at %d", ss.Name, count, statefulPodCount)
237-
}
238-
time.Sleep(1 * time.Second)
239-
continue
240-
}
241-
e2elog.Logf("Verifying statefulset %v doesn't scale past %d for another %+v", ss.Name, count, deadline.Sub(t))
242-
time.Sleep(1 * time.Second)
243-
}
244-
}
245-
246222
// GetStatefulSet gets the StatefulSet named name in namespace.
247223
func GetStatefulSet(c clientset.Interface, namespace, name string) *appsv1.StatefulSet {
248224
ss, err := c.AppsV1().StatefulSets(namespace).Get(name, metav1.GetOptions{})

0 commit comments

Comments
 (0)