Skip to content

Commit

Permalink
Issue #1446 - Delete helm temp directories (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmt authored Apr 12, 2019
1 parent 41a3352 commit ac3d12c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func GenerateManifests(appPath string, q *ManifestRequest) (*ManifestResponse, e
if err != nil {
return nil, err
}
defer h.Dispose()
targetObjs, err = h.Template(q.AppLabelValue, q.Namespace, q.ApplicationSource.Helm)
if err != nil {
if !helm.IsMissingDependencyErr(err) {
Expand Down Expand Up @@ -627,6 +628,7 @@ func (s *Service) GetAppDetails(ctx context.Context, q *RepoServerAppDetailsQuer
if err != nil {
return nil, err
}
defer h.Dispose()
params, err := h.GetParameters(q.valueFiles())
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Helm interface {
SetHome(path string)
// Init runs `helm init --client-only`
Init() error
// Dispose deletes temp resources
Dispose()
}

// NewHelmApp create a new wrapper to run commands on the `helm` command-line tool.
Expand All @@ -44,6 +46,7 @@ type helm struct {
home string
helmRepos []*argoappv1.HelmRepository
reposInitialized bool
tempDirs []string
}

// IsMissingDependencyErr tests if the error is related to a missing chart dependency
Expand Down Expand Up @@ -136,11 +139,22 @@ func (h *helm) Init() error {
return err
}
h.home = home
h.tempDirs = append(h.tempDirs, home)
}
_, err := h.helmCmd("init", "--client-only", "--skip-refresh")
return err
}

func (h *helm) Dispose() {
for i := range h.tempDirs {
err := os.RemoveAll(h.tempDirs[i])
if err != nil {
log.Warnf("Failed to delete temp directory %s", h.tempDirs[i])
}
}
h.tempDirs = []string{}
}

func (h *helm) GetParameters(valuesFiles []string) ([]*argoappv1.HelmParameter, error) {
out, err := h.helmCmd("inspect", "values", ".")
if err != nil {
Expand Down

0 comments on commit ac3d12c

Please sign in to comment.