Skip to content

Commit e024c75

Browse files
committed
move maybeAddFinalizer out of updateStatus func into the Reconcile func
1 parent 4a4dc56 commit e024c75

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

controllers/vaultdynamicsecret_controller.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
123123
return ctrl.Result{}, r.handleDeletion(ctx, o)
124124
}
125125

126+
if addedFinalizer, err := maybeAddFinalizer(ctx, r.Client, o, vaultDynamicSecretFinalizer); err != nil {
127+
return ctrl.Result{}, err
128+
} else if addedFinalizer {
129+
// the finalizer was added, requeue the request.
130+
return ctrl.Result{Requeue: true}, nil
131+
}
132+
126133
r.referenceCache.Set(SecretTransformation, req.NamespacedName,
127134
helpers.GetTransformationRefObjKeys(
128135
o.Spec.Destination.Transformation, o.Namespace)...)
@@ -150,15 +157,6 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
150157
o.Status.VaultClientMeta.CacheKey = clientCacheKey.String()
151158
o.Status.VaultClientMeta.ID = vClient.ID()
152159

153-
if !o.Spec.AllowStaticCreds && 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-
162160
var syncReason string
163161
// doSync indicates that the controller should perform the secret sync,
164162
switch {
@@ -188,12 +186,6 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
188186
}
189187

190188
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-
)
197189
leaseID := o.Status.SecretLease.ID
198190
if !doSync && r.runtimePodUID != "" && r.runtimePodUID != o.Status.LastRuntimePodUID {
199191
// don't take part in the thundering herd on start up,
@@ -563,12 +555,6 @@ func (r *VaultDynamicSecretReconciler) awaitVaultSecretRotation(ctx context.Cont
563555
}
564556

565557
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-
572558
if r.runtimePodUID != "" {
573559
o.Status.LastRuntimePodUID = r.runtimePodUID
574560
}
@@ -579,8 +565,7 @@ func (r *VaultDynamicSecretReconciler) updateStatus(ctx context.Context, o *secr
579565
"Failed to update the resource's status, err=%s", err)
580566
}
581567

582-
_, err := maybeAddFinalizer(ctx, r.Client, o, vaultDynamicSecretFinalizer)
583-
return err
568+
return nil
584569
}
585570

586571
func (r *VaultDynamicSecretReconciler) getVaultSecretLease(resp *api.Secret) *secretsv1beta1.VaultSecretLease {

0 commit comments

Comments
 (0)