mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-20 09:05:26 +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 {
|
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 {
|
||||||
|
@ -32,24 +32,24 @@ type RuntimeCache interface {
|
|||||||
ForceUpdateIfOlder(time.Time) error
|
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.
|
// NewRuntimeCache creates a container runtime cache.
|
||||||
func NewRuntimeCache(runtime Runtime) (RuntimeCache, error) {
|
func NewRuntimeCache(getter podsGetter) (RuntimeCache, error) {
|
||||||
pods, err := runtime.GetPods(false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &runtimeCache{
|
return &runtimeCache{
|
||||||
runtime: runtime,
|
getter: getter,
|
||||||
cacheTime: time.Now(),
|
updating: false,
|
||||||
pods: pods,
|
|
||||||
updating: false,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user