mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Added oomkill test for init container and fix typos
This commit is contained in:
parent
4fa97eae1b
commit
b7cbebcd03
@ -41,12 +41,20 @@ var _ = SIGDescribe("OOMKiller [LinuxOnly] [NodeConformance]", func() {
|
||||
f := framework.NewDefaultFramework("oomkiller-test")
|
||||
f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
|
||||
|
||||
testCases := []testCase{{
|
||||
name: "single process container",
|
||||
oomTargetContainerName: "oomkill-single-target-container",
|
||||
podSpec: getOOMTargetPod("oomkill-target-pod", "oomkill-single-target-container",
|
||||
getOOMTargetContainer),
|
||||
}}
|
||||
testCases := []testCase{
|
||||
{
|
||||
name: "single process container",
|
||||
oomTargetContainerName: "oomkill-single-target-container",
|
||||
podSpec: getOOMTargetPod("oomkill-target-pod", "oomkill-single-target-container",
|
||||
getOOMTargetContainer),
|
||||
},
|
||||
{
|
||||
name: "init container",
|
||||
oomTargetContainerName: "oomkill-target-init-container",
|
||||
podSpec: getInitContainerOOMTargetPod("initcontinar-oomkill-target-pod", "oomkill-target-init-container",
|
||||
getOOMTargetContainer),
|
||||
},
|
||||
}
|
||||
|
||||
// If using cgroup v2, we set memory.oom.group=1 for the container cgroup so that any process which gets OOM killed
|
||||
// in the process, causes all processes in the container to get OOM killed
|
||||
@ -118,6 +126,26 @@ func getOOMTargetPod(podName string, ctnName string, createContainer func(name s
|
||||
}
|
||||
}
|
||||
|
||||
func getInitContainerOOMTargetPod(podName string, ctnName string, createContainer func(name string) v1.Container) *v1.Pod {
|
||||
return &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: podName,
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
InitContainers: []v1.Container{
|
||||
createContainer(ctnName),
|
||||
},
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "busybox",
|
||||
Image: busyboxImage,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// getOOMTargetContainer returns a container with a single process, which attempts to allocate more memory than is
|
||||
// allowed by the container memory limit.
|
||||
func getOOMTargetContainer(name string) v1.Container {
|
||||
|
@ -109,13 +109,13 @@ func getSigkillTargetPod(podName string, ctnName string) *v1.Pod {
|
||||
Image: busyboxImage,
|
||||
// In the main container, SIGTERM was trapped and later /tmp/healthy
|
||||
// will be created for readiness probe to verify if the trap was
|
||||
// excucuted successfully
|
||||
// executed successfully
|
||||
Command: []string{
|
||||
"sh",
|
||||
"-c",
|
||||
"trap \"echo SIGTERM caught\" SIGTERM SIGINT; touch /tmp/healthy; sleep 1000",
|
||||
},
|
||||
// Using readinessprobe to guarantee signal handler registering finished
|
||||
// Using readiness probe to guarantee signal handler registering finished
|
||||
ReadinessProbe: &v1.Probe{
|
||||
InitialDelaySeconds: 1,
|
||||
TimeoutSeconds: 2,
|
||||
|
Loading…
Reference in New Issue
Block a user