1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00
policy-reporter/pkg/api/handler.go
Frank Jogeleit 7624c43147
simplify zap logging (#277)
* simplify zap logging

Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
2023-03-17 12:41:50 +01:00

49 lines
1.2 KiB
Go

package api
import (
"fmt"
"net/http"
"go.uber.org/zap"
)
// HealthzHandler for the Halthz REST API
func HealthzHandler(synced func() bool) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
if !synced() {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprint(w, `{ "error": "Informers not in sync" }`)
zap.L().Warn("informers not synced yet, waiting for k8s client to complete startup")
return
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "{}")
}
}
// ReadyHandler for the Halthz REST API
func ReadyHandler(synced func() bool) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
if !synced() {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprint(w, `{ "error": "Informers not in sync" }`)
zap.L().Warn("informers not synced yet, waiting for k8s client to be up")
return
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "{}")
}
}