Add support for --validate on chartify (#1960)

Apparently we needed to pass `--validate` on helm-template run by chartify when the targeted chart contains Capabilities.APIVersions in a chart template. Otherwise, you can never make such chart work with chartify, as at apply time helm template expressions that involved Capabilities.APIVersions are already nowhere.
This commit is contained in:
Yusuke Kuoka 2021-09-14 04:48:21 +09:00 committed by GitHub
parent 0f91f2c9cf
commit e1cabc82e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 7 deletions

2
go.mod
View File

@ -28,7 +28,7 @@ require (
github.com/spf13/cobra v1.1.1
github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939
github.com/urfave/cli v1.22.5
github.com/variantdev/chartify v0.8.9
github.com/variantdev/chartify v0.9.0
github.com/variantdev/dag v1.0.0
github.com/variantdev/vals v0.14.0
go.uber.org/multierr v1.6.0

2
go.sum
View File

@ -596,6 +596,8 @@ github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/variantdev/chartify v0.8.9 h1:kECyWario6UOShilDThKfuvk+FhXWjlFod/Cg/wTmVs=
github.com/variantdev/chartify v0.8.9/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
github.com/variantdev/chartify v0.9.0 h1:27Bh3RXqBYyev0Xa1JnfD/LWyZu3SL+iHr6ePMzHdMg=
github.com/variantdev/chartify v0.9.0/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
github.com/variantdev/dag v1.0.0 h1:7SFjATxHtrYV20P3tx53yNDBMegz6RT4jv8JPHqAHdM=
github.com/variantdev/dag v1.0.0/go.mod h1:pH1TQsNSLj2uxMo9NNl9zdGy01Wtn+/2MT96BrKmVyE=
github.com/variantdev/vals v0.14.0 h1:J+zX1DDLTQ35A198HChVkCwLfA/4OeKhSuZ5zjmgV0Q=

11
main.go
View File

@ -224,6 +224,11 @@ func main() {
Value: 0,
Usage: "maximum number of concurrent helm processes to run, 0 is unlimited",
},
cli.BoolFlag{
Name: "validate",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions",
},
cli.IntFlag{
Name: "context",
Value: 0,
@ -271,7 +276,7 @@ func main() {
},
cli.BoolFlag{
Name: "validate",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions",
},
cli.BoolFlag{
Name: "include-crds",
@ -445,6 +450,10 @@ func main() {
Value: 0,
Usage: "maximum number of concurrent helm processes to run, 0 is unlimited",
},
cli.BoolFlag{
Name: "validate",
Usage: "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requiers access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions",
},
cli.IntFlag{
Name: "context",
Value: 0,

View File

@ -172,6 +172,7 @@ func (a *App) Diff(c DiffConfigProvider) error {
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
IncludeCRDs: &includeCRDs,
Validate: c.Validate(),
}, func() {
msg, matched, affected, errs = a.diff(run, c)
})
@ -238,6 +239,7 @@ func (a *App) Template(c TemplateConfigProvider) error {
SkipDeps: c.SkipDeps(),
IncludeCRDs: &includeCRDs,
SkipCleanup: c.SkipCleanup(),
Validate: c.Validate(),
}, func() {
ok, errs = a.template(run, c)
})
@ -392,6 +394,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
WaitForJobs: c.WaitForJobs(),
IncludeCRDs: &includeCRDs,
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
Validate: c.Validate(),
}, func() {
matched, updated, es := a.apply(run, c)

View File

@ -57,6 +57,7 @@ type ApplyConfigProvider interface {
DiffOutput() string
RetainValuesFiles() bool
Validate() bool
SkipCleanup() bool
SkipDiffOnInstall() bool
@ -90,6 +91,7 @@ type DiffConfigProvider interface {
Values() []string
Set() []string
Validate() bool
SkipCRDs() bool
SkipDeps() bool

View File

@ -966,10 +966,13 @@ type ChartPrepareOptions struct {
SkipDeps bool
SkipResolve bool
SkipCleanup bool
IncludeCRDs *bool
Wait bool
WaitForJobs bool
OutputDir string
// Validate is a helm-3-only option. When it is set to true, it configures chartify to pass --validate to helm-template run by it.
// It's required when one of your chart relies on Capabilities.APIVersions in a template
Validate bool
IncludeCRDs *bool
Wait bool
WaitForJobs bool
OutputDir string
}
type chartPrepareResult struct {
@ -1142,9 +1145,10 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
if opts.IncludeCRDs != nil {
includeCRDs = *opts.IncludeCRDs
}
chartifyOpts.IncludeCRDs = includeCRDs
chartifyOpts.Validate = opts.Validate
out, err := c.Chartify(release.Name, chartPath, chartify.WithChartifyOpts(chartifyOpts))
if err != nil {
results <- &chartPrepareResult{err: err}