mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 22:20:18 +00:00
Change PodWorkers to have desired cache.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
type DockerCache interface {
|
||||
RunningContainers() (DockerContainers, error)
|
||||
ForceUpdateIfOlder(time.Time) error
|
||||
}
|
||||
|
||||
func NewDockerCache(client DockerInterface) (DockerCache, error) {
|
||||
@@ -49,6 +50,9 @@ type dockerCache struct {
|
||||
updatingThreadStopTime time.Time
|
||||
}
|
||||
|
||||
// Ensure that dockerCache abides by the DockerCache interface.
|
||||
var _ DockerCache = new(dockerCache)
|
||||
|
||||
func (d *dockerCache) RunningContainers() (DockerContainers, error) {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
@@ -69,6 +73,20 @@ func (d *dockerCache) RunningContainers() (DockerContainers, error) {
|
||||
return d.containers, nil
|
||||
}
|
||||
|
||||
func (d *dockerCache) ForceUpdateIfOlder(minExpectedCacheTime time.Time) error {
|
||||
d.lock.Lock()
|
||||
defer d.lock.Unlock()
|
||||
if d.cacheTime.Before(minExpectedCacheTime) {
|
||||
containers, err := GetKubeletDockerContainers(d.client, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.containers = containers
|
||||
d.cacheTime = time.Now()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *dockerCache) startUpdatingCache() {
|
||||
run := true
|
||||
for run {
|
||||
|
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
@@ -246,3 +247,7 @@ func NewFakeDockerCache(client DockerInterface) DockerCache {
|
||||
func (f *FakeDockerCache) RunningContainers() (DockerContainers, error) {
|
||||
return GetKubeletDockerContainers(f.client, false)
|
||||
}
|
||||
|
||||
func (f *FakeDockerCache) ForceUpdateIfOlder(time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user