Skip to content

Commit f433eba

Browse files
Fixed cert update race condition
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
1 parent f430ff3 commit f433eba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/rotator/rotator.go

+12
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ func AddRotator(mgr manager.Manager, cr *CertRotator) error {
176176
needLeaderElection: cr.RequireLeaderElection,
177177
refreshCertIfNeededDelegate: cr.refreshCertIfNeeded,
178178
fieldOwner: cr.FieldOwner,
179+
certsMounted: cr.certsMounted,
180+
enableReadinessCheck: cr.EnableReadinessCheck,
179181
}
180182
if err := addController(mgr, reconciler, cr.controllerName); err != nil {
181183
return err
@@ -251,6 +253,10 @@ type CertRotator struct {
251253
CertName string
252254
KeyName string
253255

256+
// EnableReadinessCheck if true, reconcilation loop will wait for controller-runtime's
257+
// runnable to finish execution.
258+
EnableReadinessCheck bool
259+
254260
certsMounted chan struct{}
255261
certsNotMounted chan struct{}
256262
wasCAInjected *atomic.Bool
@@ -743,6 +749,8 @@ type ReconcileWH struct {
743749
needLeaderElection bool
744750
refreshCertIfNeededDelegate func() (bool, error)
745751
fieldOwner string
752+
certsMounted chan struct{}
753+
enableReadinessCheck bool
746754
}
747755

748756
// Reconcile reads that state of the cluster for a validatingwebhookconfiguration
@@ -752,6 +760,10 @@ func (r *ReconcileWH) Reconcile(ctx context.Context, request reconcile.Request)
752760
return reconcile.Result{}, nil
753761
}
754762

763+
if r.enableReadinessCheck {
764+
<-r.certsMounted
765+
}
766+
755767
if !r.cache.WaitForCacheSync(ctx) {
756768
return reconcile.Result{}, errors.New("cache not ready")
757769
}

0 commit comments

Comments
 (0)