feat: Add `helmfile apply --skip-cleanup` (#1571)

This deprecates the old `--retain-values` which was not working as intended.

Also see #1570 - there's now `--skip-cleanup` for `helmfile-template`, too.
This commit is contained in:
Yusuke Kuoka 2020-11-05 10:18:30 +09:00 committed by GitHub
parent 3899680672
commit 5a15b65b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 7 deletions

10
main.go
View File

@ -386,7 +386,11 @@ func main() {
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "retain-values-files", Name: "retain-values-files",
Usage: "Stop cleaning up values files passed to Helm. Together with --log-level=debug, you can manually rerun helm commands as Helmfile did for debugging purpose", Usage: "DEPRECATED: Use skip-cleanup instead",
},
cli.BoolFlag{
Name: "skip-cleanup",
Usage: "Stop cleaning up temporary values generated by helmfile and helm-secrets. Useful for debugging. Don't use in production for security",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "include-tests", Name: "include-tests",
@ -725,6 +729,10 @@ func (c configImpl) Context() int {
return c.c.Int("context") return c.c.Int("context")
} }
func (c configImpl) SkipCleanup() bool {
return c.c.Bool("skip-cleanup")
}
func (c configImpl) EmbedValues() bool { func (c configImpl) EmbedValues() bool {
return c.c.Bool("embed-values") return c.c.Bool("embed-values")
} }

View File

@ -296,7 +296,7 @@ func (a *App) Apply(c ApplyConfigProvider) error {
var opts []LoadOption var opts []LoadOption
opts = append(opts, SetRetainValuesFiles(c.RetainValuesFiles())) opts = append(opts, SetRetainValuesFiles(c.RetainValuesFiles() || c.SkipCleanup()))
err := a.ForEachState(func(run *Run) (ok bool, errs []error) { err := a.ForEachState(func(run *Run) (ok bool, errs []error) {
prepErr := run.withPreparedCharts("apply", state.ChartPrepareOptions{ prepErr := run.withPreparedCharts("apply", state.ChartPrepareOptions{
@ -1062,6 +1062,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
NoColor: c.NoColor(), NoColor: c.NoColor(),
Context: c.Context(), Context: c.Context(),
Set: c.Set(), Set: c.Set(),
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
} }
infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts) infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts)
@ -1151,6 +1152,7 @@ Do you really want to apply?
syncOpts := state.SyncOpts{ syncOpts := state.SyncOpts{
Set: c.Set(), Set: c.Set(),
SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(),
} }
return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), &syncOpts) return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), &syncOpts)
})) }))

View File

@ -2298,6 +2298,7 @@ type applyConfig struct {
retainValuesFiles bool retainValuesFiles bool
set []string set []string
validate bool validate bool
skipCleanup bool
skipDeps bool skipDeps bool
includeTests bool includeTests bool
suppressSecrets bool suppressSecrets bool
@ -2326,6 +2327,10 @@ func (a applyConfig) Validate() bool {
return a.validate return a.validate
} }
func (a applyConfig) SkipCleanup() bool {
return a.skipCleanup
}
func (a applyConfig) SkipDeps() bool { func (a applyConfig) SkipDeps() bool {
return a.skipDeps return a.skipDeps
} }

View File

@ -51,6 +51,7 @@ type ApplyConfigProvider interface {
Context() int Context() int
RetainValuesFiles() bool RetainValuesFiles() bool
SkipCleanup() bool
concurrencyConfig concurrencyConfig
interactive interactive

View File

@ -536,6 +536,7 @@ func (st *HelmState) DetectReleasesToBeDeleted(helm helmexec.Interface, releases
type SyncOpts struct { type SyncOpts struct {
Set []string Set []string
SkipCleanup bool
} }
type SyncOpt interface{ Apply(*SyncOpts) } type SyncOpt interface{ Apply(*SyncOpts) }
@ -1549,6 +1550,8 @@ type DiffOpts struct {
Context int Context int
NoColor bool NoColor bool
Set []string Set []string
SkipCleanup bool
} }
func (o *DiffOpts) Apply(opts *DiffOpts) { func (o *DiffOpts) Apply(opts *DiffOpts) {