mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
kubelet/container: Update the cache interface.
This commit is contained in:
parent
26f8bc1a68
commit
a5e6bea9b5
@ -42,15 +42,15 @@ type FakeRuntime struct {
|
||||
}
|
||||
|
||||
type FakeRuntimeCache struct {
|
||||
runtime Runtime
|
||||
getter podsGetter
|
||||
}
|
||||
|
||||
func NewFakeRuntimeCache(runtime Runtime) RuntimeCache {
|
||||
return &FakeRuntimeCache{runtime}
|
||||
func NewFakeRuntimeCache(getter podsGetter) RuntimeCache {
|
||||
return &FakeRuntimeCache{getter}
|
||||
}
|
||||
|
||||
func (f *FakeRuntimeCache) GetPods() ([]*Pod, error) {
|
||||
return f.runtime.GetPods(false)
|
||||
return f.getter.GetPods(false)
|
||||
}
|
||||
|
||||
func (f *FakeRuntimeCache) ForceUpdateIfOlder(time.Time) error {
|
||||
|
@ -32,16 +32,16 @@ type RuntimeCache interface {
|
||||
ForceUpdateIfOlder(time.Time) error
|
||||
}
|
||||
|
||||
// NewRuntimeCache creates a container runtime cache.
|
||||
func NewRuntimeCache(runtime Runtime) (RuntimeCache, error) {
|
||||
pods, err := runtime.GetPods(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// TODO(yifan): The duplication of this type (another definition is in dockertools)
|
||||
// will be resolved when we removed the docker cache.
|
||||
type podsGetter interface {
|
||||
GetPods(bool) ([]*Pod, error)
|
||||
}
|
||||
|
||||
// NewRuntimeCache creates a container runtime cache.
|
||||
func NewRuntimeCache(getter podsGetter) (RuntimeCache, error) {
|
||||
return &runtimeCache{
|
||||
runtime: runtime,
|
||||
cacheTime: time.Now(),
|
||||
pods: pods,
|
||||
getter: getter,
|
||||
updating: false,
|
||||
}, nil
|
||||
}
|
||||
@ -49,7 +49,7 @@ func NewRuntimeCache(runtime Runtime) (RuntimeCache, error) {
|
||||
type runtimeCache struct {
|
||||
sync.Mutex
|
||||
// The underlying container runtime used to update the cache.
|
||||
runtime Runtime
|
||||
getter podsGetter
|
||||
// Last time when cache was updated.
|
||||
cacheTime time.Time
|
||||
// The content of the cache.
|
||||
@ -90,7 +90,7 @@ func (r *runtimeCache) ForceUpdateIfOlder(minExpectedCacheTime time.Time) error
|
||||
}
|
||||
|
||||
func (r *runtimeCache) updateCache() error {
|
||||
pods, err := r.runtime.GetPods(false)
|
||||
pods, err := r.getter.GetPods(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -105,7 +105,7 @@ func (r *runtimeCache) startUpdatingCache() {
|
||||
run := true
|
||||
for run {
|
||||
time.Sleep(defaultUpdateInterval)
|
||||
pods, err := r.runtime.GetPods(false)
|
||||
pods, err := r.getter.GetPods(false)
|
||||
cacheTime := time.Now()
|
||||
if err != nil {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user