From f03a67ed81a502598b3896ae8d4eac1a58def7f3 Mon Sep 17 00:00:00 2001
From: Maksym Fuhol <mfuhol@google.com>
Date: Mon, 9 Jun 2025 15:45:13 +0000
Subject: [PATCH] Migrate DraSnapshot off PodOwnsClaim/ClaimOwningPod to DRA
 API IsForPod

---
 .../dynamicresources/snapshot/snapshot.go     |  4 ++--
 .../dynamicresources/utils/resource_claims.go | 19 -------------------
 2 files changed, 2 insertions(+), 21 deletions(-)

diff --git a/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go b/cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go
index f473b2d633..34768c1261 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 58481b673f..68d029b5b1 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
-- 
GitLab