Fix integration tests to not depend on setting pod.Status on create

Allow the master to have pod/node cache timeouts controlled via a config
flag for integration tests.

Move integration test to '127.0.0.1' so that it correctly returns a health
check, and enable health check testing on the integration test.
This commit is contained in:
Clayton Coleman 2015-01-28 17:39:57 -05:00
parent 5603714df8
commit 7f39a37eee
2 changed files with 28 additions and 6 deletions

View File

@ -73,7 +73,7 @@ func (fakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.Pod
Client: http.DefaultClient, Client: http.DefaultClient,
Port: 10250, Port: 10250,
} }
case "machine": case "127.0.0.1":
c = &client.HTTPKubeletClient{ c = &client.HTTPKubeletClient{
Client: http.DefaultClient, Client: http.DefaultClient,
Port: 10251, Port: 10251,
@ -81,7 +81,18 @@ func (fakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.Pod
default: default:
glog.Fatalf("Can't get info for: '%v', '%v - %v'", host, podNamespace, podID) glog.Fatalf("Can't get info for: '%v', '%v - %v'", host, podNamespace, podID)
} }
return c.GetPodStatus("localhost", podNamespace, podID) r, err := c.GetPodStatus("localhost", podNamespace, podID)
if err != nil {
return r, err
}
r.Status.PodIP = "1.2.3.4"
m := make(api.PodInfo)
for k, v := range r.Status.Info {
v.PodIP = "1.2.3.4"
m[k] = v
}
r.Status.Info = m
return r, nil
} }
func (fakeKubeletClient) HealthCheck(host string) (probe.Status, error) { func (fakeKubeletClient) HealthCheck(host string) (probe.Status, error) {
@ -104,7 +115,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
// Setup // Setup
servers := []string{"http://localhost:4001"} servers := []string{"http://localhost:4001"}
glog.Infof("Creating etcd client pointing to %v", servers) glog.Infof("Creating etcd client pointing to %v", servers)
machineList := []string{"localhost", "machine"} machineList := []string{"localhost", "127.0.0.1"}
handler := delegateHandler{} handler := delegateHandler{}
apiServer := httptest.NewServer(&handler) apiServer := httptest.NewServer(&handler)
@ -163,6 +174,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
ReadWritePort: portNumber, ReadWritePort: portNumber,
ReadOnlyPort: portNumber, ReadOnlyPort: portNumber,
PublicAddress: net.ParseIP(host), PublicAddress: net.ParseIP(host),
CacheTimeout: 2 * time.Second,
}) })
handler.delegate = m.Handler handler.delegate = m.Handler
@ -185,7 +197,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
nodeResources := &api.NodeResources{} nodeResources := &api.NodeResources{}
nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl, fakeKubeletClient{}) nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl, fakeKubeletClient{})
nodeController.Run(10*time.Second, 10) nodeController.Run(5*time.Second, 10)
// Kubelet (localhost) // Kubelet (localhost)
testRootDir := makeTempDirOrDie("kubelet_integ_1.") testRootDir := makeTempDirOrDie("kubelet_integ_1.")

View File

@ -100,6 +100,10 @@ type Config struct {
// If nil, the first result from net.InterfaceAddrs will be used. // If nil, the first result from net.InterfaceAddrs will be used.
PublicAddress net.IP PublicAddress net.IP
// Control the interval that pod, node IP, and node heath status caches
// expire.
CacheTimeout time.Duration
} }
// Master contains state for a Kubernetes cluster master/api server. // Master contains state for a Kubernetes cluster master/api server.
@ -117,6 +121,7 @@ type Master struct {
storage map[string]apiserver.RESTStorage storage map[string]apiserver.RESTStorage
client *client.Client client *client.Client
portalNet *net.IPNet portalNet *net.IPNet
cacheTimeout time.Duration
mux apiserver.Mux mux apiserver.Mux
muxHelper *apiserver.MuxHelper muxHelper *apiserver.MuxHelper
@ -179,6 +184,9 @@ func setDefaults(c *Config) {
if c.ReadOnlyPort == 0 { if c.ReadOnlyPort == 0 {
c.ReadOnlyPort = 7080 c.ReadOnlyPort = 7080
} }
if c.CacheTimeout == 0 {
c.CacheTimeout = 5 * time.Second
}
if c.ReadWritePort == 0 { if c.ReadWritePort == 0 {
c.ReadWritePort = 443 c.ReadWritePort = 443
} }
@ -283,7 +291,9 @@ func New(c *Config) *Master {
authorizer: c.Authorizer, authorizer: c.Authorizer,
admissionControl: c.AdmissionControl, admissionControl: c.AdmissionControl,
v1beta3: c.EnableV1Beta3, v1beta3: c.EnableV1Beta3,
nodeIPCache: NewIPCache(c.Cloud, util.RealClock{}, 30*time.Second), nodeIPCache: NewIPCache(c.Cloud, util.RealClock{}, c.CacheTimeout),
cacheTimeout: c.CacheTimeout,
masterCount: c.MasterCount, masterCount: c.MasterCount,
publicIP: c.PublicAddress, publicIP: c.PublicAddress,
@ -365,7 +375,7 @@ func (m *Master) init(c *Config) {
RESTStorageToNodes(nodeRESTStorage).Nodes(), RESTStorageToNodes(nodeRESTStorage).Nodes(),
m.podRegistry, m.podRegistry,
) )
go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*5) go util.Forever(func() { podCache.UpdateAllContainers() }, m.cacheTimeout)
go util.Forever(func() { podCache.GarbageCollectPodStatus() }, time.Minute*30) go util.Forever(func() { podCache.GarbageCollectPodStatus() }, time.Minute*30)
// TODO: Factor out the core API registration // TODO: Factor out the core API registration