mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #84025 from oomichi/move-CreateNginxPod
Move CreateNginxPod() to specific e2e
This commit is contained in:
		@@ -112,26 +112,6 @@ func CreatePod(client clientset.Interface, namespace string, nodeSelector map[st
 | 
				
			|||||||
	return pod, nil
 | 
						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
 | 
					// 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) {
 | 
					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)
 | 
						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
 | 
						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
 | 
					// 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.
 | 
					// 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.
 | 
					// SELinux testing requires to pass HostIPC and HostPID as booleansi arguments.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,7 @@ import (
 | 
				
			|||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	storagev1 "k8s.io/api/storage/v1"
 | 
						storagev1 "k8s.io/api/storage/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/api/resource"
 | 
						"k8s.io/apimachinery/pkg/api/resource"
 | 
				
			||||||
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	utilerrors "k8s.io/apimachinery/pkg/util/errors"
 | 
						utilerrors "k8s.io/apimachinery/pkg/util/errors"
 | 
				
			||||||
	clientset "k8s.io/client-go/kubernetes"
 | 
						clientset "k8s.io/client-go/kubernetes"
 | 
				
			||||||
	"k8s.io/kubernetes/test/e2e/framework"
 | 
						"k8s.io/kubernetes/test/e2e/framework"
 | 
				
			||||||
@@ -149,7 +150,7 @@ var _ = utils.SIGDescribe("Mounted flexvolume volume expand [Slow] [Feature:Expa
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		var pod *v1.Pod
 | 
							var pod *v1.Pod
 | 
				
			||||||
		ginkgo.By("Creating 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)
 | 
							framework.ExpectNoError(err, "Failed to create pod %v", err)
 | 
				
			||||||
		defer e2epod.DeletePodWithWait(c, pod)
 | 
							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")
 | 
							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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user