@@ -99,8 +99,9 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
99
99
log := ctrl .LoggerFrom (ctx )
100
100
log .V (3 ).Info ("Reconcile Workload" )
101
101
102
- if r . shouldFinalize (wl ) {
102
+ if finalize , reason := shouldFinalize (wl ); finalize {
103
103
if controllerutil .ContainsFinalizer (wl , SliceControllerName ) {
104
+ log .V (3 ).Info (fmt .Sprintf ("Cleaning up the Slice and finalize the Workload because %s" , reason ))
104
105
err = r .client .Delete (ctx , core .SliceWithMetadata (wl ))
105
106
if client .IgnoreNotFound (err ) != nil {
106
107
return ctrl.Result {}, err
@@ -160,8 +161,24 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
160
161
return ctrl.Result {}, client .IgnoreNotFound (err )
161
162
}
162
163
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 , ""
165
182
}
166
183
167
184
func (r * WorkloadReconciler ) isRelevantWorkload (wl * kueue.Workload , log logr.Logger ) bool {
0 commit comments