Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl: honor --cache-dir so that server resources and http-cache data are stored in the same location #91851

Merged
merged 1 commit into from Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -55,7 +55,10 @@ const (
flagHTTPCacheDir = "cache-dir"
)

var defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
var (
defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
defaultDiscoveryCacheParentDir = filepath.Join(homedir.HomeDir(), ".kube", "cache", "discovery")
)

// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
// and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages
Expand Down Expand Up @@ -224,14 +227,20 @@ func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, e
// double it just so we don't end up here again for a while. This config is only used for discovery.
config.Burst = 100

httpCacheDir, discoveryCacheParentDir := defaultCacheDir, defaultDiscoveryCacheParentDir

// retrieve a user-provided value for the "cache-dir"
// defaulting to ~/.kube/http-cache if no user-value is given.
httpCacheDir := defaultCacheDir
// override httpCacheDir and discoveryCacheDir if user-value is given.
if f.CacheDir != nil {
httpCacheDir = *f.CacheDir
if len(httpCacheDir) > 0 {
// override discoveryCacheDir default value so that server resources and http-cache data are stored in the same location
discoveryCacheParentDir = filepath.Join(filepath.Dir(httpCacheDir), "cache", "discovery")
}
}

discoveryCacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube", "cache", "discovery"), config.Host)
discoveryCacheDir := computeDiscoverCacheDir(discoveryCacheParentDir, config.Host)

return diskcached.NewCachedDiscoveryClientForConfig(config, discoveryCacheDir, httpCacheDir, time.Duration(10*time.Minute))
}

Expand Down