Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: update resourceNames of ReservationInfo #1930

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions pkg/scheduler/frameworkext/reservation_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,51 @@ func (ri *ReservationInfo) Clone() *ReservationInfo {
}

func (ri *ReservationInfo) UpdateReservation(r *schedulingv1alpha1.Reservation) {
ri.Allocatable = reservationutil.ReservationRequests(r)
var parseErrors []error
resourceNames := quotav1.ResourceNames(ri.Allocatable)
if r.Spec.AllocatePolicy == schedulingv1alpha1.ReservationAllocatePolicyRestricted {
options, err := apiext.GetReservationRestrictedOptions(r.Annotations)
if err == nil {
resourceNames = reservationutil.GetReservationRestrictedResources(resourceNames, options)
} else {
parseErrors = append(parseErrors, err)
}
}
ri.ResourceNames = resourceNames

ri.Reservation = r
ri.Pod = reservationutil.NewReservePod(r)
ri.Allocatable = reservationutil.ReservationRequests(r)
ri.AllocatablePorts = util.RequestedHostPorts(ri.Pod)
ri.ResourceNames = quotav1.ResourceNames(ri.Allocatable)
ri.Allocated = quotav1.Mask(ri.Allocated, ri.ResourceNames)
ownerMatchers, err := reservationutil.ParseReservationOwnerMatchers(r.Spec.Owners)
if err != nil {
klog.ErrorS(err, "Failed to parse reservation owner matchers", "reservation", klog.KObj(r))
parseErrors = append(parseErrors, err)
}
ri.OwnerMatchers = ownerMatchers
ri.ParseError = err

var parseError error
if len(parseErrors) > 0 {
parseError = utilerrors.NewAggregate(parseErrors)
}
ri.ParseError = parseError
}

func (ri *ReservationInfo) UpdatePod(pod *corev1.Pod) {
ri.Pod = pod
ri.Allocatable, _ = resource.PodRequestsAndLimits(pod)
var parseErrors []error
resourceNames := quotav1.ResourceNames(ri.Allocatable)
options, err := apiext.GetReservationRestrictedOptions(pod.Annotations)
if err == nil {
resourceNames = reservationutil.GetReservationRestrictedResources(resourceNames, options)
} else {
parseErrors = append(parseErrors, err)
}
ri.ResourceNames = resourceNames

ri.Pod = pod
ri.AllocatablePorts = util.RequestedHostPorts(pod)
ri.ResourceNames = quotav1.ResourceNames(ri.Allocatable)
ri.Allocated = quotav1.Mask(ri.Allocated, ri.ResourceNames)

owners, err := apiext.GetReservationOwners(pod.Annotations)
Expand All @@ -338,10 +364,16 @@ func (ri *ReservationInfo) UpdatePod(pod *corev1.Pod) {
ownerMatchers, err = reservationutil.ParseReservationOwnerMatchers(owners)
if err != nil {
klog.ErrorS(err, "Failed to parse reservation owner matchers of pod", "pod", klog.KObj(pod))
parseErrors = append(parseErrors, err)
}
}
ri.OwnerMatchers = ownerMatchers
ri.ParseError = err

var parseError error
if len(parseErrors) > 0 {
parseError = utilerrors.NewAggregate(parseErrors)
}
ri.ParseError = parseError
}

func (ri *ReservationInfo) AddAssignedPod(pod *corev1.Pod) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/scheduler/frameworkext/reservation_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"

apiext "github.com/koordinator-sh/koordinator/apis/extension"
schedulingv1alpha1 "github.com/koordinator-sh/koordinator/apis/scheduling/v1alpha1"
Expand Down Expand Up @@ -459,7 +460,7 @@ func TestReservationInfoUpdateReservation(t *testing.T) {
},
},
})
return err
return utilerrors.NewAggregate([]error{err})
}(),
},
},
Expand Down Expand Up @@ -628,7 +629,7 @@ func TestReservationInfoUpdatePod(t *testing.T) {
},
},
})
return err
return utilerrors.NewAggregate([]error{err})
}(),
},
},
Expand Down
Loading