Correctly respect the KUBECACHEDIR env var (#2551)

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
mine
Marcus Noble 2024-02-22 00:54:25 +00:00 committed by GitHub
parent dae2590e0f
commit d06ab6407b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
@ -499,8 +500,13 @@ func (a *APIClient) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
return nil, err
}
httpCacheDir := filepath.Join(mustHomeDir(), ".kube", "http-cache")
discCacheDir := filepath.Join(mustHomeDir(), ".kube", "cache", "discovery", toHostDir(cfg.Host))
baseCacheDir := os.Getenv("KUBECACHEDIR")
if baseCacheDir == "" {
baseCacheDir = filepath.Join(mustHomeDir(), ".kube", "cache")
}
httpCacheDir := filepath.Join(baseCacheDir, "http")
discCacheDir := filepath.Join(baseCacheDir, "discovery", toHostDir(cfg.Host))
c, err := disk.NewCachedDiscoveryClientForConfig(cfg, discCacheDir, httpCacheDir, cacheExpiry)
if err != nil {