Added oomkill test for init container and fix typos

This commit is contained in:
CoderSherlock 2023-07-10 18:18:30 +00:00
parent 4fa97eae1b
commit b7cbebcd03
2 changed files with 36 additions and 8 deletions

View File

@ -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 {

View File

@ -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,