Files
zot/pkg/common/healthz.go
T
Asgeir Storesund Nilsen c298818cc2 feat: healthz server (#3228)
* feat: healthz server

Signed-off-by: Asgeir Nilsen <asgeir@twingine.no>

* fix: startup and readiness probe activation points

Enable startup probe at end of Controller.Init and readiness probe at
end of Controller.Run

Signed-off-by: Asgeir Nilsen <asgeir@twingine.no>

* fix: rewrote to reuse same HTTP listener

Signed-off-by: Asgeir Nilsen <asgeir@twingine.no>

---------

Signed-off-by: Asgeir Nilsen <asgeir@twingine.no>
2025-07-04 19:13:01 +03:00

65 lines
1.1 KiB
Go

package common
import (
"errors"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"zotregistry.dev/zot/pkg/api/config"
"zotregistry.dev/zot/pkg/log"
)
var errNotReady = errors.New("not ready yet")
type Healthz struct {
log log.Logger
ready bool
started bool
Handler *healthz.Handler
}
func NewHealthzServer(appConfig *config.Config, logger log.Logger) *Healthz {
var health Healthz
health.ready = false
health.started = false
health.log = logger
health.Handler = &healthz.Handler{Checks: map[string]healthz.Checker{
"livez": health.livez,
"readyz": health.readyz,
"startupz": health.startupz,
}}
return &health
}
func (h *Healthz) livez(req *http.Request) error {
return nil
}
func (h *Healthz) readyz(req *http.Request) error {
if h.ready {
return nil
}
return errNotReady
}
func (h *Healthz) startupz(req *http.Request) error {
if h.started {
return nil
}
return errNotReady
}
func (h *Healthz) Ready() {
h.ready = true
h.log.Debug().Msg("ready")
}
func (h *Healthz) Started() {
h.started = true
h.log.Debug().Msg("started")
}