From 9e17a0e9f3e33341f7c4d241e7d46be0554273a5 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Thu, 17 Oct 2019 00:10:38 +0000 Subject: [PATCH] Move CreateNginxPod() to specific e2e CreateNginxPod() is called from flexvolume_online_resize only and that seems storage specific function because that requires a PVC. So this moves the function to the place which calls it for the code cleanup. --- test/e2e/framework/pod/create.go | 61 ------------------- test/e2e/storage/flexvolume_online_resize.go | 64 +++++++++++++++++++- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/test/e2e/framework/pod/create.go b/test/e2e/framework/pod/create.go index c6e07230188..417ec2f83ad 100644 --- a/test/e2e/framework/pod/create.go +++ b/test/e2e/framework/pod/create.go @@ -112,26 +112,6 @@ func CreatePod(client clientset.Interface, namespace string, nodeSelector map[st return pod, nil } -// CreateNginxPod creates an enginx pod. -func CreateNginxPod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) (*v1.Pod, error) { - pod := makeNginxPod(namespace, nodeSelector, pvclaims) - pod, err := client.CoreV1().Pods(namespace).Create(pod) - if err != nil { - return nil, fmt.Errorf("pod Create API error: %v", err) - } - // Waiting for pod to be running - err = WaitForPodNameRunningInNamespace(client, pod.Name, namespace) - if err != nil { - return pod, fmt.Errorf("pod %q is not Running: %v", pod.Name, err) - } - // get fresh pod info - pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{}) - if err != nil { - return pod, fmt.Errorf("pod Get API error: %v", err) - } - return pod, nil -} - // CreateSecPod creates security pod with given claims func CreateSecPod(client clientset.Interface, namespace string, pvclaims []*v1.PersistentVolumeClaim, inlineVolumeSources []*v1.VolumeSource, isPrivileged bool, command string, hostIPC bool, hostPID bool, seLinuxLabel *v1.SELinuxOptions, fsGroup *int64, timeout time.Duration) (*v1.Pod, error) { return CreateSecPodWithNodeSelection(client, namespace, pvclaims, inlineVolumeSources, isPrivileged, command, hostIPC, hostPID, seLinuxLabel, fsGroup, NodeSelection{}, timeout) @@ -208,47 +188,6 @@ func MakePod(ns string, nodeSelector map[string]string, pvclaims []*v1.Persisten return podSpec } -// makeNginxPod returns a pod definition based on the namespace using nginx image -func makeNginxPod(ns string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) *v1.Pod { - podSpec := &v1.Pod{ - TypeMeta: metav1.TypeMeta{ - Kind: "Pod", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - GenerateName: "pvc-tester-", - Namespace: ns, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "write-pod", - Image: "nginx", - Ports: []v1.ContainerPort{ - { - Name: "http-server", - ContainerPort: 80, - }, - }, - }, - }, - }, - } - var volumeMounts = make([]v1.VolumeMount, len(pvclaims)) - var volumes = make([]v1.Volume, len(pvclaims)) - for index, pvclaim := range pvclaims { - volumename := fmt.Sprintf("volume%v", index+1) - volumeMounts[index] = v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename} - volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}} - } - podSpec.Spec.Containers[0].VolumeMounts = volumeMounts - podSpec.Spec.Volumes = volumes - if nodeSelector != nil { - podSpec.Spec.NodeSelector = nodeSelector - } - return podSpec -} - // MakeSecPod returns a pod definition based on the namespace. The pod references the PVC's // name. A slice of BASH commands can be supplied as args to be run by the pod. // SELinux testing requires to pass HostIPC and HostPID as booleansi arguments. diff --git a/test/e2e/storage/flexvolume_online_resize.go b/test/e2e/storage/flexvolume_online_resize.go index 03bc07f874e..89e66b92f69 100644 --- a/test/e2e/storage/flexvolume_online_resize.go +++ b/test/e2e/storage/flexvolume_online_resize.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilerrors "k8s.io/apimachinery/pkg/util/errors" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" @@ -149,7 +150,7 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa var pod *v1.Pod ginkgo.By("Creating pod") - pod, err = e2epod.CreateNginxPod(c, ns, nodeKeyValueLabel, pvcClaims) + pod, err = createNginxPod(c, ns, nodeKeyValueLabel, pvcClaims) framework.ExpectNoError(err, "Failed to create pod %v", err) defer e2epod.DeletePodWithWait(c, pod) @@ -181,3 +182,64 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa framework.ExpectEqual(len(pvcConditions), 0, "pvc should not have conditions") }) }) + +// createNginxPod creates an nginx pod. +func createNginxPod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) (*v1.Pod, error) { + pod := makeNginxPod(namespace, nodeSelector, pvclaims) + pod, err := client.CoreV1().Pods(namespace).Create(pod) + if err != nil { + return nil, fmt.Errorf("pod Create API error: %v", err) + } + // Waiting for pod to be running + err = e2epod.WaitForPodNameRunningInNamespace(client, pod.Name, namespace) + if err != nil { + return pod, fmt.Errorf("pod %q is not Running: %v", pod.Name, err) + } + // get fresh pod info + pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{}) + if err != nil { + return pod, fmt.Errorf("pod Get API error: %v", err) + } + return pod, nil +} + +// makeNginxPod returns a pod definition based on the namespace using nginx image +func makeNginxPod(ns string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) *v1.Pod { + podSpec := &v1.Pod{ + TypeMeta: metav1.TypeMeta{ + Kind: "Pod", + APIVersion: "v1", + }, + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "pvc-tester-", + Namespace: ns, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "write-pod", + Image: "nginx", + Ports: []v1.ContainerPort{ + { + Name: "http-server", + ContainerPort: 80, + }, + }, + }, + }, + }, + } + var volumeMounts = make([]v1.VolumeMount, len(pvclaims)) + var volumes = make([]v1.Volume, len(pvclaims)) + for index, pvclaim := range pvclaims { + volumename := fmt.Sprintf("volume%v", index+1) + volumeMounts[index] = v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename} + volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}} + } + podSpec.Spec.Containers[0].VolumeMounts = volumeMounts + podSpec.Spec.Volumes = volumes + if nodeSelector != nil { + podSpec.Spec.NodeSelector = nodeSelector + } + return podSpec +}