kubelet/container: Update the cache interface.

This commit is contained in:
Yifan Gu 2015-04-13 17:38:18 -07:00
parent 26f8bc1a68
commit a5e6bea9b5
2 changed files with 16 additions and 16 deletions

View File

@ -42,15 +42,15 @@ type FakeRuntime struct {
} }
type FakeRuntimeCache struct { type FakeRuntimeCache struct {
runtime Runtime getter podsGetter
} }
func NewFakeRuntimeCache(runtime Runtime) RuntimeCache { func NewFakeRuntimeCache(getter podsGetter) RuntimeCache {
return &FakeRuntimeCache{runtime} return &FakeRuntimeCache{getter}
} }
func (f *FakeRuntimeCache) GetPods() ([]*Pod, error) { func (f *FakeRuntimeCache) GetPods() ([]*Pod, error) {
return f.runtime.GetPods(false) return f.getter.GetPods(false)
} }
func (f *FakeRuntimeCache) ForceUpdateIfOlder(time.Time) error { func (f *FakeRuntimeCache) ForceUpdateIfOlder(time.Time) error {

View File

@ -32,16 +32,16 @@ type RuntimeCache interface {
ForceUpdateIfOlder(time.Time) error ForceUpdateIfOlder(time.Time) error
} }
// NewRuntimeCache creates a container runtime cache. // TODO(yifan): The duplication of this type (another definition is in dockertools)
func NewRuntimeCache(runtime Runtime) (RuntimeCache, error) { // will be resolved when we removed the docker cache.
pods, err := runtime.GetPods(false) type podsGetter interface {
if err != nil { GetPods(bool) ([]*Pod, error)
return nil, err
} }
// NewRuntimeCache creates a container runtime cache.
func NewRuntimeCache(getter podsGetter) (RuntimeCache, error) {
return &runtimeCache{ return &runtimeCache{
runtime: runtime, getter: getter,
cacheTime: time.Now(),
pods: pods,
updating: false, updating: false,
}, nil }, nil
} }
@ -49,7 +49,7 @@ func NewRuntimeCache(runtime Runtime) (RuntimeCache, error) {
type runtimeCache struct { type runtimeCache struct {
sync.Mutex sync.Mutex
// The underlying container runtime used to update the cache. // The underlying container runtime used to update the cache.
runtime Runtime getter podsGetter
// Last time when cache was updated. // Last time when cache was updated.
cacheTime time.Time cacheTime time.Time
// The content of the cache. // The content of the cache.
@ -90,7 +90,7 @@ func (r *runtimeCache) ForceUpdateIfOlder(minExpectedCacheTime time.Time) error
} }
func (r *runtimeCache) updateCache() error { func (r *runtimeCache) updateCache() error {
pods, err := r.runtime.GetPods(false) pods, err := r.getter.GetPods(false)
if err != nil { if err != nil {
return err return err
} }
@ -105,7 +105,7 @@ func (r *runtimeCache) startUpdatingCache() {
run := true run := true
for run { for run {
time.Sleep(defaultUpdateInterval) time.Sleep(defaultUpdateInterval)
pods, err := r.runtime.GetPods(false) pods, err := r.getter.GetPods(false)
cacheTime := time.Now() cacheTime := time.Now()
if err != nil { if err != nil {
continue continue