Skip to content

Commit

Permalink
Added admission checking on nominate
Browse files Browse the repository at this point in the history
  • Loading branch information
mcariatm committed Apr 4, 2023
1 parent f4bc8e1 commit 0bb02b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,20 @@ func (c *Cache) DeleteWorkload(w *kueue.Workload) error {
return nil
}

func (c *Cache) IsAssumedWorkload(w *kueue.Workload) bool {
func (c *Cache) IsAssumedOrAdmittedWorkload(w workload.Info) bool {
c.Lock()
defer c.Unlock()

k := workload.Key(w)
_, assumed := c.assumedWorkloads[k]
return assumed
k := workload.Key(w.Obj)
if _, assumed := c.assumedWorkloads[k]; assumed {
return true
}
if cq, exists := c.clusterQueues[w.ClusterQueue]; exists {
if _, admitted := cq.Workloads[k]; admitted {
return true
}
}
return false
}

func (c *Cache) AssumeWorkload(w *kueue.Workload) error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/core/clusterqueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (r *ClusterQueueReconciler) Reconcile(ctx context.Context, req ctrl.Request
func (r *ClusterQueueReconciler) NotifyWorkloadUpdate(oldWl, newWl *kueue.Workload) {
if oldWl != nil {
r.wlUpdateCh <- event.GenericEvent{Object: oldWl}
if newWl != nil && oldWl.Spec.QueueName != newWl.Spec.QueueName {
r.wlUpdateCh <- event.GenericEvent{Object: newWl}
return
}
}
if newWl != nil {
r.wlUpdateCh <- event.GenericEvent{Object: newWl}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *Scheduler) nominate(ctx context.Context, workloads []workload.Info, sna
cq := snap.ClusterQueues[w.ClusterQueue]
ns := corev1.Namespace{}
e := entry{Info: w}
if s.cache.IsAssumedWorkload(w.Obj) {
if s.cache.IsAssumedOrAdmittedWorkload(w) {
log.Error(fmt.Errorf("workload is assumed"), "nominate", "workloadInfo", w)
continue
} else if snap.InactiveClusterQueueSets.Has(w.ClusterQueue) {
Expand Down

0 comments on commit 0bb02b0

Please sign in to comment.