mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-03-03 18:40:21 +00:00
- add swagger definitions for all API routes - self-host the swagger UI on `/swagger/` - serve swagger spec on `/swagger.json`
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// Healthz godoc
|
|
// @Summary Liveness check
|
|
// @Description used by Kubernetes liveness probe
|
|
// @Tags Kubernetes
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Router /healthz [get]
|
|
// @Success 200 {string} string "OK"
|
|
func (s *Server) healthzHandler(w http.ResponseWriter, r *http.Request) {
|
|
if atomic.LoadInt32(&healthy) == 1 {
|
|
s.JSONResponse(w, r, map[string]string{"status": "OK"})
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
}
|
|
|
|
// Readyz godoc
|
|
// @Summary Readiness check
|
|
// @Description used by Kubernetes readiness probe
|
|
// @Tags Kubernetes
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Router /readyz [get]
|
|
// @Success 200 {string} string "OK"
|
|
func (s *Server) readyzHandler(w http.ResponseWriter, r *http.Request) {
|
|
if atomic.LoadInt32(&ready) == 1 {
|
|
s.JSONResponse(w, r, map[string]string{"status": "OK"})
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
}
|
|
|
|
// EnableReady godoc
|
|
// @Summary Enable ready state
|
|
// @Description signals the Kubernetes LB that this instance is ready to receive traffic
|
|
// @Tags Kubernetes
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Router /readyz/enable [post]
|
|
// @Success 202 {string} string "OK"
|
|
func (s *Server) enableReadyHandler(w http.ResponseWriter, r *http.Request) {
|
|
atomic.StoreInt32(&ready, 1)
|
|
w.WriteHeader(http.StatusAccepted)
|
|
}
|
|
|
|
// DisableReady godoc
|
|
// @Summary Disable ready state
|
|
// @Description signals the Kubernetes LB to stop sending requests to this instance
|
|
// @Tags Kubernetes
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Router /readyz/disable [post]
|
|
// @Success 202 {string} string "OK"
|
|
func (s *Server) disableReadyHandler(w http.ResponseWriter, r *http.Request) {
|
|
atomic.StoreInt32(&ready, 0)
|
|
w.WriteHeader(http.StatusAccepted)
|
|
}
|