From c621acc8d2fd39665be8d9746bb51d4e871054b4 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Thu, 16 Jul 2020 16:49:15 -0700 Subject: [PATCH] Add GetStatsSummary to PodHandlerConfig If both the metrics routes and the pod routes are attached to the same mux with the pattern "/", it will panic. Instead, add the stats handler function to PodHandlerConfig and set up the route if it is not nil. (cherry picked from commit 56b248c8549833c10e0d7b966c4b8086555879d3) Signed-off-by: Brian Goff --- node/api/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/node/api/server.go b/node/api/server.go index badf70554..3c461d75f 100644 --- a/node/api/server.go +++ b/node/api/server.go @@ -36,6 +36,7 @@ type PodHandlerConfig struct { RunInContainer ContainerExecHandlerFunc GetContainerLogs ContainerLogsHandlerFunc GetPods PodListerFunc + GetStatsSummary PodStatsSummaryHandlerFunc } // PodHandler creates an http handler for interacting with pods/containers. @@ -49,6 +50,12 @@ func PodHandler(p PodHandlerConfig, debug bool) http.Handler { } r.HandleFunc("/containerLogs/{namespace}/{pod}/{container}", HandleContainerLogs(p.GetContainerLogs)).Methods("GET") r.HandleFunc("/exec/{namespace}/{pod}/{container}", HandleContainerExec(p.RunInContainer)).Methods("POST") + if p.GetStatsSummary != nil { + f := HandlePodStatsSummary(p.GetStatsSummary) + r.HandleFunc("/stats/summary", f).Methods("GET") + r.HandleFunc("/stats/summary/", f).Methods("GET") + } + r.NotFoundHandler = http.HandlerFunc(NotFound) return r }