From a9ace511d8f5337406a01e8febbdf9f415b37441 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 29 Nov 2022 15:34:13 +0100 Subject: [PATCH] server: add healthz endpoint (#963) From the node (or any privileged pod having mounted the multus socket) you can now query the multus-cni server liveliness - for instance: ``` root@kind-worker:/# curl -v --unix-socket /run/multus/multus.sock localhost/healthz * Trying /run/multus/multus.sock:0... * Connected to localhost (/host/run/multus/multus.sock) port 80 (#0) > GET /healthz HTTP/1.1 > Host: localhost > User-Agent: curl/7.74.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Date: Mon, 14 Nov 2022 17:21:07 GMT < Content-Length: 0 < Connection: close < * Closing connection 0 ``` Signed-off-by: Miguel Duarte Barroso Signed-off-by: Miguel Duarte Barroso --- pkg/server/api/api.go | 3 +++ pkg/server/server.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/server/api/api.go b/pkg/server/api/api.go index 9d80dd374..9f348545e 100644 --- a/pkg/server/api/api.go +++ b/pkg/server/api/api.go @@ -30,6 +30,9 @@ const ( // MultusDelegateAPIEndpoint is an endpoint for multus delegate request (for hotplug) MultusDelegateAPIEndpoint = "/delegate" defaultMultusRunDir = "/run/multus/" + + // MultusHealthAPIEndpoint is an endpoint API clients can query to know if they can communicate w/ multus server + MultusHealthAPIEndpoint = "/healthz" ) // DoCNI sends a CNI request to the CNI server via JSON + HTTP over a root-owned unix socket, diff --git a/pkg/server/server.go b/pkg/server/server.go index 6c5f27ac2..e8e62d67c 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -215,6 +215,12 @@ func newCNIServer(rundir string, kubeClient *k8s.ClientInfo, exec invoke.Exec, s } }))).Methods("POST") + router.HandleFunc(api.MultusHealthAPIEndpoint, promhttp.InstrumentHandlerCounter(s.metrics.requestCounter.MustCurryWith(prometheus.Labels{"handler": api.MultusHealthAPIEndpoint}), + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "application/json") + }))).Methods("GET") + return s, nil }