Skip to content
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
29 changes: 5 additions & 24 deletions internal/scheduling/reservations/commitments/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,18 @@ func (r *CommitmentReservationController) getPipelineForFlavorGroup(flavorGroupN
func (r *CommitmentReservationController) hypervisorToReservations(ctx context.Context, obj client.Object) []reconcile.Request {
hvName := obj.GetName()
var reservationList v1alpha1.ReservationList
if err := r.List(ctx, &reservationList,
client.MatchingFields{indexReservationByStatusHost: hvName},
); err != nil {
if err := r.List(ctx, &reservationList); err != nil {
logf.FromContext(ctx).Error(err, "failed to list reservations for hypervisor", "hypervisor", hvName)
return nil
}
requests := make([]reconcile.Request, 0, len(reservationList.Items))
requests := make([]reconcile.Request, 0)
for _, res := range reservationList.Items {
if res.Spec.Type != v1alpha1.ReservationTypeCommittedResource {
continue
}
if res.Status.Host != hvName {
continue
}
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{Name: res.Name, Namespace: res.Namespace},
})
Expand Down Expand Up @@ -554,10 +555,6 @@ var commitmentReservationPredicate = predicate.Funcs{
},
}

// indexReservationByStatusHost is the field index key for Reservation.Status.Host.
// Used by the Hypervisor→Reservation mapper to efficiently look up reservations on a given host.
const indexReservationByStatusHost = ".status.host"

// SetupWithManager sets up the controller with the Manager.
func (r *CommitmentReservationController) SetupWithManager(mgr ctrl.Manager, mcl *multicluster.Client) error {
if err := mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
Expand All @@ -569,22 +566,6 @@ func (r *CommitmentReservationController) SetupWithManager(mgr ctrl.Manager, mcl
return err
}

// Index reservations by Status.Host so the HV mapper can do O(1) lookups.
if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&v1alpha1.Reservation{},
indexReservationByStatusHost,
func(obj client.Object) []string {
res := obj.(*v1alpha1.Reservation)
if res.Status.Host == "" {
return nil
}
return []string{res.Status.Host}
},
); err != nil {
return fmt.Errorf("failed to index reservations by status host: %w", err)
}

// Use WatchesMulticluster to watch Reservations across all configured clusters
// (home + remotes). This is required because Reservation CRDs may be stored
// in remote clusters, not just the home cluster. Without this, the controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,6 @@ func TestHypervisorToReservations(t *testing.T) {
WithScheme(scheme).
WithObjects(res1, res2, resOtherHost, resNoHost, resFailover).
WithStatusSubresource(&v1alpha1.Reservation{}).
WithIndex(&v1alpha1.Reservation{}, indexReservationByStatusHost, func(obj client.Object) []string {
res := obj.(*v1alpha1.Reservation)
if res.Status.Host == "" {
return nil
}
return []string{res.Status.Host}
}).
Build()

controller := &CommitmentReservationController{Client: k8sClient}
Expand Down
Loading