Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
helm/v3: garbage collect anonymous index files
Browse files Browse the repository at this point in the history
The Helm 3 dependency update generates anonymous index files on every
run without garbage collecting them, resulting in spurious disk usage.
Configuring a temporary cache directory and garbage collecting it after
the dependency update is not possible as the download manager seems to
ignore the configured repository cache path and always create the index
file in the XDG cache directory.

Instead we detect the any anonymous index filex by their "=" suffix and
delete if they are older than 2m.
  • Loading branch information
hiddeco committed May 20, 2020
1 parent 56fb84a commit baa18ad
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/helm/v3/dependency.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package v3

import (
"os"
"path/filepath"
"strings"
"time"

"helm.sh/helm/v3/pkg/downloader"

"github.com/fluxcd/helm-operator/pkg/utils"
)

func (h *HelmV3) DependencyUpdate(chartPath string) error {
defer garbageCollect(repositoryCache, time.Second * 120)
out := utils.NewLogWriter(h.logger)
man := &downloader.Manager{
Out: out,
Expand All @@ -17,3 +23,22 @@ func (h *HelmV3) DependencyUpdate(chartPath string) error {
}
return man.Update()
}

// garbageCollect walks over the files in the given path and deletes
// any anonymous index file with a mod time older than the given
// duration.
func garbageCollect(path string, olderThan time.Duration) {
now := time.Now()
filepath.Walk(path, func(p string, f os.FileInfo, err error) error {
if f.IsDir() {
return nil
}
if strings.HasSuffix(f.Name(), "=-index.yaml") || strings.HasSuffix(f.Name(), "=-charts.txt") {
if diff := now.Sub(f.ModTime()); diff > olderThan {
return os.Remove(p)
}
return nil
}
return nil
})
}

0 comments on commit baa18ad

Please sign in to comment.