@@ -125,7 +125,7 @@ type ClusterStatusController struct {
125
125
// The Controller will requeue the Request to be processed again if an error is non-nil or
126
126
// Result.Requeue is true, otherwise upon completion it will requeue the reconcile key after the duration.
127
127
func (c * ClusterStatusController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
128
- klog .V (4 ).Infof ("Syncing cluster status: %s " , req .NamespacedName .Name )
128
+ klog .V (4 ).InfoS ("Syncing cluster status" , "cluster " , req .NamespacedName .Name )
129
129
130
130
cluster := & clusterv1alpha1.Cluster {}
131
131
if err := c .Client .Get (ctx , req .NamespacedName , cluster ); err != nil {
@@ -151,9 +151,9 @@ func (c *ClusterStatusController) Reconcile(ctx context.Context, req controllerr
151
151
}
152
152
153
153
// start syncing status only when the finalizer is present on the given Cluster to
154
- // avoid conflict with cluster controller.
154
+ // avoid conflict with the cluster controller.
155
155
if ! controllerutil .ContainsFinalizer (cluster , util .ClusterControllerFinalizer ) {
156
- klog .V (2 ).Infof ("Waiting finalizer present for member cluster: %s " , cluster .Name )
156
+ klog .V (2 ).InfoS ("Waiting finalizer present for member cluster" , "cluster " , cluster .Name )
157
157
return controllerruntime.Result {Requeue : true }, nil
158
158
}
159
159
@@ -190,7 +190,7 @@ func (c *ClusterStatusController) syncClusterStatus(ctx context.Context, cluster
190
190
// create a ClusterClient for the given member cluster
191
191
clusterClient , err := c .ClusterClientSetFunc (cluster .Name , c .Client , c .ClusterClientOption )
192
192
if err != nil {
193
- klog .Errorf ( "Failed to create a ClusterClient for the given member cluster: %v, err is : %v" , cluster .Name , err )
193
+ klog .ErrorS ( err , "Failed to create a ClusterClient for the given member cluster" , "cluster" , cluster .Name )
194
194
return setStatusCollectionFailedCondition (ctx , c .Client , cluster , fmt .Sprintf ("failed to create a ClusterClient: %v" , err ))
195
195
}
196
196
@@ -200,8 +200,8 @@ func (c *ClusterStatusController) syncClusterStatus(ctx context.Context, cluster
200
200
201
201
// cluster is offline after retry timeout, update cluster status immediately and return.
202
202
if ! online && readyCondition .Status != metav1 .ConditionTrue {
203
- klog .V (2 ).Infof ("Cluster(%s) still offline after %s, ensuring offline is set. " ,
204
- cluster .Name , c .ClusterFailureThreshold .Duration )
203
+ klog .V (2 ).InfoS ("Cluster still offline after ensuring offline is set" ,
204
+ " cluster" , cluster .Name , "duration" , c .ClusterFailureThreshold .Duration )
205
205
return updateStatusCondition (ctx , c .Client , cluster , * readyCondition )
206
206
}
207
207
@@ -235,7 +235,7 @@ func (c *ClusterStatusController) setCurrentClusterStatus(clusterClient *util.Cl
235
235
var conditions []metav1.Condition
236
236
clusterVersion , err := getKubernetesVersion (clusterClient )
237
237
if err != nil {
238
- klog .Errorf ( "Failed to get Kubernetes version for Cluster %s. Error: %v." , cluster .GetName (), err )
238
+ klog .ErrorS ( err , "Failed to get Kubernetes version for Cluster" , "cluster" , cluster .GetName ())
239
239
}
240
240
currentClusterStatus .KubernetesVersion = clusterVersion
241
241
@@ -245,11 +245,11 @@ func (c *ClusterStatusController) setCurrentClusterStatus(clusterClient *util.Cl
245
245
if len (apiEnables ) == 0 {
246
246
apiEnablementCondition = util .NewCondition (clusterv1alpha1 .ClusterConditionCompleteAPIEnablements ,
247
247
apiEnablementEmptyAPIEnablements , "collected empty APIEnablements from the cluster" , metav1 .ConditionFalse )
248
- klog .Errorf ( "Failed to get any APIs installed in Cluster %s. Error: %v." , cluster .GetName (), err )
248
+ klog .ErrorS ( err , "Failed to get any APIs installed in Cluster" , "cluster" , cluster .GetName ())
249
249
} else if err != nil {
250
250
apiEnablementCondition = util .NewCondition (clusterv1alpha1 .ClusterConditionCompleteAPIEnablements ,
251
251
apiEnablementPartialAPIEnablements , fmt .Sprintf ("might collect partial APIEnablements(%d) from the cluster" , len (apiEnables )), metav1 .ConditionFalse )
252
- klog .Warningf ( "Maybe get partial(%d) APIs installed in Cluster %s. Error: %v." , len (apiEnables ), cluster .GetName (), err )
252
+ klog .ErrorS ( err , "Collected partial number of APIs installed in Cluster" , "numApiEnablements" , len (apiEnables ), " cluster" , cluster .GetName ())
253
253
} else {
254
254
apiEnablementCondition = util .NewCondition (clusterv1alpha1 .ClusterConditionCompleteAPIEnablements ,
255
255
apiEnablementsComplete , "collected complete APIEnablements from the cluster" , metav1 .ConditionTrue )
@@ -261,19 +261,19 @@ func (c *ClusterStatusController) setCurrentClusterStatus(clusterClient *util.Cl
261
261
// get or create informer for pods and nodes in member cluster
262
262
clusterInformerManager , err := c .buildInformerForCluster (clusterClient )
263
263
if err != nil {
264
- klog .Errorf ( "Failed to get or create informer for Cluster %s. Error: %v." , cluster .GetName (), err )
264
+ klog .ErrorS ( err , "Failed to get or create informer for Cluster" , "cluster" , cluster .GetName ())
265
265
// in large-scale clusters, the timeout may occur.
266
266
// if clusterInformerManager fails to be built, should be returned, otherwise, it may cause a nil pointer
267
267
return nil , err
268
268
}
269
269
nodes , err := listNodes (clusterInformerManager )
270
270
if err != nil {
271
- klog .Errorf ( "Failed to list nodes for Cluster %s. Error: %v." , cluster .GetName (), err )
271
+ klog .ErrorS ( err , "Failed to list nodes for Cluster" , "cluster" , cluster .GetName ())
272
272
}
273
273
274
274
pods , err := listPods (clusterInformerManager )
275
275
if err != nil {
276
- klog .Errorf ( "Failed to list pods for Cluster %s. Error: %v." , cluster .GetName (), err )
276
+ klog .ErrorS ( err , "Failed to list pods for Cluster" , "cluster" , cluster .GetName ())
277
277
}
278
278
currentClusterStatus .NodeSummary = getNodeSummary (nodes )
279
279
currentClusterStatus .ResourceSummary = getResourceSummary (nodes , pods )
@@ -296,7 +296,7 @@ func (c *ClusterStatusController) updateStatusIfNeeded(ctx context.Context, clus
296
296
meta .SetStatusCondition (& currentClusterStatus .Conditions , condition )
297
297
}
298
298
if ! equality .Semantic .DeepEqual (cluster .Status , currentClusterStatus ) {
299
- klog .V (4 ).Infof ("Start to update cluster status: %s " , cluster .Name )
299
+ klog .V (4 ).InfoS ("Start to update cluster status" , "cluster " , cluster .Name )
300
300
err := retry .RetryOnConflict (retry .DefaultRetry , func () (err error ) {
301
301
_ , err = helper .UpdateStatus (ctx , c .Client , cluster , func () error {
302
302
cluster .Status .KubernetesVersion = currentClusterStatus .KubernetesVersion
@@ -311,7 +311,7 @@ func (c *ClusterStatusController) updateStatusIfNeeded(ctx context.Context, clus
311
311
return err
312
312
})
313
313
if err != nil {
314
- klog .Errorf ( "Failed to update health status of the member cluster: %v, err is : %v" , cluster .Name , err )
314
+ klog .ErrorS ( err , "Failed to update health status of the member cluster" , "cluster" , cluster .Name )
315
315
return err
316
316
}
317
317
}
@@ -320,7 +320,7 @@ func (c *ClusterStatusController) updateStatusIfNeeded(ctx context.Context, clus
320
320
}
321
321
322
322
func updateStatusCondition (ctx context.Context , c client.Client , cluster * clusterv1alpha1.Cluster , conditions ... metav1.Condition ) error {
323
- klog .V (4 ).Infof ("Start to update cluster(%s) status condition" , cluster .Name )
323
+ klog .V (4 ).InfoS ("Start to update cluster status condition" , "cluster " , cluster .Name )
324
324
err := retry .RetryOnConflict (retry .DefaultRetry , func () (err error ) {
325
325
_ , err = helper .UpdateStatus (ctx , c , cluster , func () error {
326
326
for _ , condition := range conditions {
@@ -331,7 +331,7 @@ func updateStatusCondition(ctx context.Context, c client.Client, cluster *cluste
331
331
return err
332
332
})
333
333
if err != nil {
334
- klog .Errorf ( "Failed to update status condition of the member cluster: %v, err is : %v" , cluster .Name , err )
334
+ klog .ErrorS ( err , "Failed to update status condition of the member cluster" , "cluster" , cluster .Name )
335
335
return err
336
336
}
337
337
return nil
@@ -344,7 +344,7 @@ func (c *ClusterStatusController) initializeGenericInformerManagerForCluster(clu
344
344
345
345
dynamicClient , err := c .ClusterDynamicClientSetFunc (clusterClient .ClusterName , c .Client , c .ClusterClientOption )
346
346
if err != nil {
347
- klog .Errorf ( "Failed to build dynamic cluster client for cluster %s. " , clusterClient .ClusterName )
347
+ klog .ErrorS ( err , "Failed to build dynamic cluster client" , " cluster" , clusterClient .ClusterName )
348
348
return
349
349
}
350
350
c .GenericInformerManager .ForCluster (clusterClient .ClusterName , dynamicClient .DynamicClientSet , 0 )
@@ -366,7 +366,7 @@ func (c *ClusterStatusController) buildInformerForCluster(clusterClient *util.Cl
366
366
if ! singleClusterInformerManager .IsInformerSynced (gvr ) {
367
367
allSynced = false
368
368
if _ , err := singleClusterInformerManager .Lister (gvr ); err != nil {
369
- klog .Errorf ( "Failed to get the lister for gvr %s: %v" , gvr .String (), err )
369
+ klog .ErrorS ( err , "Failed to get the lister for gvr" , "gvr" , gvr .String ())
370
370
}
371
371
}
372
372
}
@@ -389,7 +389,7 @@ func (c *ClusterStatusController) buildInformerForCluster(clusterClient *util.Cl
389
389
}
390
390
return nil
391
391
}(); err != nil {
392
- klog .Errorf ( "Failed to sync cache for cluster: %s, error: %v" , clusterClient .ClusterName , err )
392
+ klog .ErrorS ( err , "Failed to sync cache for cluster" , "cluster" , clusterClient .ClusterName )
393
393
c .TypedInformerManager .Stop (clusterClient .ClusterName )
394
394
return nil , err
395
395
}
@@ -422,12 +422,12 @@ func (c *ClusterStatusController) initLeaseController(cluster *clusterv1alpha1.C
422
422
423
423
// start syncing lease
424
424
go func () {
425
- klog .Infof ("Starting syncing lease for cluster: %s " , cluster .Name )
425
+ klog .InfoS ("Starting syncing lease for cluster" , "cluster " , cluster .Name )
426
426
427
427
// lease controller will keep running until the stop channel is closed(context is canceled)
428
428
clusterLeaseController .Run (ctx )
429
429
430
- klog .Infof ("Stop syncing lease for cluster: %s " , cluster .Name )
430
+ klog .InfoS ("Stop syncing lease for cluster" , "cluster " , cluster .Name )
431
431
c .ClusterLeaseControllers .Delete (cluster .Name ) // ensure the cache is clean
432
432
}()
433
433
}
@@ -440,12 +440,12 @@ func getClusterHealthStatus(clusterClient *util.ClusterClient) (online, healthy
440
440
}
441
441
442
442
if err != nil {
443
- klog .Errorf ( "Failed to do cluster health check for cluster %v, err is : %v " , clusterClient .ClusterName , err )
443
+ klog .ErrorS ( err , "Failed to do cluster health check for cluster" , "cluster" , clusterClient .ClusterName )
444
444
return false , false
445
445
}
446
446
447
447
if healthStatus != http .StatusOK {
448
- klog .Infof ("Member cluster %v isn't healthy" , clusterClient .ClusterName )
448
+ klog .InfoS ("Member cluster isn't healthy" , "cluster " , clusterClient .ClusterName )
449
449
return true , false
450
450
}
451
451
@@ -627,7 +627,8 @@ func getNodeAvailable(allocatable corev1.ResourceList, podResources *util.Resour
627
627
// When too many pods have been created, scheduling will fail so that the allocating pods number may be huge.
628
628
// If allowedPodNumber is less than or equal to 0, we don't allow more pods to be created.
629
629
if allowedPodNumber <= 0 {
630
- klog .Warningf ("The number of schedulable Pods on the node is less than or equal to 0, we won't add the node to cluster resource models." )
630
+ klog .InfoS ("The number of schedulable Pods on the node is less than or equal to 0, " +
631
+ "we won't add the node to cluster resource models." )
631
632
return nil
632
633
}
633
634
@@ -647,7 +648,7 @@ func getAllocatableModelings(cluster *clusterv1alpha1.Cluster, nodes []*corev1.N
647
648
}
648
649
modelingSummary , err := modeling .InitSummary (cluster .Spec .ResourceModels )
649
650
if err != nil {
650
- klog .Errorf ( "Failed to init cluster summary from cluster resource models for Cluster %s. Error: %v." , cluster .GetName (), err )
651
+ klog .ErrorS ( err , "Failed to init cluster summary from cluster resource models for Cluster" , "cluster" , cluster .GetName ())
651
652
return nil
652
653
}
653
654
0 commit comments