From a5e6bea9b5910a5c3b4c9e65895055512088fc81 Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Mon, 13 Apr 2015 17:38:18 -0700 Subject: [PATCH] kubelet/container: Update the cache interface. --- pkg/kubelet/container/fake_runtime.go | 8 ++++---- pkg/kubelet/container/runtime_cache.go | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/kubelet/container/fake_runtime.go b/pkg/kubelet/container/fake_runtime.go index e9ab0e882b9..02899a1ecb2 100644 --- a/pkg/kubelet/container/fake_runtime.go +++ b/pkg/kubelet/container/fake_runtime.go @@ -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 { diff --git a/pkg/kubelet/container/runtime_cache.go b/pkg/kubelet/container/runtime_cache.go index 6bda534df56..0c02e0a4b58 100644 --- a/pkg/kubelet/container/runtime_cache.go +++ b/pkg/kubelet/container/runtime_cache.go @@ -32,24 +32,24 @@ type RuntimeCache interface { ForceUpdateIfOlder(time.Time) error } +// 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(runtime Runtime) (RuntimeCache, error) { - pods, err := runtime.GetPods(false) - if err != nil { - return nil, err - } +func NewRuntimeCache(getter podsGetter) (RuntimeCache, error) { return &runtimeCache{ - runtime: runtime, - cacheTime: time.Now(), - pods: pods, - updating: false, + getter: getter, + updating: false, }, nil } 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