feat: add template args to be used for template and within apply

Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
This commit is contained in:
Kerstin Albers 2025-02-06 14:31:33 +01:00
parent 1b8f2871f6
commit 2e52967d68
9 changed files with 39 additions and 1 deletions

View File

@ -42,6 +42,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.BoolVar(&applyOptions.StripTrailingCR, "strip-trailing-cr", false, "strip trailing carriage return on input")
f.StringVar(&applyOptions.DiffArgs, "diff-args", "", `pass args to helm helm-diff`)
f.StringVar(&applyOptions.SyncArgs, "sync-args", "", `pass args to helm upgrade`)
f.StringVar(&applyOptions.TemplateArgs, "template-args", "", `pass args to helm template`)
f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec")
f.BoolVar(&applyOptions.SkipCleanup, "skip-cleanup", false, "Stop cleaning up temporary values generated by helmfile and helm-secrets. Useful for debugging. Don't use in production for security")
f.BoolVar(&applyOptions.SkipCRDs, "skip-crds", false, "if set, no CRDs will be installed on sync. By default, CRDs are installed if not already present")

View File

@ -50,6 +50,7 @@ func NewTemplateCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.BoolVar(&templateOptions.SkipSchemaValidation, "skip-schema-validation", false, `pass skip-schema-validation to "helm template" or "helm upgrade --install"`)
f.StringVar(&templateOptions.KubeVersion, "kube-version", "", `pass --kube-version to "helm template". Overrides kubeVersion in helmfile.yaml`)
f.StringArrayVar(&templateOptions.ShowOnly, "show-only", nil, `pass --show-only to "helm template"`)
f.StringVar(&templateOptions.TemplateArgs, "template-args", "", `pass args to helm template`)
return cmd
}

View File

@ -187,6 +187,8 @@ helmDefaults:
- "--suppress-secrets"
syncArgs:
- "--labels=app.kubernetes.io/managed-by=helmfile"
templateArgs:
- "--dry-run=server"
# verify the chart before upgrading (only works with packaged charts not directories) (default false)
verify: true
keyring: path/to/keyring.gpg

View File

@ -236,6 +236,7 @@ func (a *App) Template(c TemplateConfigProvider) error {
Set: c.Set(),
Values: c.Values(),
KubeVersion: c.KubeVersion(),
TemplateArgs: c.TemplateArgs(),
}, func() {
ok, errs = a.template(run, c)
})
@ -406,6 +407,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
Validate: c.Validate(),
Concurrency: c.Concurrency(),
IncludeTransitiveNeeds: c.IncludeNeeds(),
TemplateArgs: c.TemplateArgs(),
}, func() {
matched, updated, es := a.apply(run, c)

View File

@ -2109,6 +2109,7 @@ type configImpl struct {
includeTransitiveNeeds bool
skipCharts bool
kubeVersion string
templateArgs string
}
func (c configImpl) Selectors() []string {
@ -2207,6 +2208,10 @@ func (c configImpl) KubeVersion() string {
return c.kubeVersion
}
func (c configImpl) TemplateArgs() string {
return c.templateArgs
}
func (c configImpl) SkipSchemaValidation() bool {
return c.skipSchemaValidation
}
@ -2246,6 +2251,7 @@ type applyConfig struct {
skipDiffOnInstall bool
syncArgs string
diffArgs string
templateArgs string
logger *zap.SugaredLogger
wait bool
waitRetries int
@ -2398,6 +2404,10 @@ func (a applyConfig) DiffArgs() string {
return a.diffArgs
}
func (a applyConfig) TemplateArgs() string {
return a.templateArgs
}
// helmfile-template-only flags
func (a applyConfig) IncludeCRDs() bool {
return a.includeCRDs

View File

@ -79,6 +79,7 @@ type ApplyConfigProvider interface {
DiffArgs() string
SyncArgs() string
TemplateArgs() string
SyncReleaseLabels() bool
@ -232,6 +233,7 @@ type TemplateConfigProvider interface {
NoHooks() bool
KubeVersion() string
ShowOnly() []string
TemplateArgs() string
DAGConfig

View File

@ -68,11 +68,13 @@ type ApplyOptions struct {
SyncArgs string
// HideNotes is the hide notes flag
HideNotes bool
// TakeOwnership is true if the ownership should be taken
TakeOwnership bool
SyncReleaseLabels bool
// TemplateArgs is the list of arguments to pass to helm template
TemplateArgs string
}
// NewApply creates a new Apply
@ -273,3 +275,8 @@ func (a *ApplyImpl) TakeOwnership() bool {
func (a *ApplyImpl) SyncReleaseLabels() bool {
return a.ApplyOptions.SyncReleaseLabels
}
// TemplateArgs returns the TemplateArgs.
func (a *ApplyImpl) TemplateArgs() string {
return a.ApplyOptions.TemplateArgs
}

View File

@ -44,6 +44,8 @@ type TemplateOptions struct {
KubeVersion string
// Propagate '--show-only` to helm template
ShowOnly []string
// TemplateArgs
TemplateArgs string
}
// NewTemplateOptions creates a new Apply
@ -158,3 +160,8 @@ func (t *TemplateImpl) KubeVersion() string {
func (t *TemplateImpl) ShowOnly() []string {
return t.TemplateOptions.ShowOnly
}
// TemplateArgs returns the TemplateArgs
func (t *TemplateImpl) TemplateArgs() string {
return t.TemplateOptions.TemplateArgs
}

View File

@ -1160,6 +1160,7 @@ type ChartPrepareOptions struct {
KubeVersion string
Set []string
Values []string
TemplateArgs string
// Delete wait
DeleteWait bool
DeleteTimeout int
@ -1337,6 +1338,10 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
chartifyOpts.Validate = opts.Validate
if (helmfileCommand == "template" || helmfileCommand == "apply") && opts.TemplateArgs != "" {
chartifyOpts.TemplateArgs = opts.TemplateArgs
}
chartifyOpts.KubeVersion = st.getKubeVersion(release, opts.KubeVersion)
chartifyOpts.ApiVersions = st.getApiVersions(release)
@ -1543,6 +1548,7 @@ type TemplateOpts struct {
ShowOnly []string
// Propagate '--skip-schema-validation' to helmv3 template and helm install
SkipSchemaValidation bool
TemplateArgs string
}
type TemplateOpt interface{ Apply(*TemplateOpts) }