From edff5415247af12a7b2cbf66eb737cbca828dfaf Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 19 Aug 2014 17:33:54 -0700 Subject: [PATCH] Treat async loops the same. In the name of consistency, treat the PodCache loop the same as the EndpointController. --- pkg/master/master.go | 4 ++-- pkg/master/pod_cache.go | 12 +----------- pkg/master/pod_cache_test.go | 9 ++++----- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pkg/master/master.go b/pkg/master/master.go index a6129c71ca1..174d70b0781 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -105,8 +105,8 @@ func makeMinionRegistry(c *Config) minion.Registry { } func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) { - podCache := NewPodCache(podInfoGetter, m.podRegistry, time.Second*30) - go podCache.Loop() + podCache := NewPodCache(podInfoGetter, m.podRegistry) + go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30) endpoints := endpoint.NewEndpointController(m.serviceRegistry, m.client) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) diff --git a/pkg/master/pod_cache.go b/pkg/master/pod_cache.go index 1d7a36cef68..085cbcf8e64 100644 --- a/pkg/master/pod_cache.go +++ b/pkg/master/pod_cache.go @@ -18,13 +18,11 @@ package master import ( "sync" - "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" ) @@ -36,17 +34,15 @@ type PodCache struct { pods pod.Registry // This is a map of pod id to a map of container name to the podInfo map[string]api.PodInfo - period time.Duration podLock sync.Mutex } // NewPodCache returns a new PodCache which watches container information registered in the given PodRegistry. -func NewPodCache(info client.PodInfoGetter, pods pod.Registry, period time.Duration) *PodCache { +func NewPodCache(info client.PodInfoGetter, pods pod.Registry) *PodCache { return &PodCache{ containerInfo: info, pods: pods, podInfo: map[string]api.PodInfo{}, - period: period, } } @@ -87,9 +83,3 @@ func (p *PodCache) UpdateAllContainers() { } } } - -// Loop begins watching updates of container information. -// It runs forever, and is expected to be placed in a go routine. -func (p *PodCache) Loop() { - util.Forever(func() { p.UpdateAllContainers() }, p.period) -} diff --git a/pkg/master/pod_cache_test.go b/pkg/master/pod_cache_test.go index d176c31c485..9f369662bab 100644 --- a/pkg/master/pod_cache_test.go +++ b/pkg/master/pod_cache_test.go @@ -19,7 +19,6 @@ package master import ( "reflect" "testing" - "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" @@ -40,7 +39,7 @@ func (f *FakePodInfoGetter) GetPodInfo(host, id string) (api.PodInfo, error) { } func TestPodCacheGet(t *testing.T) { - cache := NewPodCache(nil, nil, time.Second*1) + cache := NewPodCache(nil, nil) expected := api.PodInfo{"foo": docker.Container{ID: "foo"}} cache.podInfo["foo"] = expected @@ -55,7 +54,7 @@ func TestPodCacheGet(t *testing.T) { } func TestPodCacheGetMissing(t *testing.T) { - cache := NewPodCache(nil, nil, time.Second*1) + cache := NewPodCache(nil, nil) info, err := cache.GetPodInfo("host", "foo") if err == nil { @@ -71,7 +70,7 @@ func TestPodGetPodInfoGetter(t *testing.T) { fake := FakePodInfoGetter{ data: expected, } - cache := NewPodCache(&fake, nil, time.Second*1) + cache := NewPodCache(&fake, nil) cache.updatePodInfo("host", "foo") @@ -103,7 +102,7 @@ func TestPodUpdateAllContainers(t *testing.T) { fake := FakePodInfoGetter{ data: expected, } - cache := NewPodCache(&fake, mockRegistry, time.Second*1) + cache := NewPodCache(&fake, mockRegistry) cache.UpdateAllContainers()