@@ -76,9 +76,10 @@ type InitLocker interface {
7676
7777// KubeadmConfigReconciler reconciles a KubeadmConfig object.
7878type KubeadmConfigReconciler struct {
79- Client client.Client
80- Tracker * remote.ClusterCacheTracker
81- KubeadmInitLock InitLocker
79+ Client client.Client
80+ SecretCachingClient client.Client
81+ Tracker * remote.ClusterCacheTracker
82+ KubeadmInitLock InitLocker
8283
8384 // WatchFilterValue is the label value used to filter events prior to reconciliation.
8485 WatchFilterValue string
@@ -453,13 +454,15 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
453454 // Otherwise rely on certificates generated by the ControlPlane controller.
454455 // Note: A cluster does not have a ControlPlane reference when using standalone CP machines.
455456 if scope .Cluster .Spec .ControlPlaneRef == nil {
456- err = certificates .LookupOrGenerate (
457+ err = certificates .LookupOrGenerateCached (
457458 ctx ,
459+ r .SecretCachingClient ,
458460 r .Client ,
459461 util .ObjectKey (scope .Cluster ),
460462 * metav1 .NewControllerRef (scope .Config , bootstrapv1 .GroupVersion .WithKind ("KubeadmConfig" )))
461463 } else {
462- err = certificates .Lookup (ctx ,
464+ err = certificates .LookupCached (ctx ,
465+ r .SecretCachingClient ,
463466 r .Client ,
464467 util .ObjectKey (scope .Cluster ))
465468 }
@@ -531,8 +534,9 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
531534 scope .Info ("Creating BootstrapData for the worker node" )
532535
533536 certificates := secret .NewCertificatesForWorker (scope .Config .Spec .JoinConfiguration .CACertPath )
534- err := certificates .Lookup (
537+ err := certificates .LookupCached (
535538 ctx ,
539+ r .SecretCachingClient ,
536540 r .Client ,
537541 util .ObjectKey (scope .Cluster ),
538542 )
@@ -645,8 +649,9 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
645649 }
646650
647651 certificates := secret .NewControlPlaneJoinCerts (scope .Config .Spec .ClusterConfiguration )
648- err := certificates .Lookup (
652+ err := certificates .LookupCached (
649653 ctx ,
654+ r .SecretCachingClient ,
650655 r .Client ,
651656 util .ObjectKey (scope .Cluster ),
652657 )
@@ -1055,7 +1060,7 @@ func (r *KubeadmConfigReconciler) storeBootstrapData(ctx context.Context, scope
10551060// Ensure the bootstrap secret has the KubeadmConfig as a controller OwnerReference.
10561061func (r * KubeadmConfigReconciler ) ensureBootstrapSecretOwnersRef (ctx context.Context , scope * Scope ) error {
10571062 secret := & corev1.Secret {}
1058- err := r .Client .Get (ctx , client.ObjectKey {Namespace : scope .Config .Namespace , Name : scope .Config .Name }, secret )
1063+ err := r .SecretCachingClient .Get (ctx , client.ObjectKey {Namespace : scope .Config .Namespace , Name : scope .Config .Name }, secret )
10591064 if err != nil {
10601065 // If the secret has not been created yet return early.
10611066 if apierrors .IsNotFound (err ) {
0 commit comments