@@ -150,6 +150,15 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
150
150
o .Status .VaultClientMeta .CacheKey = clientCacheKey .String ()
151
151
o .Status .VaultClientMeta .ID = vClient .ID ()
152
152
153
+ if o .Status .LastGeneration != o .GetGeneration () && o .Status .SecretLease .ID == "" {
154
+ logger .Info ("short circuting sync, initial generation with empty lease" )
155
+ o .Status .LastGeneration = o .GetGeneration ()
156
+ if err := r .updateStatus (ctx , o ); err != nil {
157
+ return ctrl.Result {}, err
158
+ }
159
+ return ctrl.Result {RequeueAfter : computeHorizonWithJitter (requeueDurationOnError )}, nil
160
+ }
161
+
153
162
var syncReason string
154
163
// doSync indicates that the controller should perform the secret sync,
155
164
switch {
@@ -179,6 +188,12 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
179
188
}
180
189
181
190
doSync := syncReason != ""
191
+ logger .Info ("Reconciling" ,
192
+ "generation" , o .GetGeneration (),
193
+ "lastGeneration" , o .Status .LastGeneration ,
194
+ "leaseID" , o .Status .SecretLease .ID ,
195
+ "doSync" , doSync ,
196
+ )
182
197
leaseID := o .Status .SecretLease .ID
183
198
if ! doSync && r .runtimePodUID != "" && r .runtimePodUID != o .Status .LastRuntimePodUID {
184
199
// don't take part in the thundering herd on start up,
@@ -272,15 +287,6 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
272
287
return ctrl.Result {RequeueAfter : computeHorizonWithJitter (requeueDurationOnError )}, nil
273
288
}
274
289
275
- if ! doSync && o .Status .SecretLease .ID != "" && o .Status .LastGeneration > 0 && o .Status .LastRenewalTime > 0 &&
276
- ! r .SyncRegistry .Has (req .NamespacedName ) && r .isRenewableLease (& o .Status .SecretLease , o , true ) {
277
- horizon , inWindow := computeRelativeHorizonWithJitter (o , staticCredsJitterHorizon )
278
- if ! inWindow {
279
- logger .V (consts .LogLevelDebug ).Info ("Skipping sync, lease already exists" )
280
- return ctrl.Result {RequeueAfter : horizon }, nil
281
- }
282
- }
283
-
284
290
// sync the secret
285
291
secretLease , staticCredsUpdated , err := r .syncSecret (ctx , vClient , o , transOption )
286
292
if err != nil {
@@ -405,23 +411,6 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
405
411
) (* secretsv1beta1.VaultSecretLease , bool , error ) {
406
412
logger := log .FromContext (ctx ).WithName ("syncSecret" )
407
413
408
- // check if lease already exists
409
- //if o.Status.SecretLease.ID != "" {
410
- // logger.V(consts.LogLevelDebug).Info("Lease already exists", "leaseID", o.Status.SecretLease.ID)
411
- // // if the lease is renewable, renew it
412
- // if o.Status.SecretLease.Renewable {
413
- // secretLease, err := r.renewLease(ctx, c, o)
414
- // if err != nil {
415
- // logger.Error(err, "Failed to renew lease")
416
- // return nil, false, err
417
- // }
418
- // o.Status.SecretLease = *secretLease
419
- // return secretLease, false, nil
420
- // } else {
421
- // return &o.Status.SecretLease, false, nil
422
- // }
423
- //}
424
-
425
414
resp , err := r .doVault (ctx , c , o )
426
415
if err != nil {
427
416
return nil , false , err
@@ -574,6 +563,12 @@ func (r *VaultDynamicSecretReconciler) awaitVaultSecretRotation(ctx context.Cont
574
563
}
575
564
576
565
func (r * VaultDynamicSecretReconciler ) updateStatus (ctx context.Context , o * secretsv1beta1.VaultDynamicSecret ) error {
566
+ logger := log .FromContext (ctx ).WithName ("updateStatus" )
567
+ logger .Info ("Updating status" ,
568
+ "settingLastGeneration" , o .GetGeneration (),
569
+ "existingLastGeneration" , o .Status .LastGeneration ,
570
+ )
571
+
577
572
if r .runtimePodUID != "" {
578
573
o .Status .LastRuntimePodUID = r .runtimePodUID
579
574
}
0 commit comments