mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-08-23 22:46:35 +00:00
Extract shared container state matching helpers into podutil
Move container waiting/terminated state checking from PodLifeTime and RemovePodsHavingTooManyRestarts into podutil as separate exported helpers: HasMatchingContainerWaitingState and HasMatchingContainerTerminatedState. Each plugin composes only the helpers it needs.
This commit is contained in:
@@ -84,19 +84,13 @@ func New(ctx context.Context, args runtime.Object, handle frameworktypes.Handle)
|
||||
if states.Has(string(pod.Status.Phase)) {
|
||||
return true
|
||||
}
|
||||
|
||||
containerStatuses := pod.Status.ContainerStatuses
|
||||
|
||||
if tooManyRestartsArgs.IncludingInitContainers {
|
||||
containerStatuses = append(containerStatuses, pod.Status.InitContainerStatuses...)
|
||||
if podutil.HasMatchingContainerWaitingState(pod.Status.ContainerStatuses, states) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, containerStatus := range containerStatuses {
|
||||
if containerStatus.State.Waiting != nil && states.Has(containerStatus.State.Waiting.Reason) {
|
||||
return true
|
||||
}
|
||||
if tooManyRestartsArgs.IncludingInitContainers &&
|
||||
podutil.HasMatchingContainerWaitingState(pod.Status.InitContainerStatuses, states) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user