Exemplo n.º 1
0
func TestHealthCheck(t *testing.T) {
	fw := newServerTest()
	fw.fakeKubelet.containerVersionFunc = func() (kubecontainer.Version, error) {
		return dockertools.NewVersion("1.18")
	}
	fw.fakeKubelet.hostnameFunc = func() string {
		return "127.0.0.1"
	}

	// Test with correct hostname, Docker version
	assertHealthIsOk(t, fw.testHTTPServer.URL+"/healthz")

	//Test with incorrect hostname
	fw.fakeKubelet.hostnameFunc = func() string {
		return "fake"
	}
	assertHealthIsOk(t, fw.testHTTPServer.URL+"/healthz")

	//Test with old container runtime version
	fw.fakeKubelet.containerVersionFunc = func() (kubecontainer.Version, error) {
		return dockertools.NewVersion("1.16")
	}

	assertHealthFails(t, fw.testHTTPServer.URL+"/healthz", http.StatusInternalServerError)
}
Exemplo n.º 2
0
func TestSyncLoopCheck(t *testing.T) {
	fw := newServerTest()
	fw.fakeKubelet.containerVersionFunc = func() (kubecontainer.Version, error) {
		return dockertools.NewVersion("1.18")
	}
	fw.fakeKubelet.hostnameFunc = func() string {
		return "127.0.0.1"
	}

	fw.fakeKubelet.resyncInterval = time.Minute
	fw.fakeKubelet.loopEntryTime = time.Now()

	// Test with correct hostname, Docker version
	assertHealthIsOk(t, fw.testHTTPServer.URL+"/healthz")

	fw.fakeKubelet.loopEntryTime = time.Now().Add(time.Minute * -10)
	assertHealthFails(t, fw.testHTTPServer.URL+"/healthz", http.StatusInternalServerError)
}
Exemplo n.º 3
0
func newServerTest() *serverTestFramework {
	fw := &serverTestFramework{}
	fw.fakeKubelet = &fakeKubelet{
		containerVersionFunc: func() (kubecontainer.Version, error) {
			return dockertools.NewVersion("1.18")
		},
		podByNameFunc: func(namespace, name string) (*api.Pod, bool) {
			return &api.Pod{
				ObjectMeta: api.ObjectMeta{
					Namespace: namespace,
					Name:      name,
				},
			}, true
		},
	}
	server := NewServer(fw.fakeKubelet, true)
	fw.serverUnderTest = &server
	fw.testHTTPServer = httptest.NewServer(fw.serverUnderTest)
	return fw
}