Add helmfile state validate policy (#592)

This commit is contained in:
yxxhero
2022-12-21 10:49:31 +08:00
committed by GitHub
parent 8ec51c2826
commit d8d0bf830a
9 changed files with 148 additions and 8 deletions
+25
View File
@@ -29,6 +29,7 @@ import (
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/maputil"
"github.com/helmfile/helmfile/pkg/policy"
"github.com/helmfile/helmfile/pkg/remote"
"github.com/helmfile/helmfile/pkg/tmpl"
)
@@ -83,6 +84,30 @@ type ReleaseSetSpec struct {
LockFile string `yaml:"lockFilePath,omitempty"`
}
// helmStateAlias is helm state alias
type helmStateAlias HelmState
func (hs HelmState) MarshalYAML() (interface{}, error) {
return helmStateAlias(hs), nil
}
func (hs *HelmState) UnmarshalYAML(value *yaml.Node) error {
helmStateInfo := make(map[string]interface{})
if err := value.DecodeWithOptions(&helmStateInfo, yaml.DecodeOptions{KnownFields: true}); err != nil {
return err
}
isStrict, err := policy.Checker(helmStateInfo)
if err != nil {
if isStrict {
return err
}
fmt.Fprintf(os.Stderr, "Warning: %v\n", err)
}
return value.DecodeWithOptions((*helmStateAlias)(hs), yaml.DecodeOptions{KnownFields: true})
}
// HelmState structure for the helmfile
type HelmState struct {
basePath string