Skip to content

Commit

Permalink
Merge pull request #1348 from a7i/amir/toomanyrestarts-initcontainer
Browse files Browse the repository at this point in the history
fix: `RemovePodsHavingTooManyRestarts` to include `InitContainerStatuses`
  • Loading branch information
k8s-ci-robot authored Feb 7, 2024
2 parents af1ffe7 + 97c0044 commit 6c865fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
return true
}

for _, containerStatus := range pod.Status.ContainerStatuses {
containerStatuses := pod.Status.ContainerStatuses

if tooManyRestartsArgs.IncludingInitContainers {
containerStatuses = append(containerStatuses, pod.Status.InitContainerStatuses...)
}

for _, containerStatus := range containerStatuses {
if containerStatus.State.Waiting != nil && states.Has(containerStatus.State.Waiting.Reason) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,42 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) {
}
},
},
{
description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=true), 3 pod evictions",
args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: true},
nodes: []*v1.Node{node1},
expectedEvictedPodCount: 3,
maxPodsToEvictPerNode: &uint3,
applyFunc: func(pods []*v1.Pod) {
for _, pod := range pods {
pod.Status.InitContainerStatuses = []v1.ContainerStatus{
{
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"},
},
},
}
}
},
},
{
description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=false), 0 pod evictions",
args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: false},
nodes: []*v1.Node{node1},
expectedEvictedPodCount: 0,
maxPodsToEvictPerNode: &uint3,
applyFunc: func(pods []*v1.Pod) {
for _, pod := range pods {
pod.Status.InitContainerStatuses = []v1.ContainerStatus{
{
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"},
},
},
}
}
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 6c865fd

Please sign in to comment.