From 08f10226639b05e93de0ac45311c0e66245ebdc6 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Mon, 8 Apr 2024 21:58:40 +0000 Subject: [PATCH] Don't log 'apiserver disabled' error sent by etcd-only nodes Signed-off-by: Brad Davidson --- pkg/server/router.go | 4 ++-- pkg/util/apierrors.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/server/router.go b/pkg/server/router.go index 72c92e92ed..86d18c58c9 100644 --- a/pkg/server/router.go +++ b/pkg/server/router.go @@ -104,14 +104,14 @@ func apiserver(runtime *config.ControlRuntime) http.Handler { if runtime != nil && runtime.APIServer != nil { runtime.APIServer.ServeHTTP(resp, req) } else { - util.SendError(util.ErrNotReady, resp, req, http.StatusServiceUnavailable) + util.SendError(util.ErrAPINotReady, resp, req, http.StatusServiceUnavailable) } }) } func apiserverDisabled() http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { - util.SendError(errors.New("apiserver disabled"), resp, req, http.StatusServiceUnavailable) + util.SendError(util.ErrAPIDisabled, resp, req, http.StatusServiceUnavailable) }) } diff --git a/pkg/util/apierrors.go b/pkg/util/apierrors.go index aaba05b5db..2edca11139 100644 --- a/pkg/util/apierrors.go +++ b/pkg/util/apierrors.go @@ -15,7 +15,8 @@ import ( "k8s.io/apiserver/pkg/endpoints/handlers/responsewriters" ) -var ErrNotReady = errors.New("apiserver not ready") +var ErrAPINotReady = errors.New("apiserver not ready") +var ErrAPIDisabled = errors.New("apiserver disabled") // SendErrorWithID sends and logs a random error ID so that logs can be correlated // between the REST API (which does not provide any detailed error output, to avoid @@ -36,8 +37,8 @@ func SendError(err error, resp http.ResponseWriter, req *http.Request, status .. code = http.StatusInternalServerError } - // Don't log "apiserver not ready" errors, they are frequent during startup - if !errors.Is(err, ErrNotReady) { + // Don't log "apiserver not ready" or "apiserver disabled" errors, they are frequent during startup + if !errors.Is(err, ErrAPINotReady) && !errors.Is(err, ErrAPIDisabled) { logrus.Errorf("Sending HTTP %d response to %s: %v", code, req.RemoteAddr, err) }