Add the /runningpods/ api endpoint (#611)

* Add the /runningpods/ api endpoint

This adds an API endpoint from the kubelet (/runningpods/). It is
an endpoint on kubelet which is considered a "debug" endpoint, so
it might be worth exposing through the options, but by default
it is exposed in most k8s configs AFAICT.
This commit is contained in:
Sargun Dhillon
2019-05-13 15:10:31 -07:00
committed by Brian Goff
parent c50f33e701
commit 63fa4e124b
4 changed files with 63 additions and 4 deletions

View File

@@ -21,9 +21,14 @@ type ServeMux interface {
}
// PodHandler creates an http handler for interacting with pods/containers.
func PodHandler(p providers.Provider) http.Handler {
func PodHandler(p providers.Provider, debug bool) http.Handler {
r := mux.NewRouter()
// This matches the behaviour in the reference kubelet
r.StrictSlash(true)
if debug {
r.HandleFunc("/runningpods/", api.RunningPodsHandlerFunc(p)).Methods("GET")
}
r.HandleFunc("/containerLogs/{namespace}/{pod}/{container}", api.PodLogsHandlerFunc(p)).Methods("GET")
r.HandleFunc("/exec/{namespace}/{pod}/{container}", api.PodExecHandlerFunc(p)).Methods("POST")
r.NotFoundHandler = http.HandlerFunc(NotFound)
@@ -58,8 +63,8 @@ func MetricsSummaryHandler(p providers.Provider) http.Handler {
//
// Callers should take care to namespace the serve mux as they see fit, however
// these routes get called by the Kubernetes API server.
func AttachPodRoutes(p providers.Provider, mux ServeMux) {
mux.Handle("/", InstrumentHandler(PodHandler(p)))
func AttachPodRoutes(p providers.Provider, mux ServeMux, debug bool) {
mux.Handle("/", InstrumentHandler(PodHandler(p, debug)))
}
// AttachMetricsRoutes adds the http routes for pod/node metrics to the passed in serve mux.