Skip to content

Commit

Permalink
add cleanup to write-values & lint to harmonise this flag (#2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
itscaro authored Jan 10, 2022
1 parent 346e318 commit c069fbf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
6 changes: 5 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (a *App) WriteValues(c WriteValuesConfigProvider) error {
ForceDownload: !run.helm.IsHelm3(),
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
SkipCleanup: c.SkipCleanup(),
}, func() {
ok, errs = a.writeValues(run, c)
})
Expand Down Expand Up @@ -307,6 +308,7 @@ func (a *App) Lint(c LintConfigProvider) error {
ForceDownload: true,
SkipRepos: c.SkipDeps(),
SkipDeps: c.SkipDeps(),
SkipCleanup: c.SkipCleanup(),
}, func() {
ok, lintErrs, errs = a.lint(run, c)
})
Expand Down Expand Up @@ -1560,7 +1562,8 @@ func (a *App) lint(r *Run, c LintConfigProvider) (bool, []error, []error) {
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 {
opts := &state.LintOpts{
Set: c.Set(),
Set: c.Set(),
SkipCleanup: c.SkipCleanup(),
}
lintErrs := subst.LintReleases(helm, c.Values(), args, c.Concurrency(), opts)
if len(lintErrs) == 1 {
Expand Down Expand Up @@ -1933,6 +1936,7 @@ func (a *App) writeValues(r *Run, c WriteValuesConfigProvider) (bool, []error) {
opts := &state.WriteValuesOpts{
Set: c.Set(),
OutputFileTemplate: c.OutputFileTemplate(),
SkipCleanup: c.SkipCleanup(),
}
errs = st.WriteReleasesValues(helm, c.Values(), opts)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type LintConfigProvider interface {
Values() []string
Set() []string
SkipDeps() bool
SkipCleanup() bool

concurrencyConfig
}
Expand Down Expand Up @@ -189,6 +190,7 @@ type WriteValuesConfigProvider interface {
Set() []string
OutputFileTemplate() string
SkipDeps() bool
SkipCleanup() bool
IncludeTransitiveNeeds() bool
}

Expand Down
72 changes: 33 additions & 39 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (st *HelmState) prepareSyncReleases(helm helmexec.Interface, additionalValu
}

releases := []*ReleaseSpec{}
for i, _ := range st.Releases {
for i := range st.Releases {
releases = append(releases, &st.Releases[i])
}

Expand Down Expand Up @@ -766,15 +766,13 @@ func (st *HelmState) SyncReleases(affectedReleases *AffectedReleases, helm helme

preps, prepErrs := st.prepareSyncReleases(helm, additionalValues, workerLimit, opts)

defer func() {
if opts.SkipCleanup {
return
}

for _, p := range preps {
st.removeFiles(p.files)
}
}()
if !opts.SkipCleanup {
defer func() {
for _, p := range preps {
st.removeFiles(p.files)
}
}()
}

if len(prepErrs) > 0 {
return prepErrs
Expand Down Expand Up @@ -1339,13 +1337,9 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string,

flags, files, err := st.flagsForTemplate(helm, release, 0)

defer func() {
if opts.SkipCleanup {
return
}

st.removeFiles(files)
}()
if !opts.SkipCleanup {
defer st.removeFiles(files)
}

if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -1412,6 +1406,7 @@ func (st *HelmState) TemplateReleases(helm helmexec.Interface, outputDir string,
type WriteValuesOpts struct {
Set []string
OutputFileTemplate string
SkipCleanup bool
}

type WriteValuesOpt interface{ Apply(*WriteValuesOpts) }
Expand Down Expand Up @@ -1441,9 +1436,9 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu
return []error{err}
}

defer func() {
st.removeFiles(generatedFiles)
}()
if !opts.SkipCleanup {
defer st.removeFiles(generatedFiles)
}

for _, value := range additionalValues {
valfile, err := filepath.Abs(value)
Expand Down Expand Up @@ -1506,7 +1501,8 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu
}

type LintOpts struct {
Set []string
Set []string
SkipCleanup bool
}

type LintOpt interface{ Apply(*LintOpts) }
Expand Down Expand Up @@ -1540,7 +1536,9 @@ func (st *HelmState) LintReleases(helm helmexec.Interface, additionalValues []st

flags, files, err := st.flagsForLint(helm, &release, 0)

defer st.removeFiles(files)
if !opts.SkipCleanup {
defer st.removeFiles(files)
}

if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -1625,7 +1623,7 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu
}

releases := []*ReleaseSpec{}
for i, _ := range st.Releases {
for i := range st.Releases {
if !st.Releases[i].Desired() {
continue
}
Expand Down Expand Up @@ -1790,13 +1788,11 @@ func (st *HelmState) createHelmContextWithWriter(spec *ReleaseSpec, w io.Writer)
}

type DiffOpts struct {
Context int
Output string
NoColor bool
Set []string

SkipCleanup bool

Context int
Output string
NoColor bool
Set []string
SkipCleanup bool
SkipDiffOnInstall bool
}

Expand All @@ -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)

defer func() {
if opts.SkipCleanup {
return
}

for _, p := range preps {
st.removeFiles(p.files)
}
}()
if !opts.SkipCleanup {
defer func() {
for _, p := range preps {
st.removeFiles(p.files)
}
}()
}

if len(prepErrs) > 0 {
return []ReleaseSpec{}, prepErrs
Expand Down

0 comments on commit c069fbf

Please sign in to comment.