Skip to content

Commit 3274dc4

Browse files
committed
pkg/proxy/healthcheck: consolidate IsHealthy and isHealthy
Signed-off-by: Daman Arora <[email protected]>
1 parent 1c1fc73 commit 3274dc4

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

pkg/proxy/healthcheck/healthcheck_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ type fakeProxyHealthChecker struct {
143143
healthy bool
144144
}
145145

146-
func (fake fakeProxyHealthChecker) IsHealthy() bool {
147-
return fake.healthy
146+
func (fake fakeProxyHealthChecker) Health() (bool, time.Time) {
147+
// we only need "healthy" field for testing service healthchecks.
148+
return fake.healthy, time.Time{}
148149
}
149150

150151
func TestServer(t *testing.T) {

pkg/proxy/healthcheck/proxy_health.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,8 @@ func (hs *ProxyHealthServer) QueuedUpdate(ipFamily v1.IPFamily) {
101101
}
102102
}
103103

104-
// IsHealthy returns only the proxier's health state, following the same
105-
// definition the HTTP server defines, but ignoring the state of the Node.
106-
func (hs *ProxyHealthServer) IsHealthy() bool {
107-
isHealthy, _ := hs.isHealthy()
108-
return isHealthy
109-
}
110-
111-
func (hs *ProxyHealthServer) isHealthy() (bool, time.Time) {
104+
// Health returns only the proxier's health state and last updated time.
105+
func (hs *ProxyHealthServer) Health() (bool, time.Time) {
112106
hs.lock.RLock()
113107
defer hs.lock.RUnlock()
114108

@@ -188,7 +182,7 @@ type healthzHandler struct {
188182

189183
func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, _ *http.Request) {
190184
nodeEligible := h.hs.NodeEligible()
191-
healthy, lastUpdated := h.hs.isHealthy()
185+
healthy, lastUpdated := h.hs.Health()
192186
currentTime := h.hs.clock.Now()
193187

194188
healthy = healthy && nodeEligible
@@ -215,7 +209,7 @@ type livezHandler struct {
215209
}
216210

217211
func (h livezHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
218-
healthy, lastUpdated := h.hs.isHealthy()
212+
healthy, lastUpdated := h.hs.Health()
219213
currentTime := h.hs.clock.Now()
220214
resp.Header().Set("Content-Type", "application/json")
221215
resp.Header().Set("X-Content-Type-Options", "nosniff")

pkg/proxy/healthcheck/service_health.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strconv"
2525
"strings"
2626
"sync"
27+
"time"
2728

2829
"github.com/lithammer/dedent"
2930

@@ -53,9 +54,8 @@ type ServiceHealthServer interface {
5354
}
5455

5556
type proxyHealthChecker interface {
56-
// IsHealthy returns the proxy's health state, following the same
57-
// definition the HTTP server defines.
58-
IsHealthy() bool
57+
// Health returns the proxy's health state and last updated time.
58+
Health() (bool, time.Time)
5959
}
6060

6161
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) {
231231
}
232232
count := svc.endpoints
233233
h.hcs.lock.RUnlock()
234-
kubeProxyHealthy := h.hcs.healthzServer.IsHealthy()
234+
kubeProxyHealthy, _ := h.hcs.healthzServer.Health()
235235

236236
resp.Header().Set("Content-Type", "application/json")
237237
resp.Header().Set("X-Content-Type-Options", "nosniff")

0 commit comments

Comments
 (0)