Skip to content

Commit ae9464d

Browse files
authored
Merge pull request #8940 from sbueringer/pr-cache-secrets
🌱 cache secrets in KCP, CABPK and ClusterCacheTracker
2 parents 1ab3cde + 3e20833 commit ae9464d

File tree

22 files changed

+535
-218
lines changed

22 files changed

+535
-218
lines changed

bootstrap/kubeadm/controllers/alias.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const (
3838

3939
// KubeadmConfigReconciler reconciles a KubeadmConfig object.
4040
type KubeadmConfigReconciler struct {
41-
Client client.Client
41+
Client client.Client
42+
SecretCachingClient client.Client
4243

4344
Tracker *remote.ClusterCacheTracker
4445

@@ -52,9 +53,10 @@ type KubeadmConfigReconciler struct {
5253
// SetupWithManager sets up the reconciler with the Manager.
5354
func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5455
return (&kubeadmbootstrapcontrollers.KubeadmConfigReconciler{
55-
Client: r.Client,
56-
Tracker: r.Tracker,
57-
WatchFilterValue: r.WatchFilterValue,
58-
TokenTTL: r.TokenTTL,
56+
Client: r.Client,
57+
SecretCachingClient: r.SecretCachingClient,
58+
Tracker: r.Tracker,
59+
WatchFilterValue: r.WatchFilterValue,
60+
TokenTTL: r.TokenTTL,
5961
}).SetupWithManager(ctx, mgr, options)
6062
}

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ type InitLocker interface {
7676

7777
// KubeadmConfigReconciler reconciles a KubeadmConfig object.
7878
type 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.
10561061
func (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) {

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_reconciler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func TestKubeadmConfigReconciler(t *testing.T) {
4747
}(cluster, machine, config, ns)
4848

4949
reconciler := KubeadmConfigReconciler{
50-
Client: env,
50+
Client: env,
51+
SecretCachingClient: secretCachingClient,
5152
}
5253
t.Log("Calling reconcile should requeue")
5354
result, err := reconciler.Reconcile(ctx, ctrl.Request{

0 commit comments

Comments
 (0)