Skip to content

Commit

Permalink
[installer]: add recommended secret checks
Browse files Browse the repository at this point in the history
If field(s) not found, it returns a warning rather than an error
  • Loading branch information
Simon Emms committed Feb 22, 2022
1 parent 4820e80 commit 5d85a2d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions install/installer/pkg/cluster/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func checkKubernetesVersion(ctx context.Context, config *rest.Config, namespace
}

type checkSecretOpts struct {
RequiredFields []string
Validator func(*corev1.Secret) ([]ValidationError, error)
RequiredFields []string
RecommendedFields []string
Validator func(*corev1.Secret) ([]ValidationError, error)
}

type CheckSecretOpt func(*checkSecretOpts)
Expand All @@ -182,6 +183,12 @@ func CheckSecretRequiredData(entries ...string) CheckSecretOpt {
}
}

func CheckSecretRecommendedData(entries ...string) CheckSecretOpt {
return func(cso *checkSecretOpts) {
cso.RecommendedFields = append(cso.RecommendedFields, entries...)
}
}

func CheckSecretRule(validator func(*corev1.Secret) ([]ValidationError, error)) CheckSecretOpt {
return func(cso *checkSecretOpts) {
cso.Validator = validator
Expand Down Expand Up @@ -226,6 +233,15 @@ func CheckSecret(name string, opts ...CheckSecretOpt) ValidationCheck {
})
}
}
for _, k := range cfg.RecommendedFields {
_, ok := secret.Data[k]
if !ok {
res = append(res, ValidationError{
Message: fmt.Sprintf("secret %s has no %s entry", name, k),
Type: ValidationStatusWarning,
})
}
}

if cfg.Validator != nil {
vres, err := cfg.Validator(secret)
Expand Down

0 comments on commit 5d85a2d

Please sign in to comment.