Skip to content

Commit

Permalink
fix: remove temp helm chart cache dir afterwards
Browse files Browse the repository at this point in the history
  • Loading branch information
karlderkaefer committed Dec 14, 2024
1 parent 685c440 commit 3a88d70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ func (r *RegistryHelper) SetRandomHelmCacheDir() error {
return nil
}

func (r *RegistryHelper) RemoveTempHelmCacheDir() {
cacheDir := os.Getenv("HELM_REPOSITORY_CACHE")
configDir := os.Getenv("HELM_REPOSITORY_CONFIG")
if cacheDir != "" && strings.HasPrefix(cacheDir, "/tmp/helm_cache_") {
os.RemoveAll(cacheDir)
}
if configDir != "" && strings.HasPrefix(configDir, "/tmp/helm_config_") {
os.RemoveAll(filepath.Dir(configDir))
}
}

// GetRegistry returns the credential protected registry by hostname
func (r *RegistryHelper) GetRegistryByHostname(registry string) *RegistryInfo {
for _, registryInfo := range r.Registries {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func main() {
if err != nil {
log.Fatal("Unable to update registry info: ", err)
}
if registryHelper.config.UseRandomHelmCacheDir {
defer registryHelper.RemoveTempHelmCacheDir() // nolint: errcheck
}

if !*skipLoginAtStartFlag {
err := registryHelper.LoginAll()
Expand Down

0 comments on commit 3a88d70

Please sign in to comment.