fix init container oomkilled as a failure
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
4fccfb1cd7
commit
afde4c8bc4
@ -142,6 +142,11 @@ func (m *kubeGenericRuntimeManager) getImageUser(image string) (*int64, string,
|
|||||||
// isInitContainerFailed returns true if container has exited and exitcode is not zero
|
// isInitContainerFailed returns true if container has exited and exitcode is not zero
|
||||||
// or is in unknown state.
|
// or is in unknown state.
|
||||||
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,56 @@ 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
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
State: kubecontainer.ContainerStateExited,
|
||||||
|
ExitCode: 1,
|
||||||
|
},
|
||||||
|
isFailed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
State: kubecontainer.ContainerStateUnknown,
|
||||||
|
},
|
||||||
|
isFailed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
Reason: "OOMKilled",
|
||||||
|
},
|
||||||
|
isFailed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
State: kubecontainer.ContainerStateExited,
|
||||||
|
ExitCode: 0,
|
||||||
|
},
|
||||||
|
isFailed: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
State: kubecontainer.ContainerStateRunning,
|
||||||
|
},
|
||||||
|
isFailed: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: &kubecontainer.Status{
|
||||||
|
State: kubecontainer.ContainerStateCreated,
|
||||||
|
},
|
||||||
|
isFailed: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for i, test := range tests {
|
||||||
|
isFailed := isInitContainerFailed(test.status)
|
||||||
|
assert.Equal(t, test.isFailed, isFailed, "TestCase[%d]", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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