@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/apimachinery/pkg/runtime"
32
32
"k8s.io/apimachinery/pkg/types"
33
33
kerrors "k8s.io/apimachinery/pkg/util/errors"
34
+ "k8s.io/klog/v2"
34
35
"k8s.io/utils/pointer"
35
36
ctrl "sigs.k8s.io/controller-runtime"
36
37
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -101,7 +102,7 @@ type Scope struct {
101
102
// SetupWithManager sets up the reconciler with the Manager.
102
103
func (r * KubeadmConfigReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
103
104
if r .KubeadmInitLock == nil {
104
- r .KubeadmInitLock = locking .NewControlPlaneInitMutex (ctrl . LoggerFrom ( ctx ). WithName ( "init-locker" ), mgr .GetClient ())
105
+ r .KubeadmInitLock = locking .NewControlPlaneInitMutex (mgr .GetClient ())
105
106
}
106
107
if r .remoteClientGetter == nil {
107
108
r .remoteClientGetter = remote .NewClusterClient
@@ -172,7 +173,7 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
172
173
if configOwner == nil {
173
174
return ctrl.Result {}, nil
174
175
}
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 ())
176
177
177
178
// Lookup the cluster the config owner is associated with
178
179
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
190
191
return ctrl.Result {}, err
191
192
}
192
193
194
+ ctx = ctrl .LoggerInto (ctx , log .WithValues ("cluster" , klog .KObj (cluster )))
195
+
193
196
if annotations .IsPaused (cluster , config ) {
194
197
log .Info ("Reconciliation is paused for this object" )
195
198
return ctrl.Result {}, nil
@@ -321,14 +324,14 @@ func (r *KubeadmConfigReconciler) rotateMachinePoolBootstrapToken(ctx context.Co
321
324
return ctrl.Result {}, err
322
325
}
323
326
if shouldRotate {
324
- log .V ( 2 ). Info ("Creating new bootstrap token" )
327
+ log .Info ("Creating new bootstrap token, the existing one should be rotated " )
325
328
token , err := createToken (ctx , remoteClient , r .TokenTTL )
326
329
if err != nil {
327
330
return ctrl.Result {}, errors .Wrapf (err , "failed to create new bootstrap token" )
328
331
}
329
332
330
333
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" )
332
335
333
336
// update the bootstrap data
334
337
return r .joinWorker (ctx , scope )
@@ -378,7 +381,7 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
378
381
}
379
382
}()
380
383
381
- scope .Info ("Creating BootstrapData for the init control plane" )
384
+ scope .Info ("Creating BootstrapData for the first control plane" )
382
385
383
386
// Nb. in this case JoinConfiguration should not be defined by users, but in case of misconfigurations, CABPK simply ignore it
384
387
@@ -495,6 +498,8 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
495
498
}
496
499
497
500
func (r * KubeadmConfigReconciler ) joinWorker (ctx context.Context , scope * Scope ) (ctrl.Result , error ) {
501
+ scope .Info ("Creating BootstrapData for the worker node" )
502
+
498
503
certificates := secret .NewCertificatesForWorker (scope .Config .Spec .JoinConfiguration .CACertPath )
499
504
err := certificates .Lookup (
500
505
ctx ,
@@ -534,8 +539,6 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
534
539
return ctrl.Result {}, errors .New ("Machine is a Worker, but JoinConfiguration.ControlPlane is set in the KubeadmConfig object" )
535
540
}
536
541
537
- scope .Info ("Creating BootstrapData for the worker node" )
538
-
539
542
verbosityFlag := ""
540
543
if scope .Config .Spec .Verbosity != nil {
541
544
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)
592
595
}
593
596
594
597
func (r * KubeadmConfigReconciler ) joinControlplane (ctx context.Context , scope * Scope ) (ctrl.Result , error ) {
598
+ scope .Info ("Creating BootstrapData for the joining control plane" )
599
+
595
600
if ! scope .ConfigOwner .IsControlPlaneMachine () {
596
601
return ctrl.Result {}, fmt .Errorf ("%s is not a valid control plane kind, only Machine is supported" , scope .ConfigOwner .GetKind ())
597
602
}
@@ -635,8 +640,6 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
635
640
return ctrl.Result {}, err
636
641
}
637
642
638
- scope .Info ("Creating BootstrapData for the join control plane" )
639
-
640
643
verbosityFlag := ""
641
644
if scope .Config .Spec .Verbosity != nil {
642
645
verbosityFlag = fmt .Sprintf ("--v %s" , strconv .Itoa (int (* scope .Config .Spec .Verbosity )))
@@ -889,7 +892,7 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(ctx context.Context, cluste
889
892
890
893
apiServerEndpoint = cluster .Spec .ControlPlaneEndpoint .String ()
891
894
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 )
893
896
}
894
897
895
898
// 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
905
908
}
906
909
907
910
config .Spec .JoinConfiguration .Discovery .BootstrapToken .Token = token
908
- log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" )
911
+ log .V ( 3 ). Info ("Altering JoinConfiguration.Discovery.BootstrapToken.Token " )
909
912
}
910
913
911
914
// If the BootstrapToken does not contain any CACertHashes then force skip CA Verification
@@ -927,39 +930,39 @@ func (r *KubeadmConfigReconciler) reconcileTopLevelObjectSettings(ctx context.Co
927
930
// then use Cluster's ControlPlaneEndpoint as a control plane endpoint for the Kubernetes cluster.
928
931
if config .Spec .ClusterConfiguration .ControlPlaneEndpoint == "" && cluster .Spec .ControlPlaneEndpoint .IsValid () {
929
932
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 )
931
934
}
932
935
933
936
// If there are no ClusterName defined in ClusterConfiguration, use Cluster.Name
934
937
if config .Spec .ClusterConfiguration .ClusterName == "" {
935
938
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 )
937
940
}
938
941
939
942
// If there are no Network settings defined in ClusterConfiguration, use ClusterNetwork settings, if defined
940
943
if cluster .Spec .ClusterNetwork != nil {
941
944
if config .Spec .ClusterConfiguration .Networking .DNSDomain == "" && cluster .Spec .ClusterNetwork .ServiceDomain != "" {
942
945
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 )
944
947
}
945
948
if config .Spec .ClusterConfiguration .Networking .ServiceSubnet == "" &&
946
949
cluster .Spec .ClusterNetwork .Services != nil &&
947
950
len (cluster .Spec .ClusterNetwork .Services .CIDRBlocks ) > 0 {
948
951
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 )
950
953
}
951
954
if config .Spec .ClusterConfiguration .Networking .PodSubnet == "" &&
952
955
cluster .Spec .ClusterNetwork .Pods != nil &&
953
956
len (cluster .Spec .ClusterNetwork .Pods .CIDRBlocks ) > 0 {
954
957
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 )
956
959
}
957
960
}
958
961
959
962
// If there are no KubernetesVersion settings defined in ClusterConfiguration, use Version from machine, if defined
960
963
if config .Spec .ClusterConfiguration .KubernetesVersion == "" && machine .Spec .Version != nil {
961
964
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 )
963
966
}
964
967
}
965
968
@@ -998,7 +1001,7 @@ func (r *KubeadmConfigReconciler) storeBootstrapData(ctx context.Context, scope
998
1001
if ! apierrors .IsAlreadyExists (err ) {
999
1002
return errors .Wrapf (err , "failed to create bootstrap data secret for KubeadmConfig %s/%s" , scope .Config .Namespace , scope .Config .Name )
1000
1003
}
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 ) )
1002
1005
if err := r .Client .Update (ctx , secret ); err != nil {
1003
1006
return errors .Wrapf (err , "failed to update bootstrap data secret for KubeadmConfig %s/%s" , scope .Config .Namespace , scope .Config .Name )
1004
1007
}
0 commit comments