Skip to content

Commit f03a67e

Browse files
committed
Migrate DraSnapshot off PodOwnsClaim/ClaimOwningPod to DRA API IsForPod
1 parent 0912f9b commit f03a67e

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

cluster-autoscaler/simulator/dynamicresources/snapshot/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (s *Snapshot) RemovePodOwnedClaims(pod *apiv1.Pod) {
152152

153153
for _, claim := range claims {
154154
claimId := GetClaimId(claim)
155-
if drautils.PodOwnsClaim(pod, claim) {
155+
if err := resourceclaim.IsForPod(pod, claim); err == nil {
156156
s.resourceClaims.DeleteCurrent(claimId)
157157
continue
158158
}
@@ -201,7 +201,7 @@ func (s *Snapshot) UnreservePodClaims(pod *apiv1.Pod) error {
201201
claimId := GetClaimId(claim)
202202
claim := s.ensureClaimWritable(claim)
203203
drautils.ClearPodReservationInPlace(claim, pod)
204-
if drautils.PodOwnsClaim(pod, claim) || !drautils.ClaimInUse(claim) {
204+
if err := resourceclaim.IsForPod(pod, claim); err == nil || !drautils.ClaimInUse(claim) {
205205
drautils.DeallocateClaimInPlace(claim)
206206
}
207207

cluster-autoscaler/simulator/dynamicresources/utils/resource_claims.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,10 @@ import (
2222
apiv1 "k8s.io/api/core/v1"
2323
resourceapi "k8s.io/api/resource/v1beta1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"k8s.io/apimachinery/pkg/types"
2625
"k8s.io/component-helpers/scheduling/corev1"
2726
"k8s.io/dynamic-resource-allocation/resourceclaim"
28-
"k8s.io/utils/ptr"
2927
)
3028

31-
// ClaimOwningPod returns the name and UID of the Pod owner of the provided claim. If the claim isn't
32-
// owned by a Pod, empty strings are returned.
33-
func ClaimOwningPod(claim *resourceapi.ResourceClaim) (string, types.UID) {
34-
for _, owner := range claim.OwnerReferences {
35-
if ptr.Deref(owner.Controller, false) && owner.APIVersion == "v1" && owner.Kind == "Pod" {
36-
return owner.Name, owner.UID
37-
}
38-
}
39-
return "", ""
40-
}
41-
42-
// PodOwnsClaim determines if the provided pod is the controller of the given claim.
43-
func PodOwnsClaim(pod *apiv1.Pod, claim *resourceapi.ResourceClaim) bool {
44-
ownerPodName, ownerPodUid := ClaimOwningPod(claim)
45-
return ownerPodName == pod.Name && ownerPodUid == pod.UID
46-
}
47-
4829
// ClaimAllocated returns whether the provided claim is allocated.
4930
func ClaimAllocated(claim *resourceapi.ResourceClaim) bool {
5031
return claim.Status.Allocation != nil

0 commit comments

Comments
 (0)