From d90ffa6d20b008441d19beca011019cc00d3ce5a Mon Sep 17 00:00:00 2001 From: bennsimon Date: Tue, 3 Sep 2024 20:02:52 +0300 Subject: [PATCH] add lint-mode flag to helm template Signed-off-by: bennsimon --- pkg/action/action.go | 3 ++- pkg/action/install.go | 4 +++- pkg/action/upgrade.go | 2 +- pkg/cmd/template.go | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index bcf6ca8ef..13458a9c7 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -177,7 +177,7 @@ func splitAndDeannotate(postrendered string) (map[string]string, error) { // TODO: As part of the refactor the duplicate code in cmd/helm/template.go should be removed // // This code has to do with writing files to disk. -func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrenderer.PostRenderer, interactWithRemote, enableDNS, hideSecret bool) ([]*release.Hook, *bytes.Buffer, string, error) { +func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrenderer.PostRenderer, interactWithRemote, enableDNS, hideSecret bool, lintMode bool) ([]*release.Hook, *bytes.Buffer, string, error) { var hs []*release.Hook b := bytes.NewBuffer(nil) @@ -213,6 +213,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, e.EnableDNS = enableDNS e.CustomTemplateFuncs = cfg.CustomTemplateFuncs + e.LintMode = lintMode files, err2 = e.Render(ch, values) } diff --git a/pkg/action/install.go b/pkg/action/install.go index 5ae12904d..ef816a627 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -131,6 +131,8 @@ type Install struct { // Lock to control raceconditions when the process receives a SIGTERM Lock sync.Mutex goroutineCount atomic.Int32 + // In LintMode, some 'required' template values may be missing, so don't fail + LintMode bool } // ChartPathOptions captures common options used for controlling chart paths @@ -342,7 +344,7 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma rel := i.createRelease(chrt, vals, i.Labels) var manifestDoc *bytes.Buffer - rel.Hooks, manifestDoc, rel.Info.Notes, err = i.cfg.renderResources(chrt, valuesToRender, i.ReleaseName, i.OutputDir, i.SubNotes, i.UseReleaseName, i.IncludeCRDs, i.PostRenderer, interactWithRemote, i.EnableDNS, i.HideSecret) + rel.Hooks, manifestDoc, rel.Info.Notes, err = i.cfg.renderResources(chrt, valuesToRender, i.ReleaseName, i.OutputDir, i.SubNotes, i.UseReleaseName, i.IncludeCRDs, i.PostRenderer, interactWithRemote, i.EnableDNS, i.HideSecret, i.LintMode) // Even for errors, attach this if available if manifestDoc != nil { rel.Manifest = manifestDoc.String() diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 3688adf0e..04bb152ce 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -284,7 +284,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin interactWithRemote = true } - hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", "", u.SubNotes, false, false, u.PostRenderer, interactWithRemote, u.EnableDNS, u.HideSecret) + hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", "", u.SubNotes, false, false, u.PostRenderer, interactWithRemote, u.EnableDNS, u.HideSecret, false) if err != nil { return nil, nil, false, err } diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 81c112d51..6a7ac2c1e 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -203,6 +203,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for Capabilities.KubeVersion") f.StringSliceVarP(&extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions (multiple can be specified)") f.BoolVar(&client.UseReleaseName, "release-name", false, "use release name in the output-dir path.") + f.BoolVar(&client.LintMode, "lint-mode", false, "ignore missing 'required' template values.") bindPostRenderFlag(cmd, &client.PostRenderer, settings) return cmd