update func description
This commit is contained in:
parent
afde4c8bc4
commit
71a91d55cb
@ -139,8 +139,10 @@ 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 in unknown state.
|
||||
// 3. container occurs OOMKilled.
|
||||
func isInitContainerFailed(status *kubecontainer.Status) bool {
|
||||
// When oomkilled occurs, init container should be considered as a failure.
|
||||
if status.Reason == "OOMKilled" {
|
||||
|
@ -41,51 +41,59 @@ func seccompLocalhostPath(profileName string) string {
|
||||
|
||||
func TestIsInitContainerFailed(t *testing.T) {
|
||||
tests := []struct {
|
||||
status *kubecontainer.Status
|
||||
isFailed bool
|
||||
status *kubecontainer.Status
|
||||
isFailed bool
|
||||
description string
|
||||
}{
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateExited,
|
||||
ExitCode: 1,
|
||||
},
|
||||
isFailed: true,
|
||||
isFailed: true,
|
||||
description: "Init container which state is exited and exitcode is non-zero shoud return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateUnknown,
|
||||
},
|
||||
isFailed: true,
|
||||
isFailed: true,
|
||||
description: "Init container which state is unknown should return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
Reason: "OOMKilled",
|
||||
Reason: "OOMKilled",
|
||||
ExitCode: 0,
|
||||
},
|
||||
isFailed: true,
|
||||
isFailed: true,
|
||||
description: "Init container which state is exited and exitcode is zero shoud return true",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateExited,
|
||||
ExitCode: 0,
|
||||
},
|
||||
isFailed: false,
|
||||
isFailed: false,
|
||||
description: "Init container which state is exited and exitcode is zero shoud return false",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateRunning,
|
||||
},
|
||||
isFailed: false,
|
||||
isFailed: false,
|
||||
description: "Init container which state is running should return false",
|
||||
},
|
||||
{
|
||||
status: &kubecontainer.Status{
|
||||
State: kubecontainer.ContainerStateCreated,
|
||||
},
|
||||
isFailed: false,
|
||||
isFailed: false,
|
||||
description: "Init container which state is created should return false",
|
||||
},
|
||||
}
|
||||
for i, test := range tests {
|
||||
isFailed := isInitContainerFailed(test.status)
|
||||
assert.Equal(t, test.isFailed, isFailed, "TestCase[%d]", i)
|
||||
assert.Equal(t, test.isFailed, isFailed, "TestCase[%d]: %s", i, test.description)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user