Skip to content

Commit acb2994

Browse files
authored
Merge pull request kubernetes#86199 from hwdef/clean-e2e-framework
test/e2e: move funcs from test/e2e/pod to other folders
2 parents e2cd6ff + d45107a commit acb2994

File tree

10 files changed

+127
-167
lines changed

10 files changed

+127
-167
lines changed

test/e2e/framework/pod/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ go_library(
1414
deps = [
1515
"//pkg/api/v1/pod:go_default_library",
1616
"//pkg/client/conditions:go_default_library",
17-
"//pkg/controller:go_default_library",
1817
"//pkg/kubelet/types:go_default_library",
1918
"//pkg/kubelet/util/format:go_default_library",
2019
"//staging/src/k8s.io/api/core/v1:go_default_library",
@@ -23,7 +22,6 @@ go_library(
2322
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
2423
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
2524
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
26-
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
2725
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
2826
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
2927
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",

test/e2e/framework/pod/create.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/util/uuid"
2626
clientset "k8s.io/client-go/kubernetes"
27-
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
2827
imageutils "k8s.io/kubernetes/test/utils/image"
2928
)
3029

@@ -33,40 +32,6 @@ var (
3332
BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox)
3433
)
3534

36-
// CreateWaitAndDeletePod creates the test pod, wait for (hopefully) success, and then delete the pod.
37-
// Note: need named return value so that the err assignment in the defer sets the returned error.
38-
// Has been shown to be necessary using Go 1.7.
39-
func CreateWaitAndDeletePod(c clientset.Interface, ns string, pvc *v1.PersistentVolumeClaim, command string) (err error) {
40-
e2elog.Logf("Creating nfs test pod")
41-
pod := MakePod(ns, nil, []*v1.PersistentVolumeClaim{pvc}, true, command)
42-
runPod, err := c.CoreV1().Pods(ns).Create(pod)
43-
if err != nil {
44-
return fmt.Errorf("pod Create API error: %v", err)
45-
}
46-
defer func() {
47-
delErr := DeletePodWithWait(c, runPod)
48-
if err == nil { // don't override previous err value
49-
err = delErr // assign to returned err, can be nil
50-
}
51-
}()
52-
53-
err = testPodSuccessOrFail(c, ns, runPod)
54-
if err != nil {
55-
return fmt.Errorf("pod %q did not exit with Success: %v", runPod.Name, err)
56-
}
57-
return // note: named return value
58-
}
59-
60-
// testPodSuccessOrFail tests whether the pod's exit code is zero.
61-
func testPodSuccessOrFail(c clientset.Interface, ns string, pod *v1.Pod) error {
62-
e2elog.Logf("Pod should terminate with exitcode 0 (success)")
63-
if err := WaitForPodSuccessInNamespace(c, pod.Name, ns); err != nil {
64-
return fmt.Errorf("pod %q failed to reach Success: %v", pod.Name, err)
65-
}
66-
e2elog.Logf("Pod %v succeeded ", pod.Name)
67-
return nil
68-
}
69-
7035
// CreateUnschedulablePod with given claims based on node selector
7136
func CreateUnschedulablePod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim, isPrivileged bool, command string) (*v1.Pod, error) {
7237
pod := MakePod(namespace, nodeSelector, pvclaims, isPrivileged, command)

test/e2e/framework/pod/resource.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/labels"
3232
"k8s.io/apimachinery/pkg/types"
33-
"k8s.io/apimachinery/pkg/util/sets"
3433
"k8s.io/apimachinery/pkg/util/wait"
3534
clientset "k8s.io/client-go/kubernetes"
3635
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
@@ -147,33 +146,6 @@ func (r ProxyResponseChecker) CheckAllResponses() (done bool, err error) {
147146
return true, nil
148147
}
149148

150-
// CountRemainingPods queries the server to count number of remaining pods, and number of pods that had a missing deletion timestamp.
151-
func CountRemainingPods(c clientset.Interface, namespace string) (int, int, error) {
152-
// check for remaining pods
153-
pods, err := c.CoreV1().Pods(namespace).List(metav1.ListOptions{})
154-
if err != nil {
155-
return 0, 0, err
156-
}
157-
158-
// nothing remains!
159-
if len(pods.Items) == 0 {
160-
return 0, 0, nil
161-
}
162-
163-
// stuff remains, log about it
164-
LogPodStates(pods.Items)
165-
166-
// check if there were any pods with missing deletion timestamp
167-
numPods := len(pods.Items)
168-
missingTimestamp := 0
169-
for _, pod := range pods.Items {
170-
if pod.DeletionTimestamp == nil {
171-
missingTimestamp++
172-
}
173-
}
174-
return numPods, missingTimestamp, nil
175-
}
176-
177149
func podRunning(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
178150
return func() (bool, error) {
179151
pod, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
@@ -321,15 +293,6 @@ func podsRunning(c clientset.Interface, pods *v1.PodList) []error {
321293
return e
322294
}
323295

324-
// DumpAllPodInfo logs basic info for all pods.
325-
func DumpAllPodInfo(c clientset.Interface) {
326-
pods, err := c.CoreV1().Pods("").List(metav1.ListOptions{})
327-
if err != nil {
328-
e2elog.Logf("unable to fetch pod debug info: %v", err)
329-
}
330-
LogPodStates(pods.Items)
331-
}
332-
333296
// LogPodStates logs basic info of provided pods for debugging.
334297
func LogPodStates(pods []v1.Pod) {
335298
// Find maximum widths for pod, node, and phase strings for column printing.
@@ -578,40 +541,3 @@ func GetPodsInNamespace(c clientset.Interface, ns string, ignoreLabels map[strin
578541
}
579542
return filtered, nil
580543
}
581-
582-
// GetPodsScheduled returns a number of currently scheduled and not scheduled Pods.
583-
func GetPodsScheduled(masterNodes sets.String, pods *v1.PodList) (scheduledPods, notScheduledPods []v1.Pod) {
584-
for _, pod := range pods.Items {
585-
if !masterNodes.Has(pod.Spec.NodeName) {
586-
if pod.Spec.NodeName != "" {
587-
_, scheduledCondition := podutil.GetPodCondition(&pod.Status, v1.PodScheduled)
588-
gomega.Expect(scheduledCondition != nil).To(gomega.Equal(true))
589-
gomega.Expect(scheduledCondition.Status).To(gomega.Equal(v1.ConditionTrue))
590-
scheduledPods = append(scheduledPods, pod)
591-
} else {
592-
_, scheduledCondition := podutil.GetPodCondition(&pod.Status, v1.PodScheduled)
593-
gomega.Expect(scheduledCondition != nil).To(gomega.Equal(true))
594-
gomega.Expect(scheduledCondition.Status).To(gomega.Equal(v1.ConditionFalse))
595-
if scheduledCondition.Reason == "Unschedulable" {
596-
597-
notScheduledPods = append(notScheduledPods, pod)
598-
}
599-
}
600-
}
601-
}
602-
return
603-
}
604-
605-
// PatchContainerImages replaces the specified Container Registry with a custom
606-
// one provided via the KUBE_TEST_REPO_LIST env variable
607-
func PatchContainerImages(containers []v1.Container) error {
608-
var err error
609-
for _, c := range containers {
610-
c.Image, err = imageutils.ReplaceRegistryInImageURL(c.Image)
611-
if err != nil {
612-
return err
613-
}
614-
}
615-
616-
return nil
617-
}

test/e2e/framework/pod/wait.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"k8s.io/apimachinery/pkg/util/wait"
3535
clientset "k8s.io/client-go/kubernetes"
3636
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
37-
"k8s.io/kubernetes/pkg/controller"
3837
"k8s.io/kubernetes/pkg/kubelet/util/format"
3938
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
4039
e2eresource "k8s.io/kubernetes/test/e2e/framework/resource"
@@ -536,49 +535,6 @@ func WaitForPodsWithLabelRunningReady(c clientset.Interface, ns string, label la
536535
return pods, err
537536
}
538537

539-
// WaitForPodsInactive waits until there are no active pods left in the PodStore.
540-
// This is to make a fair comparison of deletion time between DeleteRCAndPods
541-
// and DeleteRCAndWaitForGC, because the RC controller decreases status.replicas
542-
// when the pod is inactvie.
543-
func WaitForPodsInactive(ps *testutils.PodStore, interval, timeout time.Duration) error {
544-
var activePods []*v1.Pod
545-
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
546-
pods := ps.List()
547-
activePods = controller.FilterActivePods(pods)
548-
if len(activePods) != 0 {
549-
return false, nil
550-
}
551-
return true, nil
552-
})
553-
554-
if err == wait.ErrWaitTimeout {
555-
for _, pod := range activePods {
556-
e2elog.Logf("ERROR: Pod %q running on %q is still active", pod.Name, pod.Spec.NodeName)
557-
}
558-
return fmt.Errorf("there are %d active pods. E.g. %q on node %q", len(activePods), activePods[0].Name, activePods[0].Spec.NodeName)
559-
}
560-
return err
561-
}
562-
563-
// WaitForPodsGone waits until there are no pods left in the PodStore.
564-
func WaitForPodsGone(ps *testutils.PodStore, interval, timeout time.Duration) error {
565-
var pods []*v1.Pod
566-
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
567-
if pods = ps.List(); len(pods) == 0 {
568-
return true, nil
569-
}
570-
return false, nil
571-
})
572-
573-
if err == wait.ErrWaitTimeout {
574-
for _, pod := range pods {
575-
e2elog.Logf("ERROR: Pod %q still exists. Node: %q", pod.Name, pod.Spec.NodeName)
576-
}
577-
return fmt.Errorf("there are %d pods left. E.g. %q on node %q", len(pods), pods[0].Name, pods[0].Spec.NodeName)
578-
}
579-
return err
580-
}
581-
582538
// WaitForPodsReady waits for the pods to become ready.
583539
func WaitForPodsReady(c clientset.Interface, ns, name string, minReadySeconds int) error {
584540
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))

test/e2e/framework/util.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ func DeleteResourceAndWaitForGC(c clientset.Interface, kind schema.GroupKind, ns
12371237
timeout = timeout + 3*time.Minute
12381238
}
12391239

1240-
err = e2epod.WaitForPodsInactive(ps, interval, timeout)
1240+
err = waitForPodsInactive(ps, interval, timeout)
12411241
if err != nil {
12421242
return fmt.Errorf("error while waiting for pods to become inactive %s: %v", name, err)
12431243
}
@@ -1247,13 +1247,56 @@ func DeleteResourceAndWaitForGC(c clientset.Interface, kind schema.GroupKind, ns
12471247
// In gce, at any point, small percentage of nodes can disappear for
12481248
// ~10 minutes due to hostError. 20 minutes should be long enough to
12491249
// restart VM in that case and delete the pod.
1250-
err = e2epod.WaitForPodsGone(ps, interval, 20*time.Minute)
1250+
err = waitForPodsGone(ps, interval, 20*time.Minute)
12511251
if err != nil {
12521252
return fmt.Errorf("error while waiting for pods gone %s: %v", name, err)
12531253
}
12541254
return nil
12551255
}
12561256

1257+
// waitForPodsGone waits until there are no pods left in the PodStore.
1258+
func waitForPodsGone(ps *testutils.PodStore, interval, timeout time.Duration) error {
1259+
var pods []*v1.Pod
1260+
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
1261+
if pods = ps.List(); len(pods) == 0 {
1262+
return true, nil
1263+
}
1264+
return false, nil
1265+
})
1266+
1267+
if err == wait.ErrWaitTimeout {
1268+
for _, pod := range pods {
1269+
Logf("ERROR: Pod %q still exists. Node: %q", pod.Name, pod.Spec.NodeName)
1270+
}
1271+
return fmt.Errorf("there are %d pods left. E.g. %q on node %q", len(pods), pods[0].Name, pods[0].Spec.NodeName)
1272+
}
1273+
return err
1274+
}
1275+
1276+
// waitForPodsInactive waits until there are no active pods left in the PodStore.
1277+
// This is to make a fair comparison of deletion time between DeleteRCAndPods
1278+
// and DeleteRCAndWaitForGC, because the RC controller decreases status.replicas
1279+
// when the pod is inactvie.
1280+
func waitForPodsInactive(ps *testutils.PodStore, interval, timeout time.Duration) error {
1281+
var activePods []*v1.Pod
1282+
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
1283+
pods := ps.List()
1284+
activePods = controller.FilterActivePods(pods)
1285+
if len(activePods) != 0 {
1286+
return false, nil
1287+
}
1288+
return true, nil
1289+
})
1290+
1291+
if err == wait.ErrWaitTimeout {
1292+
for _, pod := range activePods {
1293+
Logf("ERROR: Pod %q running on %q is still active", pod.Name, pod.Spec.NodeName)
1294+
}
1295+
return fmt.Errorf("there are %d active pods. E.g. %q on node %q", len(activePods), activePods[0].Name, activePods[0].Spec.NodeName)
1296+
}
1297+
return err
1298+
}
1299+
12571300
// RunHostCmd runs the given cmd in the context of the given pod using `kubectl exec`
12581301
// inside of a shell.
12591302
func RunHostCmd(ns, name, cmd string) (string, error) {

test/e2e/scheduling/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
importpath = "k8s.io/kubernetes/test/e2e/scheduling",
1818
visibility = ["//visibility:public"],
1919
deps = [
20+
"//pkg/api/v1/pod:go_default_library",
2021
"//pkg/apis/core/v1/helper/qos:go_default_library",
2122
"//pkg/apis/extensions:go_default_library",
2223
"//pkg/apis/scheduling:go_default_library",

test/e2e/scheduling/framework.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"k8s.io/apimachinery/pkg/util/sets"
2828
clientset "k8s.io/client-go/kubernetes"
2929
"k8s.io/kubernetes/test/e2e/framework"
30-
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
3130
)
3231

3332
var (
@@ -90,7 +89,7 @@ func getScheduledAndUnscheduledPods(c clientset.Interface, masterNodes sets.Stri
9089
}
9190
}
9291
pods.Items = filteredPods
93-
return e2epod.GetPodsScheduled(masterNodes, pods)
92+
return GetPodsScheduled(masterNodes, pods)
9493
}
9594

9695
// getDeletingPods returns whether there are any pods marked for deletion.

test/e2e/scheduling/predicates.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scheduling
1818

1919
import (
2020
"fmt"
21+
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
2122
"time"
2223

2324
v1 "k8s.io/api/core/v1"
@@ -730,7 +731,7 @@ func WaitForSchedulerAfterAction(f *framework.Framework, action common.Action, n
730731
func verifyResult(c clientset.Interface, expectedScheduled int, expectedNotScheduled int, ns string) {
731732
allPods, err := c.CoreV1().Pods(ns).List(metav1.ListOptions{})
732733
framework.ExpectNoError(err)
733-
scheduledPods, notScheduledPods := e2epod.GetPodsScheduled(masterNodes, allPods)
734+
scheduledPods, notScheduledPods := GetPodsScheduled(masterNodes, allPods)
734735

735736
framework.ExpectEqual(len(notScheduledPods), expectedNotScheduled, fmt.Sprintf("Not scheduled Pods: %#v", notScheduledPods))
736737
framework.ExpectEqual(len(scheduledPods), expectedScheduled, fmt.Sprintf("Scheduled Pods: %#v", scheduledPods))
@@ -817,3 +818,26 @@ func translateIPv4ToIPv6(ip string) string {
817818
}
818819
return ip
819820
}
821+
822+
// GetPodsScheduled returns a number of currently scheduled and not scheduled Pods.
823+
func GetPodsScheduled(masterNodes sets.String, pods *v1.PodList) (scheduledPods, notScheduledPods []v1.Pod) {
824+
for _, pod := range pods.Items {
825+
if !masterNodes.Has(pod.Spec.NodeName) {
826+
if pod.Spec.NodeName != "" {
827+
_, scheduledCondition := podutil.GetPodCondition(&pod.Status, v1.PodScheduled)
828+
framework.ExpectEqual(scheduledCondition != nil, true)
829+
framework.ExpectEqual(scheduledCondition.Status, v1.ConditionTrue)
830+
scheduledPods = append(scheduledPods, pod)
831+
} else {
832+
_, scheduledCondition := podutil.GetPodCondition(&pod.Status, v1.PodScheduled)
833+
framework.ExpectEqual(scheduledCondition != nil, true)
834+
framework.ExpectEqual(scheduledCondition.Status, v1.ConditionFalse)
835+
if scheduledCondition.Reason == "Unschedulable" {
836+
837+
notScheduledPods = append(notScheduledPods, pod)
838+
}
839+
}
840+
}
841+
}
842+
return
843+
}

0 commit comments

Comments
 (0)