mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 17:38:50 +00:00
fix: don't use docker config cache if it's empty
add one comment test: add unit test fix comments fix comments revert test change fix comments
This commit is contained in:
@@ -58,6 +58,10 @@ type CachingDockerConfigProvider struct {
|
||||
Provider DockerConfigProvider
|
||||
Lifetime time.Duration
|
||||
|
||||
// ShouldCache is an optional function that returns true if the specific config should be cached.
|
||||
// If nil, all configs are treated as cacheable.
|
||||
ShouldCache func(DockerConfig) bool
|
||||
|
||||
// cache fields
|
||||
cacheDockerConfig DockerConfig
|
||||
expiration time.Time
|
||||
@@ -96,7 +100,10 @@ func (d *CachingDockerConfigProvider) Provide(image string) DockerConfig {
|
||||
}
|
||||
|
||||
klog.V(2).Infof("Refreshing cache for provider: %v", reflect.TypeOf(d.Provider).String())
|
||||
d.cacheDockerConfig = d.Provider.Provide(image)
|
||||
d.expiration = time.Now().Add(d.Lifetime)
|
||||
return d.cacheDockerConfig
|
||||
config := d.Provider.Provide(image)
|
||||
if d.ShouldCache == nil || d.ShouldCache(config) {
|
||||
d.cacheDockerConfig = config
|
||||
d.expiration = time.Now().Add(d.Lifetime)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
Reference in New Issue
Block a user