Allow master's pod info getter to be faked. Wire up in integration tests in futile attempt to make travis pass.

This commit is contained in:
Daniel Smith
2014-07-01 17:08:32 -07:00
parent 587fb75a7a
commit bf3b34c2e9
3 changed files with 51 additions and 24 deletions

View File

@@ -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))

View File

@@ -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))