add cleanup to write-values & lint to harmonise this flag (#2021)
This commit is contained in:
		
							parent
							
								
									346e318fd0
								
							
						
					
					
						commit
						c069fbf268
					
				|  | @ -258,6 +258,7 @@ func (a *App) WriteValues(c WriteValuesConfigProvider) error { | ||||||
| 			ForceDownload: !run.helm.IsHelm3(), | 			ForceDownload: !run.helm.IsHelm3(), | ||||||
| 			SkipRepos:     c.SkipDeps(), | 			SkipRepos:     c.SkipDeps(), | ||||||
| 			SkipDeps:      c.SkipDeps(), | 			SkipDeps:      c.SkipDeps(), | ||||||
|  | 			SkipCleanup:   c.SkipCleanup(), | ||||||
| 		}, func() { | 		}, func() { | ||||||
| 			ok, errs = a.writeValues(run, c) | 			ok, errs = a.writeValues(run, c) | ||||||
| 		}) | 		}) | ||||||
|  | @ -307,6 +308,7 @@ func (a *App) Lint(c LintConfigProvider) error { | ||||||
| 			ForceDownload: true, | 			ForceDownload: true, | ||||||
| 			SkipRepos:     c.SkipDeps(), | 			SkipRepos:     c.SkipDeps(), | ||||||
| 			SkipDeps:      c.SkipDeps(), | 			SkipDeps:      c.SkipDeps(), | ||||||
|  | 			SkipCleanup:   c.SkipCleanup(), | ||||||
| 		}, func() { | 		}, func() { | ||||||
| 			ok, lintErrs, errs = a.lint(run, c) | 			ok, lintErrs, errs = a.lint(run, c) | ||||||
| 		}) | 		}) | ||||||
|  | @ -1560,7 +1562,8 @@ func (a *App) lint(r *Run, c LintConfigProvider) (bool, []error, []error) { | ||||||
| 	if len(toLint) > 0 { | 	if len(toLint) > 0 { | ||||||
| 		_, templateErrs := withDAG(st, helm, a.Logger, state.PlanOptions{SelectedReleases: toLint, Reverse: false, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error { | 		_, templateErrs := withDAG(st, helm, a.Logger, state.PlanOptions{SelectedReleases: toLint, Reverse: false, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error { | ||||||
| 			opts := &state.LintOpts{ | 			opts := &state.LintOpts{ | ||||||
| 				Set: c.Set(), | 				Set:         c.Set(), | ||||||
|  | 				SkipCleanup: c.SkipCleanup(), | ||||||
| 			} | 			} | ||||||
| 			lintErrs := subst.LintReleases(helm, c.Values(), args, c.Concurrency(), opts) | 			lintErrs := subst.LintReleases(helm, c.Values(), args, c.Concurrency(), opts) | ||||||
| 			if len(lintErrs) == 1 { | 			if len(lintErrs) == 1 { | ||||||
|  | @ -1933,6 +1936,7 @@ func (a *App) writeValues(r *Run, c WriteValuesConfigProvider) (bool, []error) { | ||||||
| 		opts := &state.WriteValuesOpts{ | 		opts := &state.WriteValuesOpts{ | ||||||
| 			Set:                c.Set(), | 			Set:                c.Set(), | ||||||
| 			OutputFileTemplate: c.OutputFileTemplate(), | 			OutputFileTemplate: c.OutputFileTemplate(), | ||||||
|  | 			SkipCleanup:        c.SkipCleanup(), | ||||||
| 		} | 		} | ||||||
| 		errs = st.WriteReleasesValues(helm, c.Values(), opts) | 		errs = st.WriteReleasesValues(helm, c.Values(), opts) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -156,6 +156,7 @@ type LintConfigProvider interface { | ||||||
| 	Values() []string | 	Values() []string | ||||||
| 	Set() []string | 	Set() []string | ||||||
| 	SkipDeps() bool | 	SkipDeps() bool | ||||||
|  | 	SkipCleanup() bool | ||||||
| 
 | 
 | ||||||
| 	concurrencyConfig | 	concurrencyConfig | ||||||
| } | } | ||||||
|  | @ -189,6 +190,7 @@ type WriteValuesConfigProvider interface { | ||||||
| 	Set() []string | 	Set() []string | ||||||
| 	OutputFileTemplate() string | 	OutputFileTemplate() string | ||||||
| 	SkipDeps() bool | 	SkipDeps() bool | ||||||
|  | 	SkipCleanup() bool | ||||||
| 	IncludeTransitiveNeeds() bool | 	IncludeTransitiveNeeds() bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -464,7 +464,7 @@ func (st *HelmState) prepareSyncReleases(helm helmexec.Interface, additionalValu | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	releases := []*ReleaseSpec{} | 	releases := []*ReleaseSpec{} | ||||||
| 	for i, _ := range st.Releases { | 	for i := range st.Releases { | ||||||
| 		releases = append(releases, &st.Releases[i]) | 		releases = append(releases, &st.Releases[i]) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -766,15 +766,13 @@ func (st *HelmState) SyncReleases(affectedReleases *AffectedReleases, helm helme | ||||||
| 
 | 
 | ||||||
| 	preps, prepErrs := st.prepareSyncReleases(helm, additionalValues, workerLimit, opts) | 	preps, prepErrs := st.prepareSyncReleases(helm, additionalValues, workerLimit, opts) | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	if !opts.SkipCleanup { | ||||||
| 		if opts.SkipCleanup { | 		defer func() { | ||||||
| 			return | 			for _, p := range preps { | ||||||
| 		} | 				st.removeFiles(p.files) | ||||||
| 
 | 			} | ||||||
| 		for _, p := range preps { | 		}() | ||||||
| 			st.removeFiles(p.files) | 	} | ||||||
| 		} |  | ||||||
| 	}() |  | ||||||
| 
 | 
 | ||||||
| 	if len(prepErrs) > 0 { | 	if len(prepErrs) > 0 { | ||||||
| 		return prepErrs | 		return prepErrs | ||||||
|  | @ -1339,13 +1337,9 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, | ||||||
| 
 | 
 | ||||||
| 		flags, files, err := st.flagsForTemplate(helm, release, 0) | 		flags, files, err := st.flagsForTemplate(helm, release, 0) | ||||||
| 
 | 
 | ||||||
| 		defer func() { | 		if !opts.SkipCleanup { | ||||||
| 			if opts.SkipCleanup { | 			defer st.removeFiles(files) | ||||||
| 				return | 		} | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			st.removeFiles(files) |  | ||||||
| 		}() |  | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			errs = append(errs, err) | 			errs = append(errs, err) | ||||||
|  | @ -1412,6 +1406,7 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string, | ||||||
| type WriteValuesOpts struct { | type WriteValuesOpts struct { | ||||||
| 	Set                []string | 	Set                []string | ||||||
| 	OutputFileTemplate string | 	OutputFileTemplate string | ||||||
|  | 	SkipCleanup        bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type WriteValuesOpt interface{ Apply(*WriteValuesOpts) } | type WriteValuesOpt interface{ Apply(*WriteValuesOpts) } | ||||||
|  | @ -1441,9 +1436,9 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu | ||||||
| 			return []error{err} | 			return []error{err} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		defer func() { | 		if !opts.SkipCleanup { | ||||||
| 			st.removeFiles(generatedFiles) | 			defer st.removeFiles(generatedFiles) | ||||||
| 		}() | 		} | ||||||
| 
 | 
 | ||||||
| 		for _, value := range additionalValues { | 		for _, value := range additionalValues { | ||||||
| 			valfile, err := filepath.Abs(value) | 			valfile, err := filepath.Abs(value) | ||||||
|  | @ -1506,7 +1501,8 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type LintOpts struct { | type LintOpts struct { | ||||||
| 	Set []string | 	Set         []string | ||||||
|  | 	SkipCleanup bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type LintOpt interface{ Apply(*LintOpts) } | type LintOpt interface{ Apply(*LintOpts) } | ||||||
|  | @ -1540,7 +1536,9 @@ func (st *HelmState) LintReleases(helm helmexec.Interface, additionalValues []st | ||||||
| 
 | 
 | ||||||
| 		flags, files, err := st.flagsForLint(helm, &release, 0) | 		flags, files, err := st.flagsForLint(helm, &release, 0) | ||||||
| 
 | 
 | ||||||
| 		defer st.removeFiles(files) | 		if !opts.SkipCleanup { | ||||||
|  | 			defer st.removeFiles(files) | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			errs = append(errs, err) | 			errs = append(errs, err) | ||||||
|  | @ -1625,7 +1623,7 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	releases := []*ReleaseSpec{} | 	releases := []*ReleaseSpec{} | ||||||
| 	for i, _ := range st.Releases { | 	for i := range st.Releases { | ||||||
| 		if !st.Releases[i].Desired() { | 		if !st.Releases[i].Desired() { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  | @ -1790,13 +1788,11 @@ func (st *HelmState) createHelmContextWithWriter(spec *ReleaseSpec, w io.Writer) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type DiffOpts struct { | type DiffOpts struct { | ||||||
| 	Context int | 	Context           int | ||||||
| 	Output  string | 	Output            string | ||||||
| 	NoColor bool | 	NoColor           bool | ||||||
| 	Set     []string | 	Set               []string | ||||||
| 
 | 	SkipCleanup       bool | ||||||
| 	SkipCleanup bool |  | ||||||
| 
 |  | ||||||
| 	SkipDiffOnInstall bool | 	SkipDiffOnInstall bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1822,15 +1818,13 @@ func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []st | ||||||
| 
 | 
 | ||||||
| 	preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppressSecrets, showSecrets, opts) | 	preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppressSecrets, showSecrets, opts) | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	if !opts.SkipCleanup { | ||||||
| 		if opts.SkipCleanup { | 		defer func() { | ||||||
| 			return | 			for _, p := range preps { | ||||||
| 		} | 				st.removeFiles(p.files) | ||||||
| 
 | 			} | ||||||
| 		for _, p := range preps { | 		}() | ||||||
| 			st.removeFiles(p.files) | 	} | ||||||
| 		} |  | ||||||
| 	}() |  | ||||||
| 
 | 
 | ||||||
| 	if len(prepErrs) > 0 { | 	if len(prepErrs) > 0 { | ||||||
| 		return []ReleaseSpec{}, prepErrs | 		return []ReleaseSpec{}, prepErrs | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue