From 004330df8f09232df3283cb3a8d5ce147665e5ba Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Wed, 30 Aug 2017 16:25:48 -0700 Subject: [PATCH] server: Add a /info endpoint This will give a way for client to get information about crio daemon. Signed-off-by: Mrunal Patel --- cmd/crio/main.go | 2 +- server/inspect.go | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/crio/main.go b/cmd/crio/main.go index 24569cef..959d756f 100644 --- a/cmd/crio/main.go +++ b/cmd/crio/main.go @@ -413,7 +413,7 @@ func main() { }() go func() { - err := service.StartInspectEndpoint() + err := service.StartInfoEndpoints() if err != nil { logrus.Fatalf("Failed to start container inspect endpoint: %v", err) } diff --git a/server/inspect.go b/server/inspect.go index 18537848..377d821c 100644 --- a/server/inspect.go +++ b/server/inspect.go @@ -17,11 +17,31 @@ type ContainerInfo struct { Annotations map[string]string `json:"annotations"` } -// StartInspectEndpoint starts a http server that -// serves container information requests -func (s *Server) StartInspectEndpoint() error { +// CrioInfo stores information about the crio daemon +type CrioInfo struct { + StorageDriver string `json:"storage_driver"` + StorageRoot string `json:"storage_root"` +} + +// StartInfoEndpoints starts a http server that +// serves container information requests and crio daemon information +func (s *Server) StartInfoEndpoints() error { mux := bone.New() + mux.Get("/info", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + ci := CrioInfo{ + StorageDriver: s.config.Config.Storage, + StorageRoot: s.config.Config.Root, + } + js, err := json.Marshal(ci) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.Write(js) + })) + mux.Get("/containers/:id", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { containerID := bone.GetValue(req, "id") ctr := s.GetContainer(containerID)