Skip to content

Commit

Permalink
refactor: refactor helm validate and set default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattJia committed Jun 30, 2022
1 parent 8ab86a8 commit 7d0401a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/plugin/argocd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/hashicorpvault/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/helmgeneric/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/jenkins/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/plugin/kubeprometheus/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/openldap/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion internal/pkg/plugin/tekton/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
19 changes: 11 additions & 8 deletions pkg/util/helm/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 7d0401a

Please sign in to comment.