@@ -154,7 +154,7 @@ func (n *clusterHealthData) deepCopy() *clusterHealthData {
154
154
// The Controller will requeue the Request to be processed again if an error is non-nil or
155
155
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
156
156
func (c * Controller ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
157
- klog .V (4 ).Infof ("Reconciling cluster %s " , req .NamespacedName .Name )
157
+ klog .V (4 ).InfoS ("Reconciling cluster" , "cluster " , req .NamespacedName .Name )
158
158
159
159
cluster := & clusterv1alpha1.Cluster {}
160
160
if err := c .Client .Get (ctx , req .NamespacedName , cluster ); err != nil {
@@ -175,13 +175,13 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
175
175
176
176
// Start starts an asynchronous loop that monitors the status of cluster.
177
177
func (c * Controller ) Start (ctx context.Context ) error {
178
- klog .Infof ("Starting cluster health monitor" )
179
- defer klog .Infof ("Shutting cluster health monitor" )
178
+ klog .InfoS ("Starting cluster health monitor" )
179
+ defer klog .InfoS ("Shutting cluster health monitor" )
180
180
181
181
// Incorporate the results of cluster health signal pushed from cluster-status-controller to master.
182
182
go wait .UntilWithContext (ctx , func (ctx context.Context ) {
183
183
if err := c .monitorClusterHealth (ctx ); err != nil {
184
- klog .Errorf ( "Error monitoring cluster health: %v" , err )
184
+ klog .ErrorS ( err , "Error monitoring cluster health" )
185
185
}
186
186
}, c .ClusterMonitorPeriod )
187
187
<- ctx .Done ()
@@ -219,18 +219,18 @@ func (c *Controller) syncCluster(ctx context.Context, cluster *clusterv1alpha1.C
219
219
220
220
func (c * Controller ) removeCluster (ctx context.Context , cluster * clusterv1alpha1.Cluster ) (controllerruntime.Result , error ) {
221
221
if err := c .removeExecutionSpace (ctx , cluster ); err != nil {
222
- klog .Errorf ( "Failed to remove execution space %s: %v" , cluster .Name , err )
222
+ klog .ErrorS ( err , "Failed to remove execution space" , "cluster" , cluster .Name )
223
223
c .EventRecorder .Event (cluster , corev1 .EventTypeWarning , events .EventReasonRemoveExecutionSpaceFailed , err .Error ())
224
224
return controllerruntime.Result {}, err
225
225
}
226
226
msg := fmt .Sprintf ("Removed execution space for cluster(%s)." , cluster .Name )
227
227
c .EventRecorder .Event (cluster , corev1 .EventTypeNormal , events .EventReasonRemoveExecutionSpaceSucceed , msg )
228
228
229
229
if exist , err := c .ExecutionSpaceExistForCluster (ctx , cluster .Name ); err != nil {
230
- klog .Errorf ( "Failed to check weather the execution space exist in the given member cluster or not, error is: %v" , err )
230
+ klog .ErrorS ( err , "Failed to check execution space existence" , "cluster" , cluster . Name )
231
231
return controllerruntime.Result {}, err
232
232
} else if exist {
233
- klog .Infof ("Requeuing operation until the cluster(%s) execution space deleted" , cluster .Name )
233
+ klog .InfoS ("Requeuing operation until execution space deleted" , "cluster " , cluster .Name )
234
234
return controllerruntime.Result {RequeueAfter : c .CleanupCheckInterval }, nil
235
235
}
236
236
@@ -287,12 +287,12 @@ func (c *Controller) removeExecutionSpace(ctx context.Context, cluster *clusterv
287
287
// delete finalizers of work objects when the sync-mode is pull and cluster status is notready or unknown
288
288
if cluster .Spec .SyncMode == clusterv1alpha1 .Pull && ! util .IsClusterReady (& cluster .Status ) {
289
289
if err := c .deleteFinalizerForWorks (ctx , executionSpaceObj ); err != nil {
290
- klog .Errorf ( "Error while deleting finalizers of work which in %s: %s " , executionSpaceName , err )
290
+ klog .ErrorS ( err , "Error while deleting finalizers of work" , "namespace" , executionSpaceName )
291
291
return err
292
292
}
293
293
}
294
294
if err := c .Client .Delete (ctx , executionSpaceObj ); err != nil && ! apierrors .IsNotFound (err ) {
295
- klog .Errorf ( "Error while deleting namespace %s: %s " , executionSpaceName , err )
295
+ klog .ErrorS ( err , "Error while deleting namespace" , "namespace" , executionSpaceName )
296
296
return err
297
297
}
298
298
@@ -306,11 +306,11 @@ func (c *Controller) ExecutionSpaceExistForCluster(ctx context.Context, clusterN
306
306
executionSpaceObj := & corev1.Namespace {}
307
307
err := c .Client .Get (ctx , types.NamespacedName {Name : executionSpaceName }, executionSpaceObj )
308
308
if apierrors .IsNotFound (err ) {
309
- klog .V (2 ).Infof ("Execution space(%s) no longer exists" , executionSpaceName )
309
+ klog .V (2 ).InfoS ("Execution space no longer exists" , "namespace " , executionSpaceName )
310
310
return false , nil
311
311
}
312
312
if err != nil {
313
- klog .Errorf ( "Failed to get execution space %v, err is %v " , executionSpaceName , err )
313
+ klog .ErrorS ( err , "Failed to get execution space" , "namespace" , executionSpaceName )
314
314
return false , err
315
315
}
316
316
return true , nil
@@ -323,7 +323,7 @@ func (c *Controller) deleteFinalizerForWorks(ctx context.Context, workSpace *cor
323
323
Namespace : workSpace .Name ,
324
324
})
325
325
if err != nil {
326
- klog .Errorf ( "Failed to list works in %s: %s" , workSpace .Name , err )
326
+ klog .ErrorS ( err , "Failed to list works in namespace" , "namespace" , workSpace .Name )
327
327
return err
328
328
}
329
329
@@ -386,7 +386,7 @@ func (c *Controller) createExecutionSpace(ctx context.Context, cluster *clusterv
386
386
err := c .Client .Get (ctx , types.NamespacedName {Name : executionSpaceName }, executionSpaceObj )
387
387
if err != nil {
388
388
if ! apierrors .IsNotFound (err ) {
389
- klog .Errorf ( "Failed to get namespace(%s): %v " , executionSpaceName , err )
389
+ klog .ErrorS ( err , "Failed to get namespace" , "namespace" , executionSpaceName )
390
390
return err
391
391
}
392
392
@@ -401,11 +401,11 @@ func (c *Controller) createExecutionSpace(ctx context.Context, cluster *clusterv
401
401
}
402
402
err = c .Client .Create (ctx , executionSpace )
403
403
if err != nil {
404
- klog .Errorf ( "Failed to create execution space for cluster(%s): %v " , cluster .Name , err )
404
+ klog .ErrorS ( err , "Failed to create execution space" , " cluster" , cluster .Name )
405
405
return err
406
406
}
407
407
msg := fmt .Sprintf ("Created execution space(%s) for cluster(%s)." , executionSpaceName , cluster .Name )
408
- klog .V (2 ).Info (msg )
408
+ klog .V (2 ).InfoS (msg )
409
409
c .EventRecorder .Event (cluster , corev1 .EventTypeNormal , events .EventReasonCreateExecutionSpaceSucceed , msg )
410
410
}
411
411
@@ -438,7 +438,7 @@ func (c *Controller) monitorClusterHealth(ctx context.Context) (err error) {
438
438
}
439
439
return false , nil
440
440
}); err != nil {
441
- klog .Errorf ( "Update health of Cluster '%v' from Controller error: %v. Skipping." , cluster .Name , err )
441
+ klog .ErrorS ( err , "Failed to update health, skipping" , "cluster" , cluster .Name )
442
442
continue
443
443
}
444
444
}
@@ -531,8 +531,7 @@ func (c *Controller) tryUpdateClusterHealth(ctx context.Context, cluster *cluste
531
531
for _ , clusterConditionType := range clusterConditionTypes {
532
532
currentCondition := meta .FindStatusCondition (cluster .Status .Conditions , clusterConditionType )
533
533
if currentCondition == nil {
534
- klog .V (2 ).Infof ("Condition %v of cluster %v was never updated by cluster-status-controller" ,
535
- clusterConditionType , cluster .Name )
534
+ klog .V (2 ).InfoS ("Condition was never updated by cluster-status-controller" , "condition" , clusterConditionType , "cluster" , cluster .Name )
536
535
cluster .Status .Conditions = append (cluster .Status .Conditions , metav1.Condition {
537
536
Type : clusterConditionType ,
538
537
Status : metav1 .ConditionUnknown ,
@@ -541,8 +540,9 @@ func (c *Controller) tryUpdateClusterHealth(ctx context.Context, cluster *cluste
541
540
LastTransitionTime : nowTimestamp ,
542
541
})
543
542
} else {
544
- klog . V ( 2 ). Infof ("Cluster %v hasn't been updated for %+v. Last %v is: %+v" ,
543
+ message := fmt . Sprintf ("Cluster %v hasn't been updated for %+v. Last %v is: %+v" ,
545
544
cluster .Name , metav1 .Now ().Time .Sub (clusterHealth .probeTimestamp .Time ), clusterConditionType , currentCondition )
545
+ klog .V (2 ).InfoS (message , "cluster" , cluster .Name )
546
546
if currentCondition .Status != metav1 .ConditionUnknown {
547
547
currentCondition .Status = metav1 .ConditionUnknown
548
548
currentCondition .Reason = "ClusterStatusUnknown"
@@ -556,7 +556,7 @@ func (c *Controller) tryUpdateClusterHealth(ctx context.Context, cluster *cluste
556
556
557
557
if ! equality .Semantic .DeepEqual (currentReadyCondition , observedReadyCondition ) {
558
558
if err := c .Status ().Update (ctx , cluster ); err != nil {
559
- klog .Errorf ( "Error updating cluster %s: %v" , cluster .Name , err )
559
+ klog .ErrorS ( err , "Error updating cluster status" , "cluster" , cluster .Name )
560
560
return err
561
561
}
562
562
clusterHealth = & clusterHealthData {
0 commit comments