diff --git a/test/e2e/apimachinery/table_conversion.go b/test/e2e/apimachinery/table_conversion.go index 66dce347972..959ea522a6d 100644 --- a/test/e2e/apimachinery/table_conversion.go +++ b/test/e2e/apimachinery/table_conversion.go @@ -35,8 +35,8 @@ import ( utilversion "k8s.io/apimachinery/pkg/util/version" "k8s.io/cli-runtime/pkg/printers" "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" ) var serverPrintVersion = utilversion.MustParseSemantic("v1.10.0") @@ -55,7 +55,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() { podName := "pod-1" framework.Logf("Creating pod %s", podName) - _, err := c.CoreV1().Pods(ns).Create(context.TODO(), newTablePod(podName), metav1.CreateOptions{}) + _, err := c.CoreV1().Pods(ns).Create(context.TODO(), newTablePod(ns, podName), metav1.CreateOptions{}) framework.ExpectNoError(err, "failed to create pod %s in namespace: %s", podName, ns) table := &metav1beta1.Table{} @@ -177,25 +177,10 @@ func printTable(table *metav1beta1.Table) string { return buf.String() } -func newTablePod(podName string) *v1.Pod { - containerName := fmt.Sprintf("%s-container", podName) +func newTablePod(ns, podName string) *v1.Pod { port := 8080 - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: podName, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: containerName, - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"porter"}, - Env: []v1.EnvVar{{Name: fmt.Sprintf("SERVE_PORT_%d", port), Value: "foo"}}, - Ports: []v1.ContainerPort{{ContainerPort: int32(port)}}, - }, - }, - RestartPolicy: v1.RestartPolicyNever, - }, - } + pod := e2epod.NewAgnhostPod(ns, podName, nil, nil, []v1.ContainerPort{{ContainerPort: int32(port)}}, "porter") + pod.Spec.Containers[0].Env = []v1.EnvVar{{Name: fmt.Sprintf("SERVE_PORT_%d", port), Value: "foo"}} + pod.Spec.RestartPolicy = v1.RestartPolicyNever return pod } diff --git a/test/e2e/auth/node_authn.go b/test/e2e/auth/node_authn.go index 939f038108e..e18a26adac3 100644 --- a/test/e2e/auth/node_authn.go +++ b/test/e2e/auth/node_authn.go @@ -24,11 +24,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/cluster/ports" "k8s.io/kubernetes/test/e2e/framework" - imageutils "k8s.io/kubernetes/test/utils/image" "github.com/onsi/ginkgo" "github.com/onsi/gomega" e2enode "k8s.io/kubernetes/test/e2e/framework/node" + e2epod "k8s.io/kubernetes/test/e2e/framework/pod" ) var _ = SIGDescribe("[Feature:NodeAuthenticator]", func() { @@ -93,19 +93,7 @@ var _ = SIGDescribe("[Feature:NodeAuthenticator]", func() { }) func createNodeAuthTestPod(f *framework.Framework) *v1.Pod { - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "test-node-authn-", - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: "test-node-authn", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Command: []string{"sleep", "3600"}, - }}, - RestartPolicy: v1.RestartPolicyNever, - }, - } - + pod := e2epod.NewAgnhostPod(f.Namespace.Name, "agnhost-pod", nil, nil, nil) + pod.ObjectMeta.GenerateName = "test-node-authn-" return f.PodClient().CreateSync(pod) } diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index 35ac43001d2..a47ae3f20fe 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -3587,11 +3587,7 @@ func createPausePodDeployment(cs clientset.Interface, name, ns string, replicas labels := map[string]string{"deployment": "agnhost-pause"} pauseDeployment := e2edeployment.NewDeployment(name, int32(replicas), labels, "", "", appsv1.RollingUpdateDeploymentStrategyType) - pauseDeployment.Spec.Template.Spec.Containers[0] = v1.Container{ - Name: "agnhost-pause", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"pause"}, - } + pauseDeployment.Spec.Template.Spec.Containers[0] = e2epod.NewAgnhostContainer("agnhost-pause", nil, nil, "pause") pauseDeployment.Spec.Template.Spec.Affinity = &v1.Affinity{ PodAntiAffinity: &v1.PodAntiAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ @@ -3612,25 +3608,12 @@ func createPausePodDeployment(cs clientset.Interface, name, ns string, replicas // createPodOrFail creates a pod with the specified containerPorts. func createPodOrFail(c clientset.Interface, ns, name string, labels map[string]string, containerPorts []v1.ContainerPort) { ginkgo.By(fmt.Sprintf("Creating pod %s in namespace %s", name, ns)) - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Labels: labels, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "pause", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"pause"}, - Ports: containerPorts, - // Add a dummy environment variable to work around a docker issue. - // https://github.com/docker/docker/issues/14203 - Env: []v1.EnvVar{{Name: "FOO", Value: " "}}, - }, - }, - }, - } + pod := e2epod.NewAgnhostPod(ns, name, nil, nil, containerPorts) + pod.ObjectMeta.Labels = labels + // Add a dummy environment variable to work around a docker issue. + // https://github.com/docker/docker/issues/14203 + pod.Spec.Containers[0].Env = []v1.EnvVar{{Name: "FOO", Value: " "}} + _, err := c.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{}) framework.ExpectNoError(err, "failed to create pod %s in namespace %s", name, ns) } diff --git a/test/e2e/node/pods.go b/test/e2e/node/pods.go index 23c5e82e1da..a5c1499ef3b 100644 --- a/test/e2e/node/pods.go +++ b/test/e2e/node/pods.go @@ -63,23 +63,10 @@ var _ = SIGDescribe("Pods Extended", func() { ginkgo.By("creating the pod") name := "pod-submit-remove-" + string(uuid.NewUUID()) value := strconv.Itoa(time.Now().Nanosecond()) - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Labels: map[string]string{ - "name": "foo", - "time": value, - }, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "agnhost", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"pause"}, - }, - }, - }, + pod := e2epod.NewAgnhostPod(f.Namespace.Name, name, nil, nil, nil) + pod.ObjectMeta.Labels = map[string]string{ + "name": "foo", + "time": value, } ginkgo.By("setting up selector") diff --git a/test/e2e/node/pre_stop.go b/test/e2e/node/pre_stop.go index fe3e38e7d25..bc7308753f4 100644 --- a/test/e2e/node/pre_stop.go +++ b/test/e2e/node/pre_stop.go @@ -44,21 +44,7 @@ type State struct { func testPreStop(c clientset.Interface, ns string) { // This is the server that will receive the preStop notification - podDescr := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "server", - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "server", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"nettest"}, - Ports: []v1.ContainerPort{{ContainerPort: 8080}}, - }, - }, - }, - } + podDescr := e2epod.NewAgnhostPod(ns, "server", nil, nil, []v1.ContainerPort{{ContainerPort: 8080}}, "nettest") ginkgo.By(fmt.Sprintf("Creating server pod %s in namespace %s", podDescr.Name, ns)) podDescr, err := c.CoreV1().Pods(ns).Create(context.TODO(), podDescr, metav1.CreateOptions{}) framework.ExpectNoError(err, fmt.Sprintf("creating pod %s", podDescr.Name)) diff --git a/test/e2e/storage/empty_dir_wrapper.go b/test/e2e/storage/empty_dir_wrapper.go index a9054369fe8..ed79810cc3d 100644 --- a/test/e2e/storage/empty_dir_wrapper.go +++ b/test/e2e/storage/empty_dir_wrapper.go @@ -214,25 +214,8 @@ func createGitServer(f *framework.Framework) (gitURL string, gitRepo string, cle labels := map[string]string{"name": gitServerPodName} - gitServerPod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: gitServerPodName, - Labels: labels, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "git-repo", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"fake-gitserver"}, - ImagePullPolicy: "IfNotPresent", - Ports: []v1.ContainerPort{ - {ContainerPort: int32(containerPort)}, - }, - }, - }, - }, - } + gitServerPod := e2epod.NewAgnhostPod(f.Namespace.Name, gitServerPodName, nil, nil, []v1.ContainerPort{{ContainerPort: int32(containerPort)}}, "fake-gitserver") + gitServerPod.ObjectMeta.Labels = labels f.PodClient().CreateSync(gitServerPod) // Portal IP and port diff --git a/test/e2e/storage/testsuites/subpath.go b/test/e2e/storage/testsuites/subpath.go index 5de82f8853d..b51695cdfc7 100644 --- a/test/e2e/storage/testsuites/subpath.go +++ b/test/e2e/storage/testsuites/subpath.go @@ -508,6 +508,28 @@ func SubpathTestPod(f *framework.Framework, subpath, volumeType string, source * probeVolumeName = "liveness-probe-volume" seLinuxOptions = &v1.SELinuxOptions{Level: "s0:c0,c1"} ) + + volumeMount := v1.VolumeMount{Name: volumeName, MountPath: volumePath} + volumeSubpathMount := v1.VolumeMount{Name: volumeName, MountPath: volumePath, SubPath: subpath} + probeMount := v1.VolumeMount{Name: probeVolumeName, MountPath: probeVolumePath} + + initSubpathContainer := e2epod.NewAgnhostContainer( + fmt.Sprintf("test-init-subpath-%s", suffix), + []v1.VolumeMount{volumeSubpathMount, probeMount}, nil, "mounttest") + initSubpathContainer.SecurityContext = e2evolume.GenerateSecurityContext(privilegedSecurityContext) + initVolumeContainer := e2epod.NewAgnhostContainer( + fmt.Sprintf("test-init-volume-%s", suffix), + []v1.VolumeMount{volumeMount, probeMount}, nil, "mounttest") + initVolumeContainer.SecurityContext = e2evolume.GenerateSecurityContext(privilegedSecurityContext) + subpathContainer := e2epod.NewAgnhostContainer( + fmt.Sprintf("test-container-subpath-%s", suffix), + []v1.VolumeMount{volumeSubpathMount, probeMount}, nil, "mounttest") + subpathContainer.SecurityContext = e2evolume.GenerateSecurityContext(privilegedSecurityContext) + volumeContainer := e2epod.NewAgnhostContainer( + fmt.Sprintf("test-container-volume-%s", suffix), + []v1.VolumeMount{volumeMount, probeMount}, nil, "mounttest") + volumeContainer.SecurityContext = e2evolume.GenerateSecurityContext(privilegedSecurityContext) + return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("pod-subpath-test-%s", suffix), @@ -516,88 +538,17 @@ func SubpathTestPod(f *framework.Framework, subpath, volumeType string, source * Spec: v1.PodSpec{ InitContainers: []v1.Container{ { - Name: fmt.Sprintf("init-volume-%s", suffix), - Image: e2evolume.GetTestImage(imageutils.GetE2EImage(imageutils.BusyBox)), - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: volumePath, - }, - { - Name: probeVolumeName, - MountPath: probeVolumePath, - }, - }, - SecurityContext: e2evolume.GenerateSecurityContext(privilegedSecurityContext), - }, - { - Name: fmt.Sprintf("test-init-subpath-%s", suffix), - Image: mountImage, - Args: []string{"mounttest"}, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: volumePath, - SubPath: subpath, - }, - { - Name: probeVolumeName, - MountPath: probeVolumePath, - }, - }, - SecurityContext: e2evolume.GenerateSecurityContext(privilegedSecurityContext), - }, - { - Name: fmt.Sprintf("test-init-volume-%s", suffix), - Image: mountImage, - Args: []string{"mounttest"}, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: volumePath, - }, - { - Name: probeVolumeName, - MountPath: probeVolumePath, - }, - }, + Name: fmt.Sprintf("init-volume-%s", suffix), + Image: e2evolume.GetTestImage(imageutils.GetE2EImage(imageutils.BusyBox)), + VolumeMounts: []v1.VolumeMount{volumeMount, probeMount}, SecurityContext: e2evolume.GenerateSecurityContext(privilegedSecurityContext), }, + initSubpathContainer, + initVolumeContainer, }, Containers: []v1.Container{ - { - Name: fmt.Sprintf("test-container-subpath-%s", suffix), - Image: mountImage, - Args: []string{"mounttest"}, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: volumePath, - SubPath: subpath, - }, - { - Name: probeVolumeName, - MountPath: probeVolumePath, - }, - }, - SecurityContext: e2evolume.GenerateSecurityContext(privilegedSecurityContext), - }, - { - Name: fmt.Sprintf("test-container-volume-%s", suffix), - Image: mountImage, - Args: []string{"mounttest"}, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: volumePath, - }, - { - Name: probeVolumeName, - MountPath: probeVolumePath, - }, - }, - SecurityContext: e2evolume.GenerateSecurityContext(privilegedSecurityContext), - }, + subpathContainer, + volumeContainer, }, RestartPolicy: v1.RestartPolicyNever, TerminationGracePeriodSeconds: &gracePeriod, diff --git a/test/e2e/windows/dns.go b/test/e2e/windows/dns.go index 473b74b11f4..d5945fd6a1f 100644 --- a/test/e2e/windows/dns.go +++ b/test/e2e/windows/dns.go @@ -26,7 +26,6 @@ import ( "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" "github.com/onsi/ginkgo" ) @@ -45,7 +44,7 @@ var _ = SIGDescribe("DNS", func() { testSearchPath := "resolv.conf.local" ginkgo.By("Creating a pod with dnsPolicy=None and customized dnsConfig...") - testUtilsPod := generateDNSUtilsPod() + testUtilsPod := e2epod.NewAgnhostPod(f.Namespace.Name, "e2e-dns-utils", nil, nil, nil) testUtilsPod.Spec.DNSPolicy = v1.DNSNone testUtilsPod.Spec.DNSConfig = &v1.PodDNSConfig{ Nameservers: []string{testInjectedIP}, @@ -90,23 +89,3 @@ var _ = SIGDescribe("DNS", func() { // TODO: Add more test cases for other DNSPolicies. }) }) - -func generateDNSUtilsPod() *v1.Pod { - return &v1.Pod{ - TypeMeta: metav1.TypeMeta{ - Kind: "Pod", - }, - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "e2e-dns-utils-", - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "util", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Command: []string{"sleep", "10000"}, - }, - }, - }, - } -}