added version endpoint

This commit is contained in:
Stefan Prodan
2018-01-12 02:52:29 +02:00
parent b839eba381
commit 2cf41cea78
2 changed files with 26 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
"sync/atomic"
"github.com/golang/glog"
"github.com/stefanprodan/k8s-podinfo/pkg/version"
"gopkg.in/yaml.v2"
)
@@ -52,6 +53,30 @@ func (s *Server) echo(w http.ResponseWriter, r *http.Request) {
}
}
func (s *Server) version(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/version" {
w.WriteHeader(http.StatusNotFound)
return
}
resp := map[string]string{
"version": version.VERSION,
"commit": version.GITCOMMIT,
}
d, err := yaml.Marshal(resp)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
w.Header().Set("Content-Type", "text/x-yaml; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(http.StatusOK)
w.Write(d)
}
func (s *Server) healthz(w http.ResponseWriter, r *http.Request) {
if atomic.LoadInt32(&healthy) == 1 {
w.WriteHeader(http.StatusOK)

View File

@@ -34,6 +34,7 @@ func NewServer(options ...func(*Server)) *Server {
s.mux.HandleFunc("/readyz/disable", s.disable)
s.mux.HandleFunc("/echo", s.echo)
s.mux.HandleFunc("/panic", s.panic)
s.mux.HandleFunc("/version", s.version)
s.mux.Handle("/metrics", promhttp.Handler())
return s