mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #104650 from yxxhero/initcontainer_oomkiil_as_a_failure
fix init container oomkilled as a failure
This commit is contained in:
commit
463802765d
@ -139,9 +139,16 @@ func (m *kubeGenericRuntimeManager) getImageUser(image string) (*int64, string,
|
||||
return new(int64), "", nil
|
||||
}
|
||||
|
||||
// isInitContainerFailed returns true if container has exited and exitcode is not zero
|
||||
// or is in unknown state.
|
||||
// isInitContainerFailed returns true under the following conditions:
|
||||
// 1. container has exited and exitcode is not zero.
|
||||
// 2. container is in unknown state.
|
||||
// 3. container gets OOMKilled.
|
||||
func isInitContainerFailed(status *kubecontainer.Status) bool {
|
||||
// When oomkilled occurs, init container should be considered as a failure.
|
||||
if status.Reason == "OOMKilled" {
|
||||
return true
|
||||
}
|
||||
|
||||
if status.State == kubecontainer.ContainerStateExited && status.ExitCode != 0 {
|
||||
return true
|
||||
}
|
||||
|
@ -39,6 +39,64 @@ func seccompLocalhostPath(profileName string) string {
|
||||
return "localhost/" + seccompLocalhostRef(profileName)
|
||||
}
|
||||
|
||||
func TestIsInitContainerFailed(t *testing.T) {
|
||||
tests := []struct {
|
||||
status *kubecontainer.Status
|
||||
isFailed bool
|
||||
description string
|
||||
}{
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateExited,
|
||||
ExitCode: 1,
|
||||
},
|
||||
isFailed: true,
|
||||
description: "Init container in exited state and non-zero exit code should return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
},
|
||||
isFailed: true,
|
||||
description: "Init container in unknown state should return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
Reason: "OOMKilled",
|
||||
ExitCode: 0,
|
||||
},
|
||||
isFailed: true,
|
||||
description: "Init container which reason is OOMKilled should return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateExited,
|
||||
ExitCode: 0,
|
||||
},
|
||||
isFailed: false,
|
||||
description: "Init container in exited state and zero exit code should return false",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateRunning,
|
||||
},
|
||||
isFailed: false,
|
||||
description: "Init container in running state should return false",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateCreated,
|
||||
},
|
||||
isFailed: false,
|
||||
description: "Init container in created state should return false",
|
||||
},
|
||||
}
|
||||
for i, test := range tests {
|
||||
isFailed := isInitContainerFailed(test.status)
|
||||
assert.Equal(t, test.isFailed, isFailed, "TestCase[%d]: %s", i, test.description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStableKey(t *testing.T) {
|
||||
container := &v1.Container{
|
||||
Name: "test_container",
|
||||
|
Loading…
Reference in New Issue
Block a user