mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
tests: Refactors agnhost image pod usage in tests
A previous commit created a few agnhost related functions that creates agnhost pods / containers for general purposes. Refactors tests to use those functions.
This commit is contained in:
parent
131f42d263
commit
89eae73323
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user