From bf3b34c2e9cf88b6a41a011ab61d5a5761af478e Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Tue, 1 Jul 2014 17:08:32 -0700 Subject: [PATCH] Allow master's pod info getter to be faked. Wire up in integration tests in futile attempt to make travis pass. --- cmd/apiserver/apiserver.go | 12 +++++++++-- cmd/integration/integration.go | 25 +++++++++++++++++++++- pkg/master/master.go | 38 +++++++++++++++------------------- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/cmd/apiserver/apiserver.go b/cmd/apiserver/apiserver.go index b38e761da59..584f3581488 100644 --- a/cmd/apiserver/apiserver.go +++ b/cmd/apiserver/apiserver.go @@ -21,8 +21,10 @@ package main import ( "flag" "net" + "net/http" "strconv" + "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -35,6 +37,7 @@ var ( apiPrefix = flag.String("api_prefix", "/api/v1beta1", "The prefix for API requests on the server. Default '/api/v1beta1'") cloudProvider = flag.String("cloud_provider", "", "The provider for cloud services. Empty string for no provider.") minionRegexp = flag.String("minion_regexp", "", "If non empty, and -cloud_provider is specified, a regular expression for matching minion VMs") + minionPort = flag.Uint("minion_port", 10250, "The port at which kubelet will be listening on the minions.") etcdServerList, machineList util.StringList ) @@ -68,11 +71,16 @@ func main() { } } + podInfoGetter := &client.HTTPPodInfoGetter{ + Client: http.DefaultClient, + Port: *minionPort, + } + var m *master.Master if len(etcdServerList) > 0 { - m = master.New(etcdServerList, machineList, cloud, *minionRegexp) + m = master.New(etcdServerList, machineList, podInfoGetter, cloud, *minionRegexp) } else { - m = master.NewMemoryServer(machineList, cloud) + m = master.NewMemoryServer(machineList, podInfoGetter, cloud) } glog.Fatal(m.Run(net.JoinHostPort(*address, strconv.Itoa(int(*port))), *apiPrefix)) diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 76ed5abc216..3368087270b 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -41,6 +41,29 @@ var ( fakeDocker1, fakeDocker2 kubelet.FakeDockerClient ) +type fakePodInfoGetter struct{} + +func (fakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error) { + // This is a horrible hack to get around the fact that we can't provide + // different port numbers per kubelet... + var c client.PodInfoGetter + switch host { + case "localhost": + c = &client.HTTPPodInfoGetter{ + Client: http.DefaultClient, + Port: 10250, + } + case "machine": + c = &client.HTTPPodInfoGetter{ + Client: http.DefaultClient, + Port: 10251, + } + default: + glog.Fatalf("Can't get info for: %v, %v", host, podID) + } + return c.GetPodInfo("localhost", podID) +} + func startComponents(manifestURL string) (apiServerURL string) { // Setup servers := []string{"http://localhost:4001"} @@ -48,7 +71,7 @@ func startComponents(manifestURL string) (apiServerURL string) { machineList := []string{"localhost", "machine"} // Master - m := master.New(servers, machineList, nil, "") + m := master.New(servers, machineList, fakePodInfoGetter{}, nil, "") apiserver := httptest.NewServer(m.ConstructHandler("/api/v1beta1")) controllerManager := controller.MakeReplicationManager(etcd.NewClient(servers), client.New(apiserver.URL, nil)) diff --git a/pkg/master/master.go b/pkg/master/master.go index 70dd71cec07..5b17457fcb3 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -44,53 +44,49 @@ type Master struct { } // Returns a memory (not etcd) backed apiserver. -func NewMemoryServer(minions []string, cloud cloudprovider.Interface) *Master { +func NewMemoryServer(minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface) *Master { m := &Master{ podRegistry: registry.MakeMemoryRegistry(), controllerRegistry: registry.MakeMemoryRegistry(), serviceRegistry: registry.MakeMemoryRegistry(), minionRegistry: registry.MakeMinionRegistry(minions), } - m.init(cloud) + m.init(cloud, podInfoGetter) return m } // Returns a new apiserver. -func New(etcdServers, minions []string, cloud cloudprovider.Interface, minionRegexp string) *Master { +func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string) *Master { etcdClient := etcd.NewClient(etcdServers) - var minionRegistry registry.MinionRegistry - if cloud != nil && len(minionRegexp) > 0 { - var err error - minionRegistry, err = registry.MakeCloudMinionRegistry(cloud, minionRegexp) - if err != nil { - glog.Errorf("Failed to initalize cloud minion registry reverting to static registry (%#v)", err) - minionRegistry = registry.MakeMinionRegistry(minions) - } - } else { - minionRegistry = registry.MakeMinionRegistry(minions) - } + minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp) m := &Master{ podRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry), controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry), serviceRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry), minionRegistry: minionRegistry, } - m.init(cloud) + m.init(cloud, podInfoGetter) return m } -func (m *Master) init(cloud cloudprovider.Interface) { - containerInfo := &client.HTTPPodInfoGetter{ - Client: http.DefaultClient, - Port: 10250, +func minionRegistryMaker(minions []string, cloud cloudprovider.Interface, minionRegexp string) registry.MinionRegistry { + if cloud != nil && len(minionRegexp) > 0 { + minionRegistry, err := registry.MakeCloudMinionRegistry(cloud, minionRegexp) + if err != nil { + glog.Errorf("Failed to initalize cloud minion registry reverting to static registry (%#v)", err) + } + return minionRegistry } + return registry.MakeMinionRegistry(minions) +} +func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) { m.random = rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) - podCache := NewPodCache(containerInfo, m.podRegistry, time.Second*30) + podCache := NewPodCache(podInfoGetter, m.podRegistry, time.Second*30) go podCache.Loop() s := scheduler.MakeFirstFitScheduler(m.podRegistry, m.random) m.storage = map[string]apiserver.RESTStorage{ - "pods": registry.MakePodRegistryStorage(m.podRegistry, containerInfo, s, m.minionRegistry, cloud, podCache), + "pods": registry.MakePodRegistryStorage(m.podRegistry, podInfoGetter, s, m.minionRegistry, cloud, podCache), "replicationControllers": registry.MakeControllerRegistryStorage(m.controllerRegistry, m.podRegistry), "services": registry.MakeServiceRegistryStorage(m.serviceRegistry, cloud, m.minionRegistry), "minions": registry.MakeMinionRegistryStorage(m.minionRegistry),