diff --git a/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go b/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go index f473b2d6330d6fc9d6eff6d7de4ff79e0916b587..34768c12610628ebee5d00a1177353c4e1b80c17 100644 --- a/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go +++ b/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go @@ -152,7 +152,7 @@ func (s *Snapshot) RemovePodOwnedClaims(pod *apiv1.Pod) { for _, claim := range claims { claimId := GetClaimId(claim) - if drautils.PodOwnsClaim(pod, claim) { + if err := resourceclaim.IsForPod(pod, claim); err == nil { s.resourceClaims.DeleteCurrent(claimId) continue } @@ -201,7 +201,7 @@ func (s *Snapshot) UnreservePodClaims(pod *apiv1.Pod) error { claimId := GetClaimId(claim) claim := s.ensureClaimWritable(claim) drautils.ClearPodReservationInPlace(claim, pod) - if drautils.PodOwnsClaim(pod, claim) || !drautils.ClaimInUse(claim) { + if err := resourceclaim.IsForPod(pod, claim); err == nil || !drautils.ClaimInUse(claim) { drautils.DeallocateClaimInPlace(claim) } diff --git a/cluster-autoscaler/simulator/dynamicresources/utils/resource_claims.go b/cluster-autoscaler/simulator/dynamicresources/utils/resource_claims.go index 58481b673f262e5ad4dce964dc44371c55b10a74..68d029b5b160b59f41be0d9bfc3bfac1979f8c91 100644 --- a/cluster-autoscaler/simulator/dynamicresources/utils/resource_claims.go +++ b/cluster-autoscaler/simulator/dynamicresources/utils/resource_claims.go @@ -22,29 +22,10 @@ import ( apiv1 "k8s.io/api/core/v1" resourceapi "k8s.io/api/resource/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" "k8s.io/component-helpers/scheduling/corev1" "k8s.io/dynamic-resource-allocation/resourceclaim" - "k8s.io/utils/ptr" ) -// ClaimOwningPod returns the name and UID of the Pod owner of the provided claim. If the claim isn't -// owned by a Pod, empty strings are returned. -func ClaimOwningPod(claim *resourceapi.ResourceClaim) (string, types.UID) { - for _, owner := range claim.OwnerReferences { - if ptr.Deref(owner.Controller, false) && owner.APIVersion == "v1" && owner.Kind == "Pod" { - return owner.Name, owner.UID - } - } - return "", "" -} - -// PodOwnsClaim determines if the provided pod is the controller of the given claim. -func PodOwnsClaim(pod *apiv1.Pod, claim *resourceapi.ResourceClaim) bool { - ownerPodName, ownerPodUid := ClaimOwningPod(claim) - return ownerPodName == pod.Name && ownerPodUid == pod.UID -} - // ClaimAllocated returns whether the provided claim is allocated. func ClaimAllocated(claim *resourceapi.ResourceClaim) bool { return claim.Status.Allocation != nil