diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts.go index 835422b38b..946e137b9f 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts.go @@ -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 } diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 45dfd9d56a..075d0b2f09 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -270,6 +270,24 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { } }, }, + { + description: "pods pending with initContainer with states=CrashLoopBackOff, 1 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, + 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 {