Skip to content

Commit

Permalink
Move resource related variables outside for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
MM53 committed Sep 19, 2024
1 parent 98e0e8e commit 0598a07
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions controllers/vaultstaticsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@ func (r *VaultStaticSecretReconciler) streamStaticSecretEvents(ctx context.Conte
// status
r.Recorder.Eventf(o, corev1.EventTypeNormal, consts.ReasonEventWatcherStarted, "Started watching events")

specPathPattern := strings.Join([]string{o.Spec.Mount, o.Spec.Path}, "/")
if o.Spec.Type == consts.KVSecretTypeV2 {
specPathPattern = strings.Join([]string{o.Spec.Mount, "*", o.Spec.Path}, "/")
}

specNamespace := strings.Trim(o.Spec.Namespace, "/")
if o.Spec.Namespace == "" {
specNamespace = strings.Trim(wsClient.Namespace(), "/")
}

for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -465,15 +475,7 @@ func (r *VaultStaticSecretReconciler) streamStaticSecretEvents(ctx context.Conte
if modified {
namespace := strings.Trim(messageMap.Data.Namespace, "/")
path := messageMap.Data.Event.Metadata.Path
specPathPattern := strings.Join([]string{o.Spec.Mount, o.Spec.Path}, "/")

if o.Spec.Type == consts.KVSecretTypeV2 {
specPathPattern = strings.Join([]string{o.Spec.Mount, "*", o.Spec.Path}, "/")
}
specNamespace := strings.Trim(o.Spec.Namespace, "/")
if o.Spec.Namespace == "" {
specNamespace = strings.Trim(wsClient.Namespace(), "/")
}
logger.V(consts.LogLevelTrace).Info("modified Event received from Vault",
"namespace", namespace, "path", path, "spec.namespace", specNamespace,
"spec.path", specPathPattern)
Expand Down

0 comments on commit 0598a07

Please sign in to comment.