mirror of
https://github.com/axllent/mailpit.git
synced 2024-12-28 23:06:43 +02:00
c1694f1a22
Kubernetes checks if a pod is ok and if it can retrieve traffic using probes. This commit add two routes to make a liveness probe and a readiness probe.
18 lines
449 B
Go
18 lines
449 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// ReadyzHandler is a ready probe that signals k8s to be able to retrieve traffic
|
|
func ReadyzHandler(isReady *atomic.Value) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
|
if isReady == nil || !isReady.Load().(bool) {
|
|
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusOK)
|
|
}
|
|
}
|