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 {
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 {

View File

@ -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