From d1ba893ad8e732bf8bbeb1e0029fe2335649d480 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 22 Jun 2023 11:21:37 +0200 Subject: [PATCH] dra resourceclaim controller: refactor isPodDone This covers pods that get deleted before running and will be used more than once soon. --- pkg/controller/resourceclaim/controller.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/controller/resourceclaim/controller.go b/pkg/controller/resourceclaim/controller.go index 3e06237ce48..58b19a19b7a 100644 --- a/pkg/controller/resourceclaim/controller.go +++ b/pkg/controller/resourceclaim/controller.go @@ -167,10 +167,7 @@ func (ec *Controller) enqueuePod(obj interface{}, deleted bool) { } // Release reservations of a deleted or completed pod? - if deleted || - podutil.IsPodTerminal(pod) || - // Deleted and not scheduled: - pod.DeletionTimestamp != nil && pod.Spec.NodeName == "" { + if deleted || isPodDone(pod) { for _, podClaim := range pod.Spec.ResourceClaims { claimName := resourceclaim.Name(pod, &podClaim) ec.queue.Add(claimKeyPrefix + pod.Namespace + "/" + claimName) @@ -481,3 +478,10 @@ func podResourceClaimIndexFunc(obj interface{}) ([]string, error) { } return keys, nil } + +// isPodDone returns true if it is certain that none of the containers are running and never will run. +func isPodDone(pod *v1.Pod) bool { + return podutil.IsPodPhaseTerminal(pod.Status.Phase) || + // Deleted and not scheduled: + pod.DeletionTimestamp != nil && pod.Spec.NodeName == "" +}