From 40bad6b3456afaf9a7d04fb0af3911f47ffd601b Mon Sep 17 00:00:00 2001 From: Piotr Icikowski Date: Thu, 29 Feb 2024 01:19:31 +0100 Subject: [PATCH] feat(handler): change path resolver logic --- probes.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/probes.go b/probes.go index 0343c89..5948ba6 100644 --- a/probes.go +++ b/probes.go @@ -2,6 +2,7 @@ package kubeprobes import ( "net/http" + "strings" ) type kubeprobes struct { @@ -11,15 +12,16 @@ type kubeprobes struct { // ServeHTTP implements http.Handler interface func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case "/live": + subs := strings.Split(strings.TrimSuffix(r.URL.Path, "/"), "/") + switch subs[len(subs)-1] { + case "live": sq := newStatusQuery(kp.livenessProbes) if sq.isAllGreen() { w.WriteHeader(http.StatusOK) } else { w.WriteHeader(http.StatusServiceUnavailable) } - case "/ready": + case "ready": sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...)) if sq.isAllGreen() { w.WriteHeader(http.StatusOK)