Skip to content

Commit cedacc9

Browse files
authored
Merge pull request kubernetes#84025 from oomichi/move-CreateNginxPod
Move CreateNginxPod() to specific e2e
2 parents 1dc5235 + 9e17a0e commit cedacc9

File tree

2 files changed

+63
-62
lines changed

2 files changed

+63
-62
lines changed

test/e2e/framework/pod/create.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,6 @@ func CreatePod(client clientset.Interface, namespace string, nodeSelector map[st
112112
return pod, nil
113113
}
114114

115-
// CreateNginxPod creates an enginx pod.
116-
func CreateNginxPod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) (*v1.Pod, error) {
117-
pod := makeNginxPod(namespace, nodeSelector, pvclaims)
118-
pod, err := client.CoreV1().Pods(namespace).Create(pod)
119-
if err != nil {
120-
return nil, fmt.Errorf("pod Create API error: %v", err)
121-
}
122-
// Waiting for pod to be running
123-
err = WaitForPodNameRunningInNamespace(client, pod.Name, namespace)
124-
if err != nil {
125-
return pod, fmt.Errorf("pod %q is not Running: %v", pod.Name, err)
126-
}
127-
// get fresh pod info
128-
pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{})
129-
if err != nil {
130-
return pod, fmt.Errorf("pod Get API error: %v", err)
131-
}
132-
return pod, nil
133-
}
134-
135115
// CreateSecPod creates security pod with given claims
136116
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) {
137117
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
208188
return podSpec
209189
}
210190

211-
// makeNginxPod returns a pod definition based on the namespace using nginx image
212-
func makeNginxPod(ns string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) *v1.Pod {
213-
podSpec := &v1.Pod{
214-
TypeMeta: metav1.TypeMeta{
215-
Kind: "Pod",
216-
APIVersion: "v1",
217-
},
218-
ObjectMeta: metav1.ObjectMeta{
219-
GenerateName: "pvc-tester-",
220-
Namespace: ns,
221-
},
222-
Spec: v1.PodSpec{
223-
Containers: []v1.Container{
224-
{
225-
Name: "write-pod",
226-
Image: "nginx",
227-
Ports: []v1.ContainerPort{
228-
{
229-
Name: "http-server",
230-
ContainerPort: 80,
231-
},
232-
},
233-
},
234-
},
235-
},
236-
}
237-
var volumeMounts = make([]v1.VolumeMount, len(pvclaims))
238-
var volumes = make([]v1.Volume, len(pvclaims))
239-
for index, pvclaim := range pvclaims {
240-
volumename := fmt.Sprintf("volume%v", index+1)
241-
volumeMounts[index] = v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename}
242-
volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}}
243-
}
244-
podSpec.Spec.Containers[0].VolumeMounts = volumeMounts
245-
podSpec.Spec.Volumes = volumes
246-
if nodeSelector != nil {
247-
podSpec.Spec.NodeSelector = nodeSelector
248-
}
249-
return podSpec
250-
}
251-
252191
// MakeSecPod returns a pod definition based on the namespace. The pod references the PVC's
253192
// name. A slice of BASH commands can be supplied as args to be run by the pod.
254193
// SELinux testing requires to pass HostIPC and HostPID as booleansi arguments.

test/e2e/storage/flexvolume_online_resize.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
v1 "k8s.io/api/core/v1"
2626
storagev1 "k8s.io/api/storage/v1"
2727
"k8s.io/apimachinery/pkg/api/resource"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2930
clientset "k8s.io/client-go/kubernetes"
3031
"k8s.io/kubernetes/test/e2e/framework"
@@ -149,7 +150,7 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa
149150

150151
var pod *v1.Pod
151152
ginkgo.By("Creating pod")
152-
pod, err = e2epod.CreateNginxPod(c, ns, nodeKeyValueLabel, pvcClaims)
153+
pod, err = createNginxPod(c, ns, nodeKeyValueLabel, pvcClaims)
153154
framework.ExpectNoError(err, "Failed to create pod %v", err)
154155
defer e2epod.DeletePodWithWait(c, pod)
155156

@@ -181,3 +182,64 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa
181182
framework.ExpectEqual(len(pvcConditions), 0, "pvc should not have conditions")
182183
})
183184
})
185+
186+
// createNginxPod creates an nginx pod.
187+
func createNginxPod(client clientset.Interface, namespace string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) (*v1.Pod, error) {
188+
pod := makeNginxPod(namespace, nodeSelector, pvclaims)
189+
pod, err := client.CoreV1().Pods(namespace).Create(pod)
190+
if err != nil {
191+
return nil, fmt.Errorf("pod Create API error: %v", err)
192+
}
193+
// Waiting for pod to be running
194+
err = e2epod.WaitForPodNameRunningInNamespace(client, pod.Name, namespace)
195+
if err != nil {
196+
return pod, fmt.Errorf("pod %q is not Running: %v", pod.Name, err)
197+
}
198+
// get fresh pod info
199+
pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{})
200+
if err != nil {
201+
return pod, fmt.Errorf("pod Get API error: %v", err)
202+
}
203+
return pod, nil
204+
}
205+
206+
// makeNginxPod returns a pod definition based on the namespace using nginx image
207+
func makeNginxPod(ns string, nodeSelector map[string]string, pvclaims []*v1.PersistentVolumeClaim) *v1.Pod {
208+
podSpec := &v1.Pod{
209+
TypeMeta: metav1.TypeMeta{
210+
Kind: "Pod",
211+
APIVersion: "v1",
212+
},
213+
ObjectMeta: metav1.ObjectMeta{
214+
GenerateName: "pvc-tester-",
215+
Namespace: ns,
216+
},
217+
Spec: v1.PodSpec{
218+
Containers: []v1.Container{
219+
{
220+
Name: "write-pod",
221+
Image: "nginx",
222+
Ports: []v1.ContainerPort{
223+
{
224+
Name: "http-server",
225+
ContainerPort: 80,
226+
},
227+
},
228+
},
229+
},
230+
},
231+
}
232+
var volumeMounts = make([]v1.VolumeMount, len(pvclaims))
233+
var volumes = make([]v1.Volume, len(pvclaims))
234+
for index, pvclaim := range pvclaims {
235+
volumename := fmt.Sprintf("volume%v", index+1)
236+
volumeMounts[index] = v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename}
237+
volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}}
238+
}
239+
podSpec.Spec.Containers[0].VolumeMounts = volumeMounts
240+
podSpec.Spec.Volumes = volumes
241+
if nodeSelector != nil {
242+
podSpec.Spec.NodeSelector = nodeSelector
243+
}
244+
return podSpec
245+
}

0 commit comments

Comments
 (0)