dra resourceclaim controller: refactor isPodDone

This covers pods that get deleted before running and will be used more than
once soon.
This commit is contained in:
Patrick Ohly 2023-06-22 11:21:37 +02:00
parent bbc7ca94a4
commit d1ba893ad8

View File

@ -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 == ""
}