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
|
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 in unknown state.
|
||||||
|
// 3. container occurs OOMKilled.
|
||||||
func isInitContainerFailed(status *kubecontainer.Status) bool {
|
func isInitContainerFailed(status *kubecontainer.Status) bool {
|
||||||
// When oomkilled occurs, init container should be considered as a failure.
|
// When oomkilled occurs, init container should be considered as a failure.
|
||||||
if status.Reason == "OOMKilled" {
|
if status.Reason == "OOMKilled" {
|
||||||
|
@ -41,51 +41,59 @@ func seccompLocalhostPath(profileName string) string {
|
|||||||
|
|
||||||
func TestIsInitContainerFailed(t *testing.T) {
|
func TestIsInitContainerFailed(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
status *kubecontainer.Status
|
status *kubecontainer.Status
|
||||||
isFailed bool
|
isFailed bool
|
||||||
|
description string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
status: &kubecontainer.Status{
|
status: &kubecontainer.Status{
|
||||||
State: kubecontainer.ContainerStateExited,
|
State: kubecontainer.ContainerStateExited,
|
||||||
ExitCode: 1,
|
ExitCode: 1,
|
||||||
},
|
},
|
||||||
isFailed: true,
|
isFailed: true,
|
||||||
|
description: "Init container which state is exited and exitcode is non-zero shoud return true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: &kubecontainer.Status{
|
status: &kubecontainer.Status{
|
||||||
State: kubecontainer.ContainerStateUnknown,
|
State: kubecontainer.ContainerStateUnknown,
|
||||||
},
|
},
|
||||||
isFailed: true,
|
isFailed: true,
|
||||||
|
description: "Init container which state is unknown should return true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: &kubecontainer.Status{
|
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{
|
status: &kubecontainer.Status{
|
||||||
State: kubecontainer.ContainerStateExited,
|
State: kubecontainer.ContainerStateExited,
|
||||||
ExitCode: 0,
|
ExitCode: 0,
|
||||||
},
|
},
|
||||||
isFailed: false,
|
isFailed: false,
|
||||||
|
description: "Init container which state is exited and exitcode is zero shoud return false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: &kubecontainer.Status{
|
status: &kubecontainer.Status{
|
||||||
State: kubecontainer.ContainerStateRunning,
|
State: kubecontainer.ContainerStateRunning,
|
||||||
},
|
},
|
||||||
isFailed: false,
|
isFailed: false,
|
||||||
|
description: "Init container which state is running should return false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: &kubecontainer.Status{
|
status: &kubecontainer.Status{
|
||||||
State: kubecontainer.ContainerStateCreated,
|
State: kubecontainer.ContainerStateCreated,
|
||||||
},
|
},
|
||||||
isFailed: false,
|
isFailed: false,
|
||||||
|
description: "Init container which state is created should return false",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
isFailed := isInitContainerFailed(test.status)
|
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