From 0c850c1bfe411cf1fa45cd00a57fde34d91f6079 Mon Sep 17 00:00:00 2001 From: Teodor-Adrian Mihaescu Date: Fri, 18 Oct 2024 13:36:14 +0200 Subject: [PATCH] chore: fix linting --- internal/validators/secretref/secret_ref.go | 34 +++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/internal/validators/secretref/secret_ref.go b/internal/validators/secretref/secret_ref.go index 267dd7254..600cbc6fd 100644 --- a/internal/validators/secretref/secret_ref.go +++ b/internal/validators/secretref/secret_ref.go @@ -24,8 +24,8 @@ type Validator struct { } var ( - ErrSecretKeyNotFound = errors.New("one or more keys in a referenced Secret are missing") - ErrSecretRefNotFound = errors.New("one or more referenced Secrets are missing") + ErrSecretKeyNotFound = errors.New("one or more keys in a referenced Secret are missing") + ErrSecretRefNotFound = errors.New("one or more referenced Secrets are missing") ErrSecretRefMissingFields = errors.New("secret reference is missing field/s") ) @@ -44,7 +44,7 @@ func GetValue(ctx context.Context, client client.Reader, ref telemetryv1alpha1.S if err := checkForMissingFields(ref); err != nil { return nil, err } - + var secret corev1.Secret if err := client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: ref.Namespace}, &secret); err != nil { if apierrors.IsNotFound(err) { @@ -66,19 +66,21 @@ func GetValue(ctx context.Context, client client.Reader, ref telemetryv1alpha1.S func checkForMissingFields(ref telemetryv1alpha1.SecretKeyRef) error { var missingAttributes []string - if ref.Name == "" { - missingAttributes = append(missingAttributes, "Name") - } - if ref.Namespace == "" { - missingAttributes = append(missingAttributes, "Namespace") - } - if ref.Key == "" { - missingAttributes = append(missingAttributes, "Key") - } - - if len(missingAttributes) > 0 { - return fmt.Errorf("%w: %s", ErrSecretRefMissingFields, strings.Join(missingAttributes, ", ")) - } + if ref.Name == "" { + missingAttributes = append(missingAttributes, "Name") + } + + if ref.Namespace == "" { + missingAttributes = append(missingAttributes, "Namespace") + } + + if ref.Key == "" { + missingAttributes = append(missingAttributes, "Key") + } + + if len(missingAttributes) > 0 { + return fmt.Errorf("%w: %s", ErrSecretRefMissingFields, strings.Join(missingAttributes, ", ")) + } return nil }