Skip to content

Commit 1309829

Browse files
committed
Log finalization reason.
1 parent ebea3ee commit 1309829

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

slice/internal/controller/workload_controller.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
9999
log := ctrl.LoggerFrom(ctx)
100100
log.V(3).Info("Reconcile Workload")
101101

102-
if r.shouldFinalize(wl) {
102+
if finalize, reason := shouldFinalize(wl); finalize {
103103
if controllerutil.ContainsFinalizer(wl, SliceControllerName) {
104+
log.V(3).Info(fmt.Sprintf("Cleaning up the Slice and finalize the Workload because %s", reason))
104105
err = r.client.Delete(ctx, core.SliceWithMetadata(wl))
105106
if client.IgnoreNotFound(err) != nil {
106107
return ctrl.Result{}, err
@@ -160,8 +161,24 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
160161
return ctrl.Result{}, client.IgnoreNotFound(err)
161162
}
162163

163-
func (r *WorkloadReconciler) shouldFinalize(wl *kueue.Workload) bool {
164-
return !wl.DeletionTimestamp.IsZero() || workload.IsFinished(wl) || workload.IsEvicted(wl) || !workload.IsActive(wl)
164+
func shouldFinalize(wl *kueue.Workload) (bool, string) {
165+
if !wl.DeletionTimestamp.IsZero() {
166+
return true, "it has been deleted"
167+
}
168+
169+
if workload.IsFinished(wl) {
170+
return true, "it has finished"
171+
}
172+
173+
if workload.IsEvicted(wl) {
174+
return true, "it was evicted"
175+
}
176+
177+
if !workload.IsActive(wl) {
178+
return true, "it is no longer active"
179+
}
180+
181+
return false, ""
165182
}
166183

167184
func (r *WorkloadReconciler) isRelevantWorkload(wl *kueue.Workload, log logr.Logger) bool {

0 commit comments

Comments
 (0)