Skip to content

Commit

Permalink
Don't log 'apiserver disabled' error sent by etcd-only nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 08f1022)
  • Loading branch information
brandond committed Apr 10, 2024
1 parent c043e62 commit 3baf7c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/util/apierrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit 3baf7c8

Please sign in to comment.