Skip to content

Commit bd8a3d2

Browse files
committed
fix
1 parent 6b8a499 commit bd8a3d2

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

controllers/vaultdynamicsecret_controller.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
150150
o.Status.VaultClientMeta.CacheKey = clientCacheKey.String()
151151
o.Status.VaultClientMeta.ID = vClient.ID()
152152

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+
153162
var syncReason string
154163
// doSync indicates that the controller should perform the secret sync,
155164
switch {
@@ -179,6 +188,12 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
179188
}
180189

181190
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+
)
182197
leaseID := o.Status.SecretLease.ID
183198
if !doSync && r.runtimePodUID != "" && r.runtimePodUID != o.Status.LastRuntimePodUID {
184199
// 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
272287
return ctrl.Result{RequeueAfter: computeHorizonWithJitter(requeueDurationOnError)}, nil
273288
}
274289

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-
284290
// sync the secret
285291
secretLease, staticCredsUpdated, err := r.syncSecret(ctx, vClient, o, transOption)
286292
if err != nil {
@@ -405,23 +411,6 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
405411
) (*secretsv1beta1.VaultSecretLease, bool, error) {
406412
logger := log.FromContext(ctx).WithName("syncSecret")
407413

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-
425414
resp, err := r.doVault(ctx, c, o)
426415
if err != nil {
427416
return nil, false, err
@@ -574,6 +563,12 @@ func (r *VaultDynamicSecretReconciler) awaitVaultSecretRotation(ctx context.Cont
574563
}
575564

576565
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+
577572
if r.runtimePodUID != "" {
578573
o.Status.LastRuntimePodUID = r.runtimePodUID
579574
}

0 commit comments

Comments
 (0)