From c104671401af2a20152cbc38379a63b8a39947a0 Mon Sep 17 00:00:00 2001 From: Edward Haas Date: Sun, 18 Oct 2020 15:42:06 +0300 Subject: [PATCH] test, e2e: Remove duplication when using PodClient.CreateSync The CreateSync method includes the waiting for the pod to become running and returns a fresh new pod instance. In addition, errors are asserted in the method. Therefore, there is no need for the callers to repeat these operations. Some, like the error assertions, will never be reached in case they occur as they will explode from within the method itself. Signed-off-by: Edward Haas --- test/e2e/common/downwardapi_volume.go | 6 +----- test/e2e/common/empty_dir.go | 11 ----------- test/e2e/common/projected_downwardapi.go | 6 +----- test/e2e/network/dual_stack.go | 9 ++------- test/e2e_node/node_problem_detector_linux.go | 4 +--- 5 files changed, 5 insertions(+), 31 deletions(-) diff --git a/test/e2e/common/downwardapi_volume.go b/test/e2e/common/downwardapi_volume.go index 654a4dc9766..c802e730845 100644 --- a/test/e2e/common/downwardapi_volume.go +++ b/test/e2e/common/downwardapi_volume.go @@ -17,7 +17,6 @@ limitations under the License. package common import ( - "context" "fmt" "time" @@ -165,10 +164,7 @@ var _ = ginkgo.Describe("[sig-storage] Downward API volume", func() { containerName := "client-container" ginkgo.By("Creating the pod") - podClient.CreateSync(pod) - - pod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{}) - framework.ExpectNoError(err, "Failed to get pod %q", pod.Name) + pod = podClient.CreateSync(pod) gomega.Eventually(func() (string, error) { return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName) diff --git a/test/e2e/common/empty_dir.go b/test/e2e/common/empty_dir.go index 4392ae95059..2abf7722296 100644 --- a/test/e2e/common/empty_dir.go +++ b/test/e2e/common/empty_dir.go @@ -17,7 +17,6 @@ limitations under the License. package common import ( - "context" "fmt" "path" @@ -26,7 +25,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" - e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" imageutils "k8s.io/kubernetes/test/utils/image" ) @@ -278,18 +276,9 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { }, } - var err error ginkgo.By("Creating Pod") pod = f.PodClient().CreateSync(pod) - ginkgo.By("Waiting for the pod running") - err = e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) - framework.ExpectNoError(err, "failed to deploy pod %s", pod.Name) - - ginkgo.By("Geting the pod") - pod, err = f.PodClient().Get(context.TODO(), pod.Name, metav1.GetOptions{}) - framework.ExpectNoError(err, "failed to get pod %s", pod.Name) - ginkgo.By("Reading file content from the nginx-container") result := f.ExecShellInContainer(pod.Name, busyBoxMainContainerName, fmt.Sprintf("cat %s", busyBoxMainVolumeFilePath)) framework.ExpectEqual(result, message, "failed to match expected string %s with %s", message, resultString) diff --git a/test/e2e/common/projected_downwardapi.go b/test/e2e/common/projected_downwardapi.go index 4ad2f16f80e..dc15aa552ce 100644 --- a/test/e2e/common/projected_downwardapi.go +++ b/test/e2e/common/projected_downwardapi.go @@ -17,7 +17,6 @@ limitations under the License. package common import ( - "context" "fmt" "time" @@ -165,10 +164,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected downwardAPI", func() { containerName := "client-container" ginkgo.By("Creating the pod") - podClient.CreateSync(pod) - - pod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{}) - framework.ExpectNoError(err, "Failed to get pod %q", pod.Name) + pod = podClient.CreateSync(pod) gomega.Eventually(func() (string, error) { return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName) diff --git a/test/e2e/network/dual_stack.go b/test/e2e/network/dual_stack.go index 6feb9aa9512..5565162d865 100644 --- a/test/e2e/network/dual_stack.go +++ b/test/e2e/network/dual_stack.go @@ -33,7 +33,6 @@ import ( "k8s.io/kubernetes/test/e2e/framework" e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment" e2enode "k8s.io/kubernetes/test/e2e/framework/node" - e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2eservice "k8s.io/kubernetes/test/e2e/framework/service" imageutils "k8s.io/kubernetes/test/utils/image" netutils "k8s.io/utils/net" @@ -99,11 +98,7 @@ var _ = SIGDescribe("[Feature:IPv6DualStackAlphaFeature] [LinuxOnly]", func() { } ginkgo.By("submitting the pod to kubernetes") - podClient.CreateSync(pod) - framework.ExpectNoError(e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)) - - p, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{}) - framework.ExpectNoError(err, "Failed to get pod %q", pod.Name) + p := podClient.CreateSync(pod) gomega.Expect(p.Status.PodIP).ShouldNot(gomega.BeEquivalentTo("")) gomega.Expect(p.Status.PodIPs).ShouldNot(gomega.BeNil()) @@ -116,7 +111,7 @@ var _ = SIGDescribe("[Feature:IPv6DualStackAlphaFeature] [LinuxOnly]", func() { framework.ExpectEqual(isIPv4(p.Status.PodIPs[0].IP) != isIPv4(p.Status.PodIPs[1].IP), true) ginkgo.By("deleting the pod") - err = podClient.Delete(context.TODO(), pod.Name, *metav1.NewDeleteOptions(30)) + err := podClient.Delete(context.TODO(), pod.Name, *metav1.NewDeleteOptions(30)) framework.ExpectNoError(err, "failed to delete pod") }) diff --git a/test/e2e_node/node_problem_detector_linux.go b/test/e2e_node/node_problem_detector_linux.go index 50651a085f4..aea4a5a4683 100644 --- a/test/e2e_node/node_problem_detector_linux.go +++ b/test/e2e_node/node_problem_detector_linux.go @@ -171,7 +171,7 @@ var _ = framework.KubeDescribe("NodeProblemDetector [NodeFeature:NodeProblemDete ginkgo.By("Create the node problem detector") hostPathType := new(v1.HostPathType) *hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate)) - f.PodClient().CreateSync(&v1.Pod{ + pod := f.PodClient().CreateSync(&v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -237,8 +237,6 @@ var _ = framework.KubeDescribe("NodeProblemDetector [NodeFeature:NodeProblemDete }, }, }) - pod, err := f.PodClient().Get(context.TODO(), name, metav1.GetOptions{}) - framework.ExpectNoError(err) // TODO: remove hardcoded kubelet volume directory path // framework.TestContext.KubeVolumeDir is currently not populated for node e2e hostLogFile = "/var/lib/kubelet/pods/" + string(pod.UID) + "/volumes/kubernetes.io~empty-dir" + logFile