mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +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
|
return new(int64), "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// isInitContainerFailed returns true if container has exited and exitcode is not zero
|
// isInitContainerFailed returns true under the following conditions:
|
||||||
// or is in unknown state.
|
// 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 {
|
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 {
|
if status.State == kubecontainer.ContainerStateExited && status.ExitCode != 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,64 @@ func seccompLocalhostPath(profileName string) string {
|
|||||||
return "localhost/" + seccompLocalhostRef(profileName)
|
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) {
|
func TestStableKey(t *testing.T) {
|
||||||
container := &v1.Container{
|
container := &v1.Container{
|
||||||
Name: "test_container",
|
Name: "test_container",
|
||||||
|
Loading…
Reference in New Issue
Block a user