diff --git a/pkg/proxy/healthcheck/healthcheck_test.go b/pkg/proxy/healthcheck/healthcheck_test.go index 83c9708909b..9eb92004d58 100644 --- a/pkg/proxy/healthcheck/healthcheck_test.go +++ b/pkg/proxy/healthcheck/healthcheck_test.go @@ -143,8 +143,9 @@ type fakeProxyHealthChecker struct { healthy bool } -func (fake fakeProxyHealthChecker) IsHealthy() bool { - return fake.healthy +func (fake fakeProxyHealthChecker) Health() (bool, time.Time) { + // we only need "healthy" field for testing service healthchecks. + return fake.healthy, time.Time{} } func TestServer(t *testing.T) { diff --git a/pkg/proxy/healthcheck/proxy_health.go b/pkg/proxy/healthcheck/proxy_health.go index 652f7ef90dc..2039f801954 100644 --- a/pkg/proxy/healthcheck/proxy_health.go +++ b/pkg/proxy/healthcheck/proxy_health.go @@ -101,14 +101,8 @@ func (hs *ProxyHealthServer) QueuedUpdate(ipFamily v1.IPFamily) { } } -// IsHealthy returns only the proxier's health state, following the same -// definition the HTTP server defines, but ignoring the state of the Node. -func (hs *ProxyHealthServer) IsHealthy() bool { - isHealthy, _ := hs.isHealthy() - return isHealthy -} - -func (hs *ProxyHealthServer) isHealthy() (bool, time.Time) { +// Health returns only the proxier's health state and last updated time. +func (hs *ProxyHealthServer) Health() (bool, time.Time) { hs.lock.RLock() defer hs.lock.RUnlock() @@ -188,7 +182,7 @@ type healthzHandler struct { func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, _ *http.Request) { nodeEligible := h.hs.NodeEligible() - healthy, lastUpdated := h.hs.isHealthy() + healthy, lastUpdated := h.hs.Health() currentTime := h.hs.clock.Now() healthy = healthy && nodeEligible @@ -215,7 +209,7 @@ type livezHandler struct { } func (h livezHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { - healthy, lastUpdated := h.hs.isHealthy() + healthy, lastUpdated := h.hs.Health() currentTime := h.hs.clock.Now() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("X-Content-Type-Options", "nosniff") diff --git a/pkg/proxy/healthcheck/service_health.go b/pkg/proxy/healthcheck/service_health.go index e0894aae98a..0f9eb300f00 100644 --- a/pkg/proxy/healthcheck/service_health.go +++ b/pkg/proxy/healthcheck/service_health.go @@ -24,6 +24,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/lithammer/dedent" @@ -53,9 +54,8 @@ type ServiceHealthServer interface { } type proxyHealthChecker interface { - // IsHealthy returns the proxy's health state, following the same - // definition the HTTP server defines. - IsHealthy() bool + // Health returns the proxy's health state and last updated time. + Health() (bool, time.Time) } func newServiceHealthServer(hostname string, recorder events.EventRecorder, listener listener, factory httpServerFactory, nodePortAddresses *proxyutil.NodePortAddresses, healthzServer proxyHealthChecker) ServiceHealthServer { @@ -231,7 +231,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { } count := svc.endpoints h.hcs.lock.RUnlock() - kubeProxyHealthy := h.hcs.healthzServer.IsHealthy() + kubeProxyHealthy, _ := h.hcs.healthzServer.Health() resp.Header().Set("Content-Type", "application/json") resp.Header().Set("X-Content-Type-Options", "nosniff")