@@ -103,7 +103,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
103103 r .nodeDeletionRetryTimeout = 10 * time .Second
104104 }
105105
106- tr := log .Reconciler (r , "controllers.MachineReconciler" , "machine" )
106+ tr := log .Reconciler (r )
107107 controller , err := ctrl .NewControllerManagedBy (mgr ).
108108 For (& clusterv1.Machine {}).
109109 WithOptions (options ).
@@ -297,7 +297,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
297297 if err != nil {
298298 switch err {
299299 case errNoControlPlaneNodes , errLastControlPlaneNode , errNilNodeRef , errClusterIsBeingDeleted , errControlPlaneIsBeingDeleted :
300- log .Info ("Deleting Kubernetes Node associated with Machine is not allowed" , "node" , m .Status .NodeRef , "cause" , err .Error ())
300+ log .Info ("Deleting Kubernetes Node associated with Machine is not allowed" , "node" , klog . KRef ( "" , m .Status .NodeRef . Name ) , "cause" , err .Error ())
301301 default :
302302 return ctrl.Result {}, errors .Wrapf (err , "failed to check if Kubernetes Node deletion is allowed" )
303303 }
@@ -319,7 +319,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
319319 return ctrl.Result {}, err
320320 }
321321
322- log .Info ("Draining node" , "node" , m .Status .NodeRef .Name )
322+ log .Info ("Draining node" , "node" , klog . KRef ( "" , m .Status .NodeRef .Name ) )
323323 // The DrainingSucceededCondition never exists before the node is drained for the first time,
324324 // so its transition time can be used to record the first time draining.
325325 // This `if` condition prevents the transition time to be changed more than once.
@@ -351,7 +351,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
351351 r .recorder .Eventf (m , corev1 .EventTypeWarning , "FailedWaitForVolumeDetach" , "error wait for volume detach, node %q: %v" , m .Status .NodeRef .Name , err )
352352 return ctrl.Result {}, err
353353 }
354- log .Info ("Waiting for node volumes to be detached" , "node" , m .Status .NodeRef .Name )
354+ log .Info ("Waiting for node volumes to be detached" , "node" , klog . KRef ( "" , m .Status .NodeRef .Name ) )
355355 return ctrl.Result {}, nil
356356 }
357357 conditions .MarkTrue (m , clusterv1 .VolumeDetachSucceededCondition )
@@ -391,7 +391,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
391391 // We only delete the node after the underlying infrastructure is gone.
392392 // https://github.com/kubernetes-sigs/cluster-api/issues/2565
393393 if isDeleteNodeAllowed {
394- log .Info ("Deleting node" , "node" , m .Status .NodeRef .Name )
394+ log .Info ("Deleting node" , "node" , klog . KRef ( "" , m .Status .NodeRef .Name ) )
395395
396396 var deleteNodeErr error
397397 waitErr := wait .PollImmediate (2 * time .Second , r .nodeDeletionRetryTimeout , func () (bool , error ) {
@@ -401,7 +401,7 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Clu
401401 return true , nil
402402 })
403403 if waitErr != nil {
404- log .Error (deleteNodeErr , "Timed out deleting node" , "node" , m .Status .NodeRef .Name )
404+ log .Error (deleteNodeErr , "Timed out deleting node" , "node" , klog . KRef ( "" , m .Status .NodeRef .Name ) )
405405 conditions .MarkFalse (m , clusterv1 .MachineNodeHealthyCondition , clusterv1 .DeletionFailedReason , clusterv1 .ConditionSeverityWarning , "" )
406406 r .recorder .Eventf (m , corev1 .EventTypeWarning , "FailedDeleteNode" , "error deleting Machine's node: %v" , deleteNodeErr )
407407
@@ -449,7 +449,7 @@ func (r *Reconciler) nodeDrainTimeoutExceeded(machine *clusterv1.Machine) bool {
449449// isDeleteNodeAllowed returns nil only if the Machine's NodeRef is not nil
450450// and if the Machine is not the last control plane node in the cluster.
451451func (r * Reconciler ) isDeleteNodeAllowed (ctx context.Context , cluster * clusterv1.Cluster , machine * clusterv1.Machine ) error {
452- log := ctrl .LoggerFrom (ctx , "cluster" , klog . KObj ( cluster ). String () )
452+ log := ctrl .LoggerFrom (ctx )
453453 // Return early if the cluster is being deleted.
454454 if ! cluster .DeletionTimestamp .IsZero () {
455455 return errClusterIsBeingDeleted
@@ -509,7 +509,7 @@ func (r *Reconciler) isDeleteNodeAllowed(ctx context.Context, cluster *clusterv1
509509}
510510
511511func (r * Reconciler ) drainNode (ctx context.Context , cluster * clusterv1.Cluster , nodeName string ) (ctrl.Result , error ) {
512- log := ctrl .LoggerFrom (ctx , "node" , nodeName )
512+ log := ctrl .LoggerFrom (ctx , "node" , klog . KRef ( "" , nodeName ) )
513513
514514 restConfig , err := remote .RESTConfig (ctx , controllerName , r .Client , util .ObjectKey (cluster ))
515515 if err != nil {
@@ -581,7 +581,7 @@ func (r *Reconciler) drainNode(ctx context.Context, cluster *clusterv1.Cluster,
581581// because if the node is deleted before detach success, then the underline VMDK will be deleted together with the Machine
582582// so after node draining we need to check if all volumes are detached before deleting the node.
583583func (r * Reconciler ) shouldWaitForNodeVolumes (ctx context.Context , cluster * clusterv1.Cluster , nodeName string ) (bool , error ) {
584- log := ctrl .LoggerFrom (ctx , "node" , nodeName )
584+ log := ctrl .LoggerFrom (ctx , "node" , klog . KRef ( "" , nodeName ) )
585585
586586 remoteClient , err := r .Tracker .GetClient (ctx , util .ObjectKey (cluster ))
587587 if err != nil {
0 commit comments