feat: add helmfile template --validate (#1135)

This adds the ability for helmfile to call `helm template --validate` introduced in helm 3.

fixes #1105
This commit is contained in:
KUOKA Yusuke 2020-03-05 08:07:02 +09:00 committed by GitHub
parent 7c80a859fa
commit bf22502a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 2 deletions

View File

@ -236,6 +236,10 @@ func main() {
Value: 0,
Usage: "maximum number of concurrent downloads of release charts",
},
cli.BoolFlag{
Name: "validate",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at",
},
cli.BoolFlag{
Name: "skip-deps",
Usage: "skip running `helm repo update` and `helm dependency build`",
@ -528,6 +532,10 @@ func (c configImpl) OutputDir() string {
return c.c.String("output-dir")
}
func (c configImpl) Validate() bool {
return c.c.Bool("validate")
}
func (c configImpl) Concurrency() int {
return c.c.Int("concurrency")
}

View File

@ -1114,7 +1114,7 @@ func (a *App) template(r *Run, c TemplateConfigProvider) (bool, []error) {
opts := &state.TemplateOpts{
Set: c.Set(),
}
return subst.TemplateReleases(helm, c.OutputDir(), c.Values(), args, c.Concurrency(), opts)
return subst.TemplateReleases(helm, c.OutputDir(), c.Values(), args, c.Concurrency(), c.Validate(), opts)
}))
if templateErrs != nil && len(templateErrs) > 0 {

View File

@ -1877,6 +1877,10 @@ func (c configImpl) Args() string {
return "some args"
}
func (c configImpl) Validate() bool {
return true
}
func (c configImpl) SkipDeps() bool {
return true
}
@ -1894,6 +1898,7 @@ type applyConfig struct {
values []string
retainValuesFiles bool
set []string
validate bool
skipDeps bool
suppressSecrets bool
suppressDiff bool
@ -1917,6 +1922,10 @@ func (a applyConfig) Set() []string {
return a.set
}
func (a applyConfig) Validate() bool {
return a.validate
}
func (a applyConfig) SkipDeps() bool {
return a.skipDeps
}

View File

@ -125,6 +125,7 @@ type TemplateConfigProvider interface {
Values() []string
Set() []string
Validate() bool
SkipDeps() bool
OutputDir() string

View File

@ -760,7 +760,7 @@ func (o *TemplateOpts) Apply(opts *TemplateOpts) {
}
// TemplateReleases wrapper for executing helm template on the releases
func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, additionalValues []string, args []string, workerLimit int, opt ...TemplateOpt) []error {
func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, additionalValues []string, args []string, workerLimit int, validate bool, opt ...TemplateOpt) []error {
opts := &TemplateOpts{}
for _, o := range opt {
o.Apply(opts)
@ -832,6 +832,10 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string,
os.Mkdir(releaseOutputDir, 0755)
}
if validate {
flags = append(flags, "--validate")
}
if len(errs) == 0 {
if err := helm.TemplateRelease(release.Name, temp[release.Name], flags...); err != nil {
errs = append(errs, err)