Skip to content

Commit

Permalink
feat: add fix for secrets
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <[email protected]>
  • Loading branch information
RealAnna committed Sep 27, 2023
1 parent 40fa7d2 commit cff4bb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions metrics-operator/api/v1alpha3/keptnmetricsprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ func (p *KeptnMetricsProvider) HasSecretDefined() bool {
return true
}

func (p *KeptnMetricsProvider) HasSecretKeyDefined() bool {
if p.Spec.SecretKeyRef == (corev1.SecretKeySelector{}) {
return false
}
//if the secret name exists the secret is defined
if strings.TrimSpace(p.Spec.SecretKeyRef.Key) == "" {
return false
}
return true
}

func (p *KeptnMetricsProvider) GetType() string {
if p.Spec.Type != "" {
return p.Spec.Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Error struct {
}

func getDTSecret(ctx context.Context, provider metricsapi.KeptnMetricsProvider, k8sClient client.Client) (string, error) {
if !provider.HasSecretDefined() {
if !provider.HasSecretDefined() || !provider.HasSecretKeyDefined() {
return "", ErrSecretKeyRefNotDefined
}
dtCredsSecret := &corev1.Secret{}
Expand Down
2 changes: 1 addition & 1 deletion test/prometheus/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
data:
password: dG9vcg== # toor
user: YWRtaW4= # admin
type: Opaque
type: Opaque

0 comments on commit cff4bb2

Please sign in to comment.