Skip to content

Commit 7a0690c

Browse files
committed
Use ProxierHealthUpdater directly to avoid panic
1 parent 9f6f608 commit 7a0690c

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

cmd/kube-proxy/app/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ type ProxyServer struct {
532532
UseEndpointSlices bool
533533
OOMScoreAdj *int32
534534
ConfigSyncPeriod time.Duration
535-
HealthzServer *healthcheck.ProxierHealthServer
535+
HealthzServer healthcheck.ProxierHealthUpdater
536536
}
537537

538538
// createClients creates a kube client and an event client from the given config and masterOverride.

cmd/kube-proxy/app/server_others.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func newProxyServer(
130130
Namespace: "",
131131
}
132132

133-
var healthzServer *healthcheck.ProxierHealthServer
133+
var healthzServer healthcheck.ProxierHealthUpdater
134134
if len(config.HealthzBindAddress) > 0 {
135135
healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef)
136136
}

cmd/kube-proxy/app/server_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
9292
Namespace: "",
9393
}
9494

95-
var healthzServer *healthcheck.ProxierHealthServer
95+
var healthzServer healthcheck.ProxierHealthUpdater
9696
if len(config.HealthzBindAddress) > 0 {
9797
healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef)
9898
}

pkg/proxy/healthcheck/proxier_health.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ type ProxierHealthUpdater interface {
4242
// Updated should be called when the proxier has successfully updated the service
4343
// rules to reflect the current state.
4444
Updated()
45+
46+
// Run starts the healthz http server and returns.
47+
Run()
4548
}
4649

47-
var _ ProxierHealthUpdater = &ProxierHealthServer{}
50+
var _ ProxierHealthUpdater = &proxierHealthServer{}
4851

49-
// ProxierHealthServer returns 200 "OK" by default. It verifies that the delay between
52+
// proxierHealthServer returns 200 "OK" by default. It verifies that the delay between
5053
// QueuedUpdate() calls and Updated() calls never exceeds healthTimeout.
51-
type ProxierHealthServer struct {
54+
type proxierHealthServer struct {
5255
listener listener
5356
httpFactory httpServerFactory
5457
clock clock.Clock
@@ -63,12 +66,12 @@ type ProxierHealthServer struct {
6366
}
6467

6568
// NewProxierHealthServer returns a proxier health http server.
66-
func NewProxierHealthServer(addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *ProxierHealthServer {
69+
func NewProxierHealthServer(addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) ProxierHealthUpdater {
6770
return newProxierHealthServer(stdNetListener{}, stdHTTPServerFactory{}, clock.RealClock{}, addr, healthTimeout, recorder, nodeRef)
6871
}
6972

70-
func newProxierHealthServer(listener listener, httpServerFactory httpServerFactory, c clock.Clock, addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *ProxierHealthServer {
71-
return &ProxierHealthServer{
73+
func newProxierHealthServer(listener listener, httpServerFactory httpServerFactory, c clock.Clock, addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *proxierHealthServer {
74+
return &proxierHealthServer{
7275
listener: listener,
7376
httpFactory: httpServerFactory,
7477
clock: c,
@@ -80,17 +83,17 @@ func newProxierHealthServer(listener listener, httpServerFactory httpServerFacto
8083
}
8184

8285
// Updated updates the lastUpdated timestamp.
83-
func (hs *ProxierHealthServer) Updated() {
86+
func (hs *proxierHealthServer) Updated() {
8487
hs.lastUpdated.Store(hs.clock.Now())
8588
}
8689

8790
// QueuedUpdate updates the lastQueued timestamp.
88-
func (hs *ProxierHealthServer) QueuedUpdate() {
91+
func (hs *proxierHealthServer) QueuedUpdate() {
8992
hs.lastQueued.Store(hs.clock.Now())
9093
}
9194

9295
// Run starts the healthz http server and returns.
93-
func (hs *ProxierHealthServer) Run() {
96+
func (hs *proxierHealthServer) Run() {
9497
serveMux := http.NewServeMux()
9598
serveMux.Handle("/healthz", healthzHandler{hs: hs})
9699
server := hs.httpFactory.New(hs.addr, serveMux)
@@ -117,7 +120,7 @@ func (hs *ProxierHealthServer) Run() {
117120
}
118121

119122
type healthzHandler struct {
120-
hs *ProxierHealthServer
123+
hs *proxierHealthServer
121124
}
122125

123126
func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {

0 commit comments

Comments
 (0)