Skip to content

Commit

Permalink
scheduler: fix reservation reserved updated
Browse files Browse the repository at this point in the history
Co-authored-by: shenxin <[email protected]>
Signed-off-by: saintube <[email protected]>
  • Loading branch information
saintube and shenxin committed Jan 17, 2025
1 parent 79036cf commit 3b18165
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/scheduler/frameworkext/reservation_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ func (ri *ReservationInfo) UpdateReservation(r *schedulingv1alpha1.Reservation)
if ri.Allocated != nil {
ri.Allocated = quotav1.Mask(ri.Allocated, ri.ResourceNames)
}
reserved := util.GetNodeReservationFromAnnotation(r.Annotations)
ri.Reserved = reserved

ownerMatchers, err := reservationutil.ParseReservationOwnerMatchers(r.Spec.Owners)
if err != nil {
klog.ErrorS(err, "Failed to parse reservation owner matchers", "reservation", klog.KObj(r))
Expand Down Expand Up @@ -407,6 +410,8 @@ func (ri *ReservationInfo) UpdatePod(pod *corev1.Pod) {
ri.Pod = pod
ri.AllocatablePorts = util.RequestedHostPorts(pod)
ri.Allocated = quotav1.Mask(ri.Allocated, ri.ResourceNames)
reserved := util.GetNodeReservationFromAnnotation(pod.Annotations)
ri.Reserved = reserved

owners, err := apiext.GetReservationOwners(pod.Annotations)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions pkg/scheduler/frameworkext/reservation_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,28 @@ func TestReservationInfoUpdateReservation(t *testing.T) {
ParseError: nil,
},
},
{
name: "reservation's reserved has changed",
reservation: reservation,
newReservation: func() *schedulingv1alpha1.Reservation {
r := reservation.DeepCopy()
if r.Annotations == nil {
r.Annotations = map[string]string{}
}
r.Annotations[apiext.AnnotationNodeReservation] = `{"resources": {"cpu": "1"}}`
return r
}(),
want: &ReservationInfo{
ResourceNames: []corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory},
Allocatable: allocatable.DeepCopy(),
Reserved: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("1"),
},
AssignedPods: map[types.UID]*PodRequirement{},
OwnerMatchers: ownerMatchers,
ParseError: nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3b18165

Please sign in to comment.