Skip to content
Snippets Groups Projects
Unverified Commit c85f22f7 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub
Browse files

Merge pull request #7798 from omerap12/migrate-claimReservedForPod

migrate claimReservedForPod to use upstream IsReservedForPod
parents 6b55dc90 e02272a4
Branches
Tags
No related merge requests found
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
drautils "k8s.io/autoscaler/cluster-autoscaler/simulator/dynamicresources/utils" drautils "k8s.io/autoscaler/cluster-autoscaler/simulator/dynamicresources/utils"
"k8s.io/autoscaler/cluster-autoscaler/simulator/framework" "k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
resourceclaim "k8s.io/dynamic-resource-allocation/resourceclaim"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
) )
...@@ -194,7 +195,7 @@ func (s Snapshot) ReservePodClaims(pod *apiv1.Pod) error { ...@@ -194,7 +195,7 @@ func (s Snapshot) ReservePodClaims(pod *apiv1.Pod) error {
return err return err
} }
for _, claim := range claims { for _, claim := range claims {
if drautils.ClaimFullyReserved(claim) && !drautils.ClaimReservedForPod(claim, pod) { if drautils.ClaimFullyReserved(claim) && !resourceclaim.IsReservedForPod(pod, claim) {
return fmt.Errorf("claim %s/%s already has max number of reservations set, can't add more", claim.Namespace, claim.Name) return fmt.Errorf("claim %s/%s already has max number of reservations set, can't add more", claim.Namespace, claim.Name)
} }
} }
... ...
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/component-helpers/scheduling/corev1" "k8s.io/component-helpers/scheduling/corev1"
resourceclaim "k8s.io/dynamic-resource-allocation/resourceclaim"
"k8s.io/utils/ptr" "k8s.io/utils/ptr"
) )
...@@ -48,16 +49,6 @@ func ClaimInUse(claim *resourceapi.ResourceClaim) bool { ...@@ -48,16 +49,6 @@ func ClaimInUse(claim *resourceapi.ResourceClaim) bool {
return len(claim.Status.ReservedFor) > 0 return len(claim.Status.ReservedFor) > 0
} }
// ClaimReservedForPod returns whether the provided claim is currently reserved for the provided pod.
func ClaimReservedForPod(claim *resourceapi.ResourceClaim, pod *apiv1.Pod) bool {
for _, consumerRef := range claim.Status.ReservedFor {
if claimConsumerReferenceMatchesPod(pod, consumerRef) {
return true
}
}
return false
}
// ClaimFullyReserved returns whether the provided claim already has the maximum possible reservations // ClaimFullyReserved returns whether the provided claim already has the maximum possible reservations
// set, and no more can be added. // set, and no more can be added.
func ClaimFullyReserved(claim *resourceapi.ResourceClaim) bool { func ClaimFullyReserved(claim *resourceapi.ResourceClaim) bool {
...@@ -105,7 +96,7 @@ func ClearPodReservationInPlace(claim *resourceapi.ResourceClaim, pod *apiv1.Pod ...@@ -105,7 +96,7 @@ func ClearPodReservationInPlace(claim *resourceapi.ResourceClaim, pod *apiv1.Pod
// AddPodReservationInPlace adds a reservation for the provided pod to the provided Claim. It is a no-op // AddPodReservationInPlace adds a reservation for the provided pod to the provided Claim. It is a no-op
// if the claim is already reserved for the Pod. // if the claim is already reserved for the Pod.
func AddPodReservationInPlace(claim *resourceapi.ResourceClaim, pod *apiv1.Pod) { func AddPodReservationInPlace(claim *resourceapi.ResourceClaim, pod *apiv1.Pod) {
if !ClaimReservedForPod(claim, pod) { if !resourceclaim.IsReservedForPod(pod, claim) {
claim.Status.ReservedFor = append(claim.Status.ReservedFor, PodClaimConsumerReference(pod)) claim.Status.ReservedFor = append(claim.Status.ReservedFor, PodClaimConsumerReference(pod))
} }
} }
... ...
......
...@@ -241,67 +241,6 @@ func TestClaimInUse(t *testing.T) { ...@@ -241,67 +241,6 @@ func TestClaimInUse(t *testing.T) {
} }
} }
func TestClaimReservedForPod(t *testing.T) {
pod := &apiv1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "chosenPod", UID: "chosenPodUid"}}
for _, tc := range []struct {
testName string
claim *resourceapi.ResourceClaim
wantReserved bool
}{
{
testName: "claim with no reservations",
claim: &resourceapi.ResourceClaim{
ObjectMeta: metav1.ObjectMeta{Name: "claim", UID: "claimUid", Namespace: "default"},
Status: resourceapi.ResourceClaimStatus{},
},
wantReserved: false,
},
{
testName: "claim with some reservations, but none match the pod",
claim: &resourceapi.ResourceClaim{
ObjectMeta: metav1.ObjectMeta{Name: "claim", UID: "claimUid", Namespace: "default"},
Status: resourceapi.ResourceClaimStatus{
ReservedFor: []resourceapi.ResourceClaimConsumerReference{
{Resource: "pods", Name: "pod1", UID: "pod1Uid"},
{Resource: "pods", Name: "pod2", UID: "pod2Uid"},
{Resource: "somethingelses", Name: "somethingelse", UID: "somethingelseUid"},
{Resource: "pods", Name: "chosenPod", UID: "badUid"},
{Resource: "pods", Name: "badName", UID: "chosenPodUid"},
{Resource: "badResource", Name: "chosenPod", UID: "chosenPodUid"},
},
},
},
wantReserved: false,
},
{
testName: "claim with some reservations, one matches the pod",
claim: &resourceapi.ResourceClaim{
ObjectMeta: metav1.ObjectMeta{Name: "claim", UID: "claimUid", Namespace: "default"},
Status: resourceapi.ResourceClaimStatus{
ReservedFor: []resourceapi.ResourceClaimConsumerReference{
{Resource: "pods", Name: "pod1", UID: "pod1Uid"},
{Resource: "pods", Name: "pod2", UID: "pod2Uid"},
{Resource: "somethingelses", Name: "somethingelse", UID: "somethingelseUid"},
{Resource: "pods", Name: "chosenPod", UID: "badUid"},
{Resource: "pods", Name: "badName", UID: "chosenPodUid"},
{Resource: "badResource", Name: "chosenPod", UID: "chosenPodUid"},
{Resource: "pods", Name: "chosenPod", UID: "chosenPodUid"},
},
},
},
wantReserved: true,
},
} {
t.Run(tc.testName, func(t *testing.T) {
reserved := ClaimReservedForPod(tc.claim, pod)
if tc.wantReserved != reserved {
t.Errorf("ClaimReservedForPod(): unexpected result: want %v, got %v", tc.wantReserved, reserved)
}
})
}
}
func TestClaimFullyReserved(t *testing.T) { func TestClaimFullyReserved(t *testing.T) {
for _, tc := range []struct { for _, tc := range []struct {
testName string testName string
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment