From 5b2c14b123195c9f002634751cf5504eaf5be34f Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Thu, 14 Apr 2022 17:30:04 -0700 Subject: [PATCH] Print a helpful error when trying to join additional servers but etcd is not in use Signed-off-by: Brad Davidson --- pkg/server/router.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/server/router.go b/pkg/server/router.go index f3da6c93eb..86a5db3984 100644 --- a/pkg/server/router.go +++ b/pkg/server/router.go @@ -69,9 +69,7 @@ func router(ctx context.Context, config *Config, cfg *cmds.Server) http.Handler serverAuthed.Path(prefix + "/encrypt/status").Handler(encryptionStatusHandler(serverConfig)) serverAuthed.Path(prefix + "/encrypt/config").Handler(encryptionConfigHandler(ctx, serverConfig)) serverAuthed.Path("/db/info").Handler(nodeAuthed) - if serverConfig.Runtime.HTTPBootstrap { - serverAuthed.Path(prefix + "/server-bootstrap").Handler(bootstrap.Handler(&serverConfig.Runtime.ControlRuntimeBootstrap)) - } + serverAuthed.Path(prefix + "/server-bootstrap").Handler(bootstrapHandler(serverConfig.Runtime)) staticDir := filepath.Join(serverConfig.DataDir, "static") router := mux.NewRouter() @@ -107,6 +105,20 @@ func apiserverDisabled() http.Handler { }) } +func bootstrapHandler(runtime *config.ControlRuntime) http.Handler { + if runtime.HTTPBootstrap { + return bootstrap.Handler(&runtime.ControlRuntimeBootstrap) + } + return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { + logrus.Warnf("Received HTTP bootstrap request from %s, but embedded etcd is not enabled.", req.RemoteAddr) + data := []byte("etcd disabled") + resp.WriteHeader(http.StatusBadRequest) + resp.Header().Set("Content-Type", "text/plain") + resp.Header().Set("Content-length", strconv.Itoa(len(data))) + resp.Write(data) + }) +} + func cacerts(serverCA string) http.Handler { var ca []byte return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {