Skip to content

Commit 3783e03

Browse files
authored
Merge pull request kubernetes#87266 from claudiubelu/tests/agnhost-usage-refactor
tests: Refactor agnhost image pod usage
2 parents 796f9d8 + 1384921 commit 3783e03

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

test/e2e/framework/pod/resource.go

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -409,49 +409,55 @@ func isNotRestartAlwaysMirrorPod(p *v1.Pod) bool {
409409
return p.Spec.RestartPolicy != v1.RestartPolicyAlways
410410
}
411411

412-
// NewExecPodSpec returns the pod spec of hostexec pod
413-
func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod {
412+
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
413+
// that behave the same, no matter the underlying OS. If no args are given, it defaults to the pause subcommand.
414+
// For more information about agnhost subcommands, see: https://github.com/kubernetes/kubernetes/tree/master/test/images/agnhost#agnhost
415+
func NewAgnhostPod(ns, podName string, volumes []v1.Volume, mounts []v1.VolumeMount, ports []v1.ContainerPort, args ...string) *v1.Pod {
414416
immediate := int64(0)
415417
pod := &v1.Pod{
416418
ObjectMeta: metav1.ObjectMeta{
417-
Name: name,
419+
Name: podName,
418420
Namespace: ns,
419421
},
420422
Spec: v1.PodSpec{
421423
Containers: []v1.Container{
422-
{
423-
Name: "agnhost",
424-
Image: imageutils.GetE2EImage(imageutils.Agnhost),
425-
ImagePullPolicy: v1.PullIfNotPresent,
426-
},
424+
NewAgnhostContainer("agnhost-container", mounts, ports, args...),
427425
},
428-
HostNetwork: hostNetwork,
426+
Volumes: volumes,
429427
SecurityContext: &v1.PodSecurityContext{},
430428
TerminationGracePeriodSeconds: &immediate,
431429
},
432430
}
433431
return pod
434432
}
435433

434+
// NewAgnhostContainer returns the container Spec of an agnhost container.
435+
func NewAgnhostContainer(containerName string, mounts []v1.VolumeMount, ports []v1.ContainerPort, args ...string) v1.Container {
436+
if len(args) == 0 {
437+
args = []string{"pause"}
438+
}
439+
return v1.Container{
440+
Name: containerName,
441+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
442+
Args: args,
443+
VolumeMounts: mounts,
444+
Ports: ports,
445+
SecurityContext: &v1.SecurityContext{},
446+
ImagePullPolicy: v1.PullIfNotPresent,
447+
}
448+
}
449+
450+
// NewExecPodSpec returns the pod spec of hostexec pod
451+
func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod {
452+
pod := NewAgnhostPod(ns, name, nil, nil, nil)
453+
pod.Spec.HostNetwork = hostNetwork
454+
return pod
455+
}
456+
436457
// newExecPodSpec returns the pod spec of exec pod
437458
func newExecPodSpec(ns, generateName string) *v1.Pod {
438-
immediate := int64(0)
439-
pod := &v1.Pod{
440-
ObjectMeta: metav1.ObjectMeta{
441-
GenerateName: generateName,
442-
Namespace: ns,
443-
},
444-
Spec: v1.PodSpec{
445-
TerminationGracePeriodSeconds: &immediate,
446-
Containers: []v1.Container{
447-
{
448-
Name: "agnhost-pause",
449-
Image: imageutils.GetE2EImage(imageutils.Agnhost),
450-
Args: []string{"pause"},
451-
},
452-
},
453-
},
454-
}
459+
pod := NewAgnhostPod(ns, "agnhost-pod", nil, nil, nil)
460+
pod.ObjectMeta.GenerateName = generateName
455461
return pod
456462
}
457463

0 commit comments

Comments
 (0)