Skip to content

Commit

Permalink
VDS: Log and record Vault request failures
Browse files Browse the repository at this point in the history
  • Loading branch information
benashz committed Dec 8, 2023
1 parent 28be7b3 commit 6dafc2e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions controllers/vaultdynamicsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ func (r *VaultDynamicSecretReconciler) Reconcile(ctx context.Context, req ctrl.R
secretLease, staticCredsUpdated, err := r.syncSecret(ctx, vClient, o)
if err != nil {
_, jitter := computeMaxJitterWithPercent(requeueDurationOnError, 0.5)
horizon := requeueDurationOnError + time.Duration(jitter)
r.Recorder.Eventf(o, corev1.EventTypeWarning, consts.ReasonSecretSyncError,
"Failed to sync the secret, horizon=%s, err=%s", horizon, err)
return ctrl.Result{
RequeueAfter: requeueDurationOnError + time.Duration(jitter),
RequeueAfter: horizon,
}, nil
}

Expand Down Expand Up @@ -274,9 +277,10 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
}

method := o.Spec.RequestHTTPMethod
logger := log.FromContext(ctx).WithName("syncSecret")
if params != nil {
if !(method == http.MethodPost || method == http.MethodPut) {
log.FromContext(ctx).V(consts.LogLevelWarning).Info(
logger.V(consts.LogLevelWarning).Info(
"Params provided, ignoring specified method",
"requestHTTPMethod", o.Spec.RequestHTTPMethod)
}
Expand All @@ -286,6 +290,7 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
method = http.MethodGet
}

logger = logger.WithValues("path", path, "method", method)
switch method {
case http.MethodPut, http.MethodPost:
resp, err = c.Write(ctx, vault.NewWriteRequest(path, params))
Expand All @@ -296,6 +301,7 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
}

if err != nil {
logger.Error(err, "Vault request failed")
return nil, false, err
}

Expand Down Expand Up @@ -360,6 +366,7 @@ func (r *VaultDynamicSecretReconciler) syncSecret(ctx context.Context, c vault.C
}

if err := helpers.SyncSecret(ctx, r.Client, o, data); err != nil {
logger.Error(err, "Destination sync failed")
return nil, false, err
}

Expand Down

0 comments on commit 6dafc2e

Please sign in to comment.