mirror of https://github.com/helm/helm
Merge pull request #777 from arschles/probes
Add HTTP server for liveness and readiness probespull/791/head
commit
336c650407
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func readinessProbe(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func livenessProbe(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newProbesMux() *http.ServeMux {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/readiness", readinessProbe)
|
||||||
|
mux.HandleFunc("/liveness", livenessProbe)
|
||||||
|
return mux
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProbesServer(t *testing.T) {
|
||||||
|
mux := newProbesMux()
|
||||||
|
srv := httptest.NewServer(mux)
|
||||||
|
defer srv.Close()
|
||||||
|
resp, err := http.Get(srv.URL + "/readiness")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GET /readiness returned an error (%s)", err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Fatalf("GET /readiness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err = http.Get(srv.URL + "/liveness")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GET /liveness returned an error (%s)", err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Fatalf("GET /liveness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue