Skip to content

Commit

Permalink
controller/k8stools: add more error context to GetGredFromSecret
Browse files Browse the repository at this point in the history
It should help to debug failed e2e tests

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Sep 24, 2024
1 parent 1cf6435 commit 27ad7e1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions internal/controller/operator/factory/k8stools/secret_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ func LoadBasicAuthSecret(ctx context.Context, rclient client.Client, ns string,
return bac, nil
}

func extractCredKey(secret *corev1.Secret, sel *corev1.SecretKeySelector) (string, error) {
if s, ok := secret.Data[sel.Key]; ok {
return maybeTrimSpace(string(s)), nil
}
return "", &KeyNotFoundError{sel.Key, sel.Name, "secret"}
}

// GetCredFromSecret fetch content of secret by given key
func GetCredFromSecret(
ctx context.Context,
Expand All @@ -139,7 +132,10 @@ func GetCredFromSecret(
}
cache[cacheKey] = s
}
return extractCredKey(s, sel)
if s, ok := s.Data[sel.Key]; ok {
return maybeTrimSpace(string(s)), nil
}
return "", &KeyNotFoundError{sel.Key, cacheKey, "secret"}
}

// GetCredFromConfigMap fetches content of configmap by given key
Expand Down

0 comments on commit 27ad7e1

Please sign in to comment.