Skip to content

Commit a8c2fc0

Browse files
committed
Fix double secret fetching in BasicAuth processing
This commit addresses the performance issue where spec.secretRef was being fetched twice - once in extractAuthFromSecret and again in secrets.BasicAuthFromSecret. The fix moves BasicAuth processing directly into extractAuthFromSecret using the already-fetched secret data, eliminating the redundant API call. This aligns with the special nature of spec.secretRef that contains multiple authentication methods and follows the advice to not use runtime/secrets for special requirements as discussed in flux2#5433. Signed-off-by: cappyzawa <[email protected]>
1 parent 6e18c48 commit a8c2fc0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

internal/server/event_handlers.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ func extractAuthFromSecret(ctx context.Context, kubeClient client.Client, provid
344344
options = append(options, notifier.WithHeaders(headers))
345345
}
346346

347+
if user, ok := secret.Data["username"]; ok {
348+
if pass, ok := secret.Data["password"]; ok {
349+
options = append(options, notifier.WithUsername(strings.TrimSpace(string(user))))
350+
options = append(options, notifier.WithPassword(strings.TrimSpace(string(pass))))
351+
}
352+
}
353+
347354
return options, secret.Data, nil
348355
}
349356

@@ -404,12 +411,6 @@ func createNotifier(ctx context.Context, kubeClient client.Client, provider *api
404411
if val, ok := secretData[secrets.TokenKey]; ok {
405412
token = strings.TrimSpace(string(val))
406413
}
407-
408-
user, pass, err := secrets.BasicAuthFromSecret(ctx, kubeClient, provider.Spec.SecretRef.Name, provider.Namespace)
409-
if err == nil {
410-
options = append(options, notifier.WithUsername(user))
411-
options = append(options, notifier.WithPassword(pass))
412-
}
413414
}
414415

415416
if provider.Spec.ProxySecretRef != nil {

0 commit comments

Comments
 (0)