From 7d0401af0e2d63091b473b4833d665220a56b357 Mon Sep 17 00:00:00 2001 From: Wyatt Jia Date: Thu, 30 Jun 2022 12:58:23 +0800 Subject: [PATCH] refactor: refactor helm validate and set default timeout --- internal/pkg/plugin/argocd/validate.go | 2 +- .../pkg/plugin/hashicorpvault/validate.go | 2 +- internal/pkg/plugin/helmgeneric/validate.go | 2 +- internal/pkg/plugin/jenkins/validate.go | 2 +- .../pkg/plugin/kubeprometheus/validate.go | 2 +- internal/pkg/plugin/openldap/validate.go | 2 +- internal/pkg/plugin/tekton/validate.go | 2 +- pkg/util/helm/validation.go | 19 +++++++++++-------- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/internal/pkg/plugin/argocd/validate.go b/internal/pkg/plugin/argocd/validate.go index e58205891..85a506cda 100644 --- a/internal/pkg/plugin/argocd/validate.go +++ b/internal/pkg/plugin/argocd/validate.go @@ -7,5 +7,5 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/internal/pkg/plugin/hashicorpvault/validate.go b/internal/pkg/plugin/hashicorpvault/validate.go index 6ca964e51..a17a0387a 100644 --- a/internal/pkg/plugin/hashicorpvault/validate.go +++ b/internal/pkg/plugin/hashicorpvault/validate.go @@ -7,5 +7,5 @@ import ( // validate the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/internal/pkg/plugin/helmgeneric/validate.go b/internal/pkg/plugin/helmgeneric/validate.go index a54ea3aba..ab8fa8bed 100644 --- a/internal/pkg/plugin/helmgeneric/validate.go +++ b/internal/pkg/plugin/helmgeneric/validate.go @@ -7,5 +7,5 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/internal/pkg/plugin/jenkins/validate.go b/internal/pkg/plugin/jenkins/validate.go index 269fed972..af315a26d 100644 --- a/internal/pkg/plugin/jenkins/validate.go +++ b/internal/pkg/plugin/jenkins/validate.go @@ -10,7 +10,7 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - errs := helm.Validate(opts.GetHelmParam()) + errs := helm.DefaultsAndValidate(opts.GetHelmParam()) if len(errs) != 0 { return errs } diff --git a/internal/pkg/plugin/kubeprometheus/validate.go b/internal/pkg/plugin/kubeprometheus/validate.go index f5df15e8c..365bdbe44 100644 --- a/internal/pkg/plugin/kubeprometheus/validate.go +++ b/internal/pkg/plugin/kubeprometheus/validate.go @@ -7,5 +7,5 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/internal/pkg/plugin/openldap/validate.go b/internal/pkg/plugin/openldap/validate.go index c08c7e8b5..0a261c7c4 100644 --- a/internal/pkg/plugin/openldap/validate.go +++ b/internal/pkg/plugin/openldap/validate.go @@ -7,5 +7,5 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/internal/pkg/plugin/tekton/validate.go b/internal/pkg/plugin/tekton/validate.go index 0e65e7c5b..fc992a2b8 100644 --- a/internal/pkg/plugin/tekton/validate.go +++ b/internal/pkg/plugin/tekton/validate.go @@ -7,5 +7,5 @@ import ( // validate validates the options provided by the core. func validate(opts *Options) []error { - return helm.Validate(opts.GetHelmParam()) + return helm.DefaultsAndValidate(opts.GetHelmParam()) } diff --git a/pkg/util/helm/validation.go b/pkg/util/helm/validation.go index 7eeabf7f1..77bdb535b 100644 --- a/pkg/util/helm/validation.go +++ b/pkg/util/helm/validation.go @@ -2,16 +2,19 @@ package helm import "github.com/devstream-io/devstream/pkg/util/validator" -func Validate(param *HelmParam) []error { - Defaults(param) - return validator.Struct(param) -} - -// Defaults set the default value with HelmParam. -// TODO(daniel-hutao): don't call this function insides the Validate() -func Defaults(param *HelmParam) { +// defaults set the default value with HelmParam. +func defaults(param *HelmParam) { if param.Chart.Timeout == "" { // Make the timeout be same as the default value for `--timeout` with `helm install/upgrade/rollback` param.Chart.Timeout = "5m0s" } } + +func validate(param *HelmParam) []error { + return validator.Struct(param) +} + +func DefaultsAndValidate(param *HelmParam) []error { + defaults(param) + return validate(param) +}