mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #87266 from claudiubelu/tests/agnhost-usage-refactor
tests: Refactor agnhost image pod usage
This commit is contained in:
commit
3783e03dc9
@ -409,23 +409,21 @@ func isNotRestartAlwaysMirrorPod(p *v1.Pod) bool {
|
|||||||
return p.Spec.RestartPolicy != v1.RestartPolicyAlways
|
return p.Spec.RestartPolicy != v1.RestartPolicyAlways
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExecPodSpec returns the pod spec of hostexec pod
|
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
|
||||||
func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod {
|
// that behave the same, no matter the underlying OS. If no args are given, it defaults to the pause subcommand.
|
||||||
|
// For more information about agnhost subcommands, see: https://github.com/kubernetes/kubernetes/tree/master/test/images/agnhost#agnhost
|
||||||
|
func NewAgnhostPod(ns, podName string, volumes []v1.Volume, mounts []v1.VolumeMount, ports []v1.ContainerPort, args ...string) *v1.Pod {
|
||||||
immediate := int64(0)
|
immediate := int64(0)
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: podName,
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
NewAgnhostContainer("agnhost-container", mounts, ports, args...),
|
||||||
Name: "agnhost",
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
|
||||||
ImagePullPolicy: v1.PullIfNotPresent,
|
|
||||||
},
|
},
|
||||||
},
|
Volumes: volumes,
|
||||||
HostNetwork: hostNetwork,
|
|
||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &immediate,
|
TerminationGracePeriodSeconds: &immediate,
|
||||||
},
|
},
|
||||||
@ -433,25 +431,33 @@ func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod {
|
|||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAgnhostContainer returns the container Spec of an agnhost container.
|
||||||
|
func NewAgnhostContainer(containerName string, mounts []v1.VolumeMount, ports []v1.ContainerPort, args ...string) v1.Container {
|
||||||
|
if len(args) == 0 {
|
||||||
|
args = []string{"pause"}
|
||||||
|
}
|
||||||
|
return v1.Container{
|
||||||
|
Name: containerName,
|
||||||
|
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
||||||
|
Args: args,
|
||||||
|
VolumeMounts: mounts,
|
||||||
|
Ports: ports,
|
||||||
|
SecurityContext: &v1.SecurityContext{},
|
||||||
|
ImagePullPolicy: v1.PullIfNotPresent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewExecPodSpec returns the pod spec of hostexec pod
|
||||||
|
func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod {
|
||||||
|
pod := NewAgnhostPod(ns, name, nil, nil, nil)
|
||||||
|
pod.Spec.HostNetwork = hostNetwork
|
||||||
|
return pod
|
||||||
|
}
|
||||||
|
|
||||||
// newExecPodSpec returns the pod spec of exec pod
|
// newExecPodSpec returns the pod spec of exec pod
|
||||||
func newExecPodSpec(ns, generateName string) *v1.Pod {
|
func newExecPodSpec(ns, generateName string) *v1.Pod {
|
||||||
immediate := int64(0)
|
pod := NewAgnhostPod(ns, "agnhost-pod", nil, nil, nil)
|
||||||
pod := &v1.Pod{
|
pod.ObjectMeta.GenerateName = generateName
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
GenerateName: generateName,
|
|
||||||
Namespace: ns,
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
TerminationGracePeriodSeconds: &immediate,
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: "agnhost-pause",
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
|
||||||
Args: []string{"pause"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user