mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-08-08 23:37:11 +00:00
pkg/proxy/healthcheck: consolidate IsHealthy and isHealthy
Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user