@@ -31,6 +31,7 @@ import (
3131 "k8s.io/apimachinery/pkg/runtime"
3232 "k8s.io/apimachinery/pkg/types"
3333 kerrors "k8s.io/apimachinery/pkg/util/errors"
34+ "k8s.io/klog/v2"
3435 "k8s.io/utils/pointer"
3536 ctrl "sigs.k8s.io/controller-runtime"
3637 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -101,7 +102,7 @@ type Scope struct {
101102// SetupWithManager sets up the reconciler with the Manager.
102103func (r * KubeadmConfigReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
103104 if r .KubeadmInitLock == nil {
104- r .KubeadmInitLock = locking .NewControlPlaneInitMutex (ctrl . LoggerFrom ( ctx ). WithName ( "init-locker" ), mgr .GetClient ())
105+ r .KubeadmInitLock = locking .NewControlPlaneInitMutex (mgr .GetClient ())
105106 }
106107 if r .remoteClientGetter == nil {
107108 r .remoteClientGetter = remote .NewClusterClient
@@ -172,7 +173,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
172173 if configOwner == nil {
173174 return ctrl.Result {}, nil
174175 }
175- log = log .WithValues ("kind" , configOwner .GetKind (), "version" , configOwner .GetResourceVersion () , "name " , configOwner .GetName ())
176+ log = log .WithValues (configOwner . LowerCamelCaseKind (), klog . KRef ( configOwner .GetNamespace (), configOwner .GetName ()) , "resourceVersion " , configOwner .GetResourceVersion ())
176177
177178 // Lookup the cluster the config owner is associated with
178179 cluster , err := util .GetClusterByName (ctx , r .Client , configOwner .GetNamespace (), configOwner .ClusterName ())
@@ -190,6 +191,8 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
190191 return ctrl.Result {}, err
191192 }
192193
194+ ctx = ctrl .LoggerInto (ctx , log .WithValues ("cluster" , klog .KObj (cluster )))
195+
193196 if annotations .IsPaused (cluster , config ) {
194197 log .Info ("Reconciliation is paused for this object" )
195198 return ctrl.Result {}, nil
@@ -321,14 +324,14 @@ func (r *KubeadmConfigReconciler) rotateMachinePoolBootstrapToken(ctx context.Co
321324 return ctrl.Result {}, err
322325 }
323326 if shouldRotate {
324- log .V ( 2 ). Info ("Creating new bootstrap token" )
327+ log .Info ("Creating new bootstrap token, the existing one should be rotated " )
325328 token , err := createToken (ctx , remoteClient , r .TokenTTL )
326329 if err != nil {
327330 return ctrl.Result {}, errors .Wrapf (err , "failed to create new bootstrap token" )
328331 }
329332
330333 config .Spec .JoinConfiguration .Discovery .BootstrapToken .Token = token
331- log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" , " Token", token )
334+ log .V ( 3 ). Info ("Altering JoinConfiguration.Discovery.BootstrapToken. Token" )
332335
333336 // update the bootstrap data
334337 return r .joinWorker (ctx , scope )
@@ -378,7 +381,7 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
378381 }
379382 }()
380383
381- scope .Info ("Creating BootstrapData for the init control plane" )
384+ scope .Info ("Creating BootstrapData for the first control plane" )
382385
383386 // Nb. in this case JoinConfiguration should not be defined by users, but in case of misconfigurations, CABPK simply ignore it
384387
@@ -495,6 +498,8 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
495498}
496499
497500func (r * KubeadmConfigReconciler ) joinWorker (ctx context.Context , scope * Scope ) (ctrl.Result , error ) {
501+ scope .Info ("Creating BootstrapData for the worker node" )
502+
498503 certificates := secret .NewCertificatesForWorker (scope .Config .Spec .JoinConfiguration .CACertPath )
499504 err := certificates .Lookup (
500505 ctx ,
@@ -534,8 +539,6 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
534539 return ctrl.Result {}, errors .New ("Machine is a Worker, but JoinConfiguration.ControlPlane is set in the KubeadmConfig object" )
535540 }
536541
537- scope .Info ("Creating BootstrapData for the worker node" )
538-
539542 verbosityFlag := ""
540543 if scope .Config .Spec .Verbosity != nil {
541544 verbosityFlag = fmt .Sprintf ("--v %s" , strconv .Itoa (int (* scope .Config .Spec .Verbosity )))
@@ -592,6 +595,8 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
592595}
593596
594597func (r * KubeadmConfigReconciler ) joinControlplane (ctx context.Context , scope * Scope ) (ctrl.Result , error ) {
598+ scope .Info ("Creating BootstrapData for the joining control plane" )
599+
595600 if ! scope .ConfigOwner .IsControlPlaneMachine () {
596601 return ctrl.Result {}, fmt .Errorf ("%s is not a valid control plane kind, only Machine is supported" , scope .ConfigOwner .GetKind ())
597602 }
@@ -635,8 +640,6 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
635640 return ctrl.Result {}, err
636641 }
637642
638- scope .Info ("Creating BootstrapData for the join control plane" )
639-
640643 verbosityFlag := ""
641644 if scope .Config .Spec .Verbosity != nil {
642645 verbosityFlag = fmt .Sprintf ("--v %s" , strconv .Itoa (int (* scope .Config .Spec .Verbosity )))
@@ -889,7 +892,7 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(ctx context.Context, cluste
889892
890893 apiServerEndpoint = cluster .Spec .ControlPlaneEndpoint .String ()
891894 config .Spec .JoinConfiguration .Discovery .BootstrapToken .APIServerEndpoint = apiServerEndpoint
892- log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" , "APIServerEndpoint" , apiServerEndpoint )
895+ log .V ( 3 ). Info ("Altering JoinConfiguration.Discovery.BootstrapToken.APIServerEndpoint " , "APIServerEndpoint" , apiServerEndpoint )
893896 }
894897
895898 // if BootstrapToken already contains a token, respect it; otherwise create a new bootstrap token for the node to join
@@ -905,7 +908,7 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(ctx context.Context, cluste
905908 }
906909
907910 config .Spec .JoinConfiguration .Discovery .BootstrapToken .Token = token
908- log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" )
911+ log .V ( 3 ). Info ("Altering JoinConfiguration.Discovery.BootstrapToken.Token " )
909912 }
910913
911914 // If the BootstrapToken does not contain any CACertHashes then force skip CA Verification
@@ -927,39 +930,39 @@ func (r *KubeadmConfigReconciler) reconcileTopLevelObjectSettings(ctx context.Co
927930 // then use Cluster's ControlPlaneEndpoint as a control plane endpoint for the Kubernetes cluster.
928931 if config .Spec .ClusterConfiguration .ControlPlaneEndpoint == "" && cluster .Spec .ControlPlaneEndpoint .IsValid () {
929932 config .Spec .ClusterConfiguration .ControlPlaneEndpoint = cluster .Spec .ControlPlaneEndpoint .String ()
930- log .Info ("Altering ClusterConfiguration" , "ControlPlaneEndpoint" , config .Spec .ClusterConfiguration .ControlPlaneEndpoint )
933+ log .V ( 3 ). Info ("Altering ClusterConfiguration.ControlPlaneEndpoint " , "ControlPlaneEndpoint" , config .Spec .ClusterConfiguration .ControlPlaneEndpoint )
931934 }
932935
933936 // If there are no ClusterName defined in ClusterConfiguration, use Cluster.Name
934937 if config .Spec .ClusterConfiguration .ClusterName == "" {
935938 config .Spec .ClusterConfiguration .ClusterName = cluster .Name
936- log .Info ("Altering ClusterConfiguration" , "ClusterName" , config .Spec .ClusterConfiguration .ClusterName )
939+ log .V ( 3 ). Info ("Altering ClusterConfiguration.ClusterName " , "ClusterName" , config .Spec .ClusterConfiguration .ClusterName )
937940 }
938941
939942 // If there are no Network settings defined in ClusterConfiguration, use ClusterNetwork settings, if defined
940943 if cluster .Spec .ClusterNetwork != nil {
941944 if config .Spec .ClusterConfiguration .Networking .DNSDomain == "" && cluster .Spec .ClusterNetwork .ServiceDomain != "" {
942945 config .Spec .ClusterConfiguration .Networking .DNSDomain = cluster .Spec .ClusterNetwork .ServiceDomain
943- log .Info ("Altering ClusterConfiguration" , "DNSDomain" , config .Spec .ClusterConfiguration .Networking .DNSDomain )
946+ log .V ( 3 ). Info ("Altering ClusterConfiguration.Networking.DNSDomain " , "DNSDomain" , config .Spec .ClusterConfiguration .Networking .DNSDomain )
944947 }
945948 if config .Spec .ClusterConfiguration .Networking .ServiceSubnet == "" &&
946949 cluster .Spec .ClusterNetwork .Services != nil &&
947950 len (cluster .Spec .ClusterNetwork .Services .CIDRBlocks ) > 0 {
948951 config .Spec .ClusterConfiguration .Networking .ServiceSubnet = cluster .Spec .ClusterNetwork .Services .String ()
949- log .Info ("Altering ClusterConfiguration" , "ServiceSubnet" , config .Spec .ClusterConfiguration .Networking .ServiceSubnet )
952+ log .V ( 3 ). Info ("Altering ClusterConfiguration.Networking.ServiceSubnet " , "ServiceSubnet" , config .Spec .ClusterConfiguration .Networking .ServiceSubnet )
950953 }
951954 if config .Spec .ClusterConfiguration .Networking .PodSubnet == "" &&
952955 cluster .Spec .ClusterNetwork .Pods != nil &&
953956 len (cluster .Spec .ClusterNetwork .Pods .CIDRBlocks ) > 0 {
954957 config .Spec .ClusterConfiguration .Networking .PodSubnet = cluster .Spec .ClusterNetwork .Pods .String ()
955- log .Info ("Altering ClusterConfiguration" , "PodSubnet" , config .Spec .ClusterConfiguration .Networking .PodSubnet )
958+ log .V ( 3 ). Info ("Altering ClusterConfiguration.Networking.PodSubnet " , "PodSubnet" , config .Spec .ClusterConfiguration .Networking .PodSubnet )
956959 }
957960 }
958961
959962 // If there are no KubernetesVersion settings defined in ClusterConfiguration, use Version from machine, if defined
960963 if config .Spec .ClusterConfiguration .KubernetesVersion == "" && machine .Spec .Version != nil {
961964 config .Spec .ClusterConfiguration .KubernetesVersion = * machine .Spec .Version
962- log .Info ("Altering ClusterConfiguration" , "KubernetesVersion" , config .Spec .ClusterConfiguration .KubernetesVersion )
965+ log .V ( 3 ). Info ("Altering ClusterConfiguration.KubernetesVersion " , "KubernetesVersion" , config .Spec .ClusterConfiguration .KubernetesVersion )
963966 }
964967}
965968
@@ -998,7 +1001,7 @@ func (r *KubeadmConfigReconciler) storeBootstrapData(ctx context.Context, scope
9981001 if ! apierrors .IsAlreadyExists (err ) {
9991002 return errors .Wrapf (err , "failed to create bootstrap data secret for KubeadmConfig %s/%s" , scope .Config .Namespace , scope .Config .Name )
10001003 }
1001- log .Info ("bootstrap data secret for KubeadmConfig already exists, updating" , "secret" , secret . Name , "KubeadmConfig" , scope . Config . Name )
1004+ log .Info ("bootstrap data secret for KubeadmConfig already exists, updating" , "secret" , klog . KObj ( secret ) )
10021005 if err := r .Client .Update (ctx , secret ); err != nil {
10031006 return errors .Wrapf (err , "failed to update bootstrap data secret for KubeadmConfig %s/%s" , scope .Config .Namespace , scope .Config .Name )
10041007 }
0 commit comments