From 56b248c8549833c10e0d7b966c4b8086555879d3 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. --- node/api/server.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/api/server.go b/node/api/server.go index 7ab0761ad..eba8e88aa 100644 --- a/node/api/server.go +++ b/node/api/server.go @@ -40,6 +40,7 @@ type PodHandlerConfig struct { GetPods PodListerFunc // GetPodsFromKubernetes is meant to enumerate the pods that the node is meant to be running GetPodsFromKubernetes PodListerFunc + GetStatsSummary PodStatsSummaryHandlerFunc StreamIdleTimeout time.Duration StreamCreationTimeout time.Duration } @@ -64,6 +65,13 @@ func PodHandler(p PodHandlerConfig, debug bool) http.Handler { WithExecStreamIdleTimeout(p.StreamIdleTimeout), ), ).Methods("POST", "GET") + + 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 }