server: Add a /info endpoint
This will give a way for client to get information about crio daemon. Signed-off-by: Mrunal Patel <mpatel@redhat.com>
This commit is contained in:
parent
f557020994
commit
004330df8f
2 changed files with 24 additions and 4 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue