Merge pull request #87870 from tedyu/restore-proxier-updater

Use ProxierHealthUpdater directly to avoid panic
This commit is contained in:
Kubernetes Prow Robot 2020-02-17 10:13:29 -08:00 committed by GitHub
commit ea5cef1c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 13 deletions

View File

@ -532,7 +532,7 @@ type ProxyServer struct {
UseEndpointSlices bool UseEndpointSlices bool
OOMScoreAdj *int32 OOMScoreAdj *int32
ConfigSyncPeriod time.Duration ConfigSyncPeriod time.Duration
HealthzServer *healthcheck.ProxierHealthServer HealthzServer healthcheck.ProxierHealthUpdater
} }
// createClients creates a kube client and an event client from the given config and masterOverride. // createClients creates a kube client and an event client from the given config and masterOverride.

View File

@ -130,7 +130,7 @@ func newProxyServer(
Namespace: "", Namespace: "",
} }
var healthzServer *healthcheck.ProxierHealthServer var healthzServer healthcheck.ProxierHealthUpdater
if len(config.HealthzBindAddress) > 0 { if len(config.HealthzBindAddress) > 0 {
healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef) healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef)
} }

View File

@ -92,7 +92,7 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
Namespace: "", Namespace: "",
} }
var healthzServer *healthcheck.ProxierHealthServer var healthzServer healthcheck.ProxierHealthUpdater
if len(config.HealthzBindAddress) > 0 { if len(config.HealthzBindAddress) > 0 {
healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef) healthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, recorder, nodeRef)
} }

View File

@ -42,13 +42,16 @@ type ProxierHealthUpdater interface {
// Updated should be called when the proxier has successfully updated the service // Updated should be called when the proxier has successfully updated the service
// rules to reflect the current state. // rules to reflect the current state.
Updated() Updated()
// Run starts the healthz http server and returns.
Run()
} }
var _ ProxierHealthUpdater = &ProxierHealthServer{} var _ ProxierHealthUpdater = &proxierHealthServer{}
// ProxierHealthServer returns 200 "OK" by default. It verifies that the delay between // proxierHealthServer returns 200 "OK" by default. It verifies that the delay between
// QueuedUpdate() calls and Updated() calls never exceeds healthTimeout. // QueuedUpdate() calls and Updated() calls never exceeds healthTimeout.
type ProxierHealthServer struct { type proxierHealthServer struct {
listener listener listener listener
httpFactory httpServerFactory httpFactory httpServerFactory
clock clock.Clock clock clock.Clock
@ -63,12 +66,12 @@ type ProxierHealthServer struct {
} }
// NewProxierHealthServer returns a proxier health http server. // NewProxierHealthServer returns a proxier health http server.
func NewProxierHealthServer(addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *ProxierHealthServer { func NewProxierHealthServer(addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) ProxierHealthUpdater {
return newProxierHealthServer(stdNetListener{}, stdHTTPServerFactory{}, clock.RealClock{}, addr, healthTimeout, recorder, nodeRef) return newProxierHealthServer(stdNetListener{}, stdHTTPServerFactory{}, clock.RealClock{}, addr, healthTimeout, recorder, nodeRef)
} }
func newProxierHealthServer(listener listener, httpServerFactory httpServerFactory, c clock.Clock, addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *ProxierHealthServer { func newProxierHealthServer(listener listener, httpServerFactory httpServerFactory, c clock.Clock, addr string, healthTimeout time.Duration, recorder record.EventRecorder, nodeRef *v1.ObjectReference) *proxierHealthServer {
return &ProxierHealthServer{ return &proxierHealthServer{
listener: listener, listener: listener,
httpFactory: httpServerFactory, httpFactory: httpServerFactory,
clock: c, clock: c,
@ -80,17 +83,17 @@ func newProxierHealthServer(listener listener, httpServerFactory httpServerFacto
} }
// Updated updates the lastUpdated timestamp. // Updated updates the lastUpdated timestamp.
func (hs *ProxierHealthServer) Updated() { func (hs *proxierHealthServer) Updated() {
hs.lastUpdated.Store(hs.clock.Now()) hs.lastUpdated.Store(hs.clock.Now())
} }
// QueuedUpdate updates the lastQueued timestamp. // QueuedUpdate updates the lastQueued timestamp.
func (hs *ProxierHealthServer) QueuedUpdate() { func (hs *proxierHealthServer) QueuedUpdate() {
hs.lastQueued.Store(hs.clock.Now()) hs.lastQueued.Store(hs.clock.Now())
} }
// Run starts the healthz http server and returns. // Run starts the healthz http server and returns.
func (hs *ProxierHealthServer) Run() { func (hs *proxierHealthServer) Run() {
serveMux := http.NewServeMux() serveMux := http.NewServeMux()
serveMux.Handle("/healthz", healthzHandler{hs: hs}) serveMux.Handle("/healthz", healthzHandler{hs: hs})
server := hs.httpFactory.New(hs.addr, serveMux) server := hs.httpFactory.New(hs.addr, serveMux)
@ -117,7 +120,7 @@ func (hs *ProxierHealthServer) Run() {
} }
type healthzHandler struct { type healthzHandler struct {
hs *ProxierHealthServer hs *proxierHealthServer
} }
func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {