mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #979 from thockin/cleanups
Accumulated minor cleanups
This commit is contained in:
commit
3605e07800
@ -25,11 +25,11 @@ find_test_dirs() {
|
|||||||
find . -not \( \
|
find . -not \( \
|
||||||
\( \
|
\( \
|
||||||
-wholename './third_party' \
|
-wholename './third_party' \
|
||||||
-wholename './Godeps' \
|
-wholename './Godeps' \
|
||||||
-o -wholename './release' \
|
-o -wholename './release' \
|
||||||
-o -wholename './target' \
|
-o -wholename './target' \
|
||||||
-o -wholename '*/third_party/*' \
|
-o -wholename '*/third_party/*' \
|
||||||
-o -wholename '*/Godeps/*' \
|
-o -wholename '*/Godeps/*' \
|
||||||
-o -wholename '*/output/*' \
|
-o -wholename '*/output/*' \
|
||||||
\) -prune \
|
\) -prune \
|
||||||
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u | xargs -n1 printf "${KUBE_GO_PACKAGE}/%s\n"
|
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u | xargs -n1 printf "${KUBE_GO_PACKAGE}/%s\n"
|
||||||
|
@ -65,7 +65,7 @@ type Master struct {
|
|||||||
// New returns a new instance of Master connected to the given etcdServer.
|
// New returns a new instance of Master connected to the given etcdServer.
|
||||||
func New(c *Config) *Master {
|
func New(c *Config) *Master {
|
||||||
etcdClient := goetcd.NewClient(c.EtcdServers)
|
etcdClient := goetcd.NewClient(c.EtcdServers)
|
||||||
minionRegistry := minionRegistryMaker(c)
|
minionRegistry := makeMinionRegistry(c)
|
||||||
m := &Master{
|
m := &Master{
|
||||||
podRegistry: etcd.NewRegistry(etcdClient, minionRegistry),
|
podRegistry: etcd.NewRegistry(etcdClient, minionRegistry),
|
||||||
controllerRegistry: etcd.NewRegistry(etcdClient, minionRegistry),
|
controllerRegistry: etcd.NewRegistry(etcdClient, minionRegistry),
|
||||||
@ -78,7 +78,7 @@ func New(c *Config) *Master {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func minionRegistryMaker(c *Config) minion.Registry {
|
func makeMinionRegistry(c *Config) minion.Registry {
|
||||||
var minionRegistry minion.Registry
|
var minionRegistry minion.Registry
|
||||||
if c.Cloud != nil && len(c.MinionRegexp) > 0 {
|
if c.Cloud != nil && len(c.MinionRegexp) > 0 {
|
||||||
var err error
|
var err error
|
||||||
@ -105,8 +105,8 @@ func minionRegistryMaker(c *Config) minion.Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) {
|
func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) {
|
||||||
podCache := NewPodCache(podInfoGetter, m.podRegistry, time.Second*30)
|
podCache := NewPodCache(podInfoGetter, m.podRegistry)
|
||||||
go podCache.Loop()
|
go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30)
|
||||||
|
|
||||||
endpoints := endpoint.NewEndpointController(m.serviceRegistry, m.client)
|
endpoints := endpoint.NewEndpointController(m.serviceRegistry, m.client)
|
||||||
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
|
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
|
||||||
|
@ -18,13 +18,11 @@ package master
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
@ -36,17 +34,15 @@ type PodCache struct {
|
|||||||
pods pod.Registry
|
pods pod.Registry
|
||||||
// This is a map of pod id to a map of container name to the
|
// This is a map of pod id to a map of container name to the
|
||||||
podInfo map[string]api.PodInfo
|
podInfo map[string]api.PodInfo
|
||||||
period time.Duration
|
|
||||||
podLock sync.Mutex
|
podLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPodCache returns a new PodCache which watches container information registered in the given PodRegistry.
|
// 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{
|
return &PodCache{
|
||||||
containerInfo: info,
|
containerInfo: info,
|
||||||
pods: pods,
|
pods: pods,
|
||||||
podInfo: map[string]api.PodInfo{},
|
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)
|
|
||||||
}
|
|
||||||
|
@ -19,7 +19,6 @@ package master
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
"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) {
|
func TestPodCacheGet(t *testing.T) {
|
||||||
cache := NewPodCache(nil, nil, time.Second*1)
|
cache := NewPodCache(nil, nil)
|
||||||
|
|
||||||
expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
|
expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
|
||||||
cache.podInfo["foo"] = expected
|
cache.podInfo["foo"] = expected
|
||||||
@ -55,7 +54,7 @@ func TestPodCacheGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPodCacheGetMissing(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")
|
info, err := cache.GetPodInfo("host", "foo")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -71,7 +70,7 @@ func TestPodGetPodInfoGetter(t *testing.T) {
|
|||||||
fake := FakePodInfoGetter{
|
fake := FakePodInfoGetter{
|
||||||
data: expected,
|
data: expected,
|
||||||
}
|
}
|
||||||
cache := NewPodCache(&fake, nil, time.Second*1)
|
cache := NewPodCache(&fake, nil)
|
||||||
|
|
||||||
cache.updatePodInfo("host", "foo")
|
cache.updatePodInfo("host", "foo")
|
||||||
|
|
||||||
@ -103,7 +102,7 @@ func TestPodUpdateAllContainers(t *testing.T) {
|
|||||||
fake := FakePodInfoGetter{
|
fake := FakePodInfoGetter{
|
||||||
data: expected,
|
data: expected,
|
||||||
}
|
}
|
||||||
cache := NewPodCache(&fake, mockRegistry, time.Second*1)
|
cache := NewPodCache(&fake, mockRegistry)
|
||||||
|
|
||||||
cache.UpdateAllContainers()
|
cache.UpdateAllContainers()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user