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

Commit

Permalink
Merge pull request #422 from fluxcd/helm/gc-dep-update
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed May 21, 2020
2 parents 05067b9 + a93c2d4 commit 1d9f181
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/helm/v3/dependency.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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 {
// Garbage collect before the dependency update so that
// anonymous files from previous runs are cleared, with
// a safe guard time offset to not touch any files in
// use.
garbageCollect(repositoryCache, time.Second * 120)
out := utils.NewLogWriter(h.logger)
man := &downloader.Manager{
Out: out,
Expand All @@ -17,3 +27,21 @@ 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 err != nil || f.IsDir() {
return nil
}
if strings.HasSuffix(f.Name(), "=-index.yaml") || strings.HasSuffix(f.Name(), "=-charts.txt") {
if now.Sub(f.ModTime()) > olderThan {
return os.Remove(p)
}
}
return nil
})
}

0 comments on commit 1d9f181

Please sign in to comment.