@@ -76,13 +76,13 @@ func (c *RebalancerController) SetupWithManager(mgr controllerruntime.Manager) e
76
76
// The Controller will requeue the Request to be processed again if an error is non-nil or
77
77
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
78
78
func (c * RebalancerController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
79
- klog .V (4 ).Infof ("Reconciling for WorkloadRebalancer %s" , req .Name )
79
+ klog .V (4 ).InfoS ("Reconciling for WorkloadRebalancer %s" , req .Name )
80
80
81
81
// 1. get latest WorkloadRebalancer
82
82
rebalancer := & appsv1alpha1.WorkloadRebalancer {}
83
83
if err := c .Client .Get (ctx , req .NamespacedName , rebalancer ); err != nil {
84
84
if apierrors .IsNotFound (err ) {
85
- klog .Infof ("no need to reconcile WorkloadRebalancer for it not found" )
85
+ klog .InfoS ("no need to reconcile WorkloadRebalancer for it not found" )
86
86
return controllerruntime.Result {}, nil
87
87
}
88
88
return controllerruntime.Result {}, err
@@ -203,7 +203,7 @@ func (c *RebalancerController) triggerReschedule(ctx context.Context, metadata m
203
203
if resource .Workload .Namespace != "" {
204
204
binding := & workv1alpha2.ResourceBinding {}
205
205
if err := c .Client .Get (ctx , client.ObjectKey {Namespace : resource .Workload .Namespace , Name : bindingName }, binding ); err != nil {
206
- klog .Errorf ( "get binding for resource %+v failed: %+v" , resource .Workload , err )
206
+ klog .ErrorS ( err , "get binding for resource failed" , "resource" , resource .Workload )
207
207
c .recordAndCountRebalancerFailed (& newStatus .ObservedWorkloads [i ], & retryNum , err )
208
208
continue
209
209
}
@@ -212,7 +212,7 @@ func (c *RebalancerController) triggerReschedule(ctx context.Context, metadata m
212
212
binding .Spec .RescheduleTriggeredAt = & metadata .CreationTimestamp
213
213
214
214
if err := c .Client .Update (ctx , binding ); err != nil {
215
- klog .Errorf ( "update binding for resource %+v failed: %+v" , resource .Workload , err )
215
+ klog .ErrorS ( err , "update binding for resource failed" , "resource" , resource .Workload )
216
216
c .recordAndCountRebalancerFailed (& newStatus .ObservedWorkloads [i ], & retryNum , err )
217
217
continue
218
218
}
@@ -221,7 +221,7 @@ func (c *RebalancerController) triggerReschedule(ctx context.Context, metadata m
221
221
} else {
222
222
clusterbinding := & workv1alpha2.ClusterResourceBinding {}
223
223
if err := c .Client .Get (ctx , client.ObjectKey {Name : bindingName }, clusterbinding ); err != nil {
224
- klog .Errorf ( "get cluster binding for resource %+v failed: %+v" , resource .Workload , err )
224
+ klog .ErrorS ( err , "get cluster binding for resource failed" , "resource" , resource .Workload )
225
225
c .recordAndCountRebalancerFailed (& newStatus .ObservedWorkloads [i ], & retryNum , err )
226
226
continue
227
227
}
@@ -230,7 +230,7 @@ func (c *RebalancerController) triggerReschedule(ctx context.Context, metadata m
230
230
clusterbinding .Spec .RescheduleTriggeredAt = & metadata .CreationTimestamp
231
231
232
232
if err := c .Client .Update (ctx , clusterbinding ); err != nil {
233
- klog .Errorf ( "update cluster binding for resource %+v failed: %+v" , resource .Workload , err )
233
+ klog .ErrorS ( err , "update cluster binding for resource failed" , "resource" , resource .Workload )
234
234
c .recordAndCountRebalancerFailed (& newStatus .ObservedWorkloads [i ], & retryNum , err )
235
235
continue
236
236
}
@@ -239,8 +239,8 @@ func (c *RebalancerController) triggerReschedule(ctx context.Context, metadata m
239
239
}
240
240
}
241
241
242
- klog .V (4 ).Infof ( "Finish handling WorkloadRebalancer (%s) , %d/%d resource success in all, while %d resource need retry" ,
243
- metadata .Name , successNum , len (newStatus .ObservedWorkloads ), retryNum )
242
+ klog .V (4 ).InfoS ( fmt . Sprintf ( "Finish handling WorkloadRebalancer, %d/%d resource success in all, while %d resource need retry" ,
243
+ successNum , len ( newStatus . ObservedWorkloads ), retryNum ), "workloadRebalancer" , metadata .Name , " successNum" , successNum , "totalNum" , len (newStatus .ObservedWorkloads ), "retryNum" , retryNum )
244
244
return newStatus , retryNum
245
245
}
246
246
@@ -269,33 +269,33 @@ func (c *RebalancerController) updateWorkloadRebalancerStatus(ctx context.Contex
269
269
modifiedRebalancer .Status = * newStatus
270
270
271
271
return retry .RetryOnConflict (retry .DefaultRetry , func () (err error ) {
272
- klog .V (4 ).Infof ("Start to patch WorkloadRebalancer(%s) status" , rebalancer .Name )
272
+ klog .V (4 ).InfoS ("Start to patch WorkloadRebalancer status" , "workloadRebalancer " , rebalancer .Name )
273
273
if err = c .Client .Status ().Patch (ctx , modifiedRebalancer , client .MergeFrom (rebalancer )); err != nil {
274
- klog .Errorf ( "Failed to patch WorkloadRebalancer (%s) status, err: %+v" , rebalancer .Name , err )
274
+ klog .ErrorS ( err , "Failed to patch WorkloadRebalancer status" , "workloadRebalancer" , rebalancer .Name )
275
275
return err
276
276
}
277
- klog .V (4 ).Infof ("Patch WorkloadRebalancer(%s) successful" , rebalancer .Name )
277
+ klog .V (4 ).InfoS ("Patch WorkloadRebalancer successful" , "workloadRebalancer " , rebalancer .Name )
278
278
return nil
279
279
})
280
280
}
281
281
282
282
func (c * RebalancerController ) deleteWorkloadRebalancer (ctx context.Context , rebalancer * appsv1alpha1.WorkloadRebalancer ) error {
283
- klog .V (4 ).Infof ("Start to clean up WorkloadRebalancer(%s) " , rebalancer .Name )
283
+ klog .V (4 ).InfoS ("Start to clean up WorkloadRebalancer" , "workloadRebalancer " , rebalancer .Name )
284
284
285
285
options := & client.DeleteOptions {Preconditions : & metav1.Preconditions {ResourceVersion : & rebalancer .ResourceVersion }}
286
286
if err := c .Client .Delete (ctx , rebalancer , options ); err != nil {
287
- klog .Errorf ( "Cleaning up WorkloadRebalancer(%s) failed: %+v." , rebalancer .Name , err )
287
+ klog .ErrorS ( err , "Cleaning up WorkloadRebalancer failed" , "workloadRebalancer" , rebalancer .Name )
288
288
return err
289
289
}
290
290
291
- klog .V (4 ).Infof ("Cleaning up WorkloadRebalancer(%s) successful" , rebalancer .Name )
291
+ klog .V (4 ).InfoS ("Cleaning up WorkloadRebalancer successful" , "workloadRebalancer " , rebalancer .Name )
292
292
return nil
293
293
}
294
294
295
295
func timeLeft (r * appsv1alpha1.WorkloadRebalancer ) time.Duration {
296
296
expireAt := r .Status .FinishTime .Add (time .Duration (* r .Spec .TTLSecondsAfterFinished ) * time .Second )
297
297
remainingTTL := time .Until (expireAt )
298
298
299
- klog .V (4 ).Infof ( "Found Rebalancer(%s) finished at: %+v, remainingTTL: %+v" , r .Name , r .Status .FinishTime .UTC (), remainingTTL )
299
+ klog .V (4 ).InfoS ( "Check remaining TTL" , "workloadRebalancer" , r .Name , "FinishTime" , r .Status .FinishTime .UTC (), "remainingTTL" , remainingTTL )
300
300
return remainingTTL
301
301
}
0 commit comments