in pkg/controller/core/workload_controller.go [209:247]
func (r *WorkloadReconciler) Delete(e event.DeleteEvent) bool {
wl, isWorkload := e.Object.(*kueue.Workload)
if !isWorkload {
// this event will be handled by the LimitRange/RuntimeClass handle
return true
}
defer r.notifyWatchers(wl, nil)
status := "unknown"
if !e.DeleteStateUnknown {
status = workloadStatus(wl)
}
log := r.log.WithValues("workload", klog.KObj(wl), "queue", wl.Spec.QueueName, "status", status)
log.V(2).Info("Workload delete event")
ctx := ctrl.LoggerInto(context.Background(), log)
// When assigning a clusterQueue to a workload, we assume it in the cache. If
// the state is unknown, the workload could have been assumed and we need
// to clear it from the cache.
if workload.IsAdmitted(wl) || e.DeleteStateUnknown {
// trigger the move of associated inadmissibleWorkloads if required.
r.queues.QueueAssociatedInadmissibleWorkloadsAfter(ctx, wl, func() {
// Delete the workload from cache while holding the queues lock
// to guarantee that requeueued workloads are taken into account before
// the next scheduling cycle.
if err := r.cache.DeleteWorkload(wl); err != nil {
if !e.DeleteStateUnknown {
log.Error(err, "Failed to delete workload from cache")
}
}
})
}
// Even if the state is unknown, the last cached state tells us whether the
// workload was in the queues and should be cleared from them.
if workload.IsAdmitted(wl) {
r.queues.DeleteWorkload(wl)
}
return true
}