Merge pull request #821 from mrunalp/crio_info

server: Add a /info endpoint
This commit is contained in:
Antonio Murdaca 2017-08-31 16:08:18 +02:00 committed by GitHub
commit c070da051c
2 changed files with 24 additions and 4 deletions

View file

@ -413,7 +413,7 @@ func main() {
}() }()
go func() { go func() {
err := service.StartInspectEndpoint() err := service.StartInfoEndpoints()
if err != nil { if err != nil {
logrus.Fatalf("Failed to start container inspect endpoint: %v", err) logrus.Fatalf("Failed to start container inspect endpoint: %v", err)
} }

View file

@ -17,11 +17,31 @@ type ContainerInfo struct {
Annotations map[string]string `json:"annotations"` Annotations map[string]string `json:"annotations"`
} }
// StartInspectEndpoint starts a http server that // CrioInfo stores information about the crio daemon
// serves container information requests type CrioInfo struct {
func (s *Server) StartInspectEndpoint() error { 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 := 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) { mux.Get("/containers/:id", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
containerID := bone.GetValue(req, "id") containerID := bone.GetValue(req, "id")
ctr := s.GetContainer(containerID) ctr := s.GetContainer(containerID)