Merge pull request #777 from arschles/probes

Add HTTP server for liveness and readiness probes
pull/791/head
Matt Butcher 9 years ago
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)
}
}

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"net" "net"
"net/http"
"os" "os"
"github.com/kubernetes/helm/cmd/tiller/environment" "github.com/kubernetes/helm/cmd/tiller/environment"
@ -21,6 +22,7 @@ var rootServer = grpc.NewServer()
var env = environment.New() var env = environment.New()
var addr = ":44134" var addr = ":44134"
var probe = ":44135"
var namespace = "" var namespace = ""
const globalUsage = `The Kubernetes Helm server. const globalUsage = `The Kubernetes Helm server.
@ -53,10 +55,29 @@ func start(c *cobra.Command, args []string) {
} }
fmt.Printf("Tiller is running on %s\n", addr) fmt.Printf("Tiller is running on %s\n", addr)
fmt.Printf("Tiller probes server is running on %s\n", probe)
srvErrCh := make(chan error)
probeErrCh := make(chan error)
go func() {
if err := rootServer.Serve(lstn); err != nil { if err := rootServer.Serve(lstn); err != nil {
srvErrCh <- err
}
}()
go func() {
mux := newProbesMux()
if err := http.ListenAndServe(addr, mux); err != nil {
probeErrCh <- err
}
}()
select {
case err := <-srvErrCh:
fmt.Fprintf(os.Stderr, "Server died: %s\n", err) fmt.Fprintf(os.Stderr, "Server died: %s\n", err)
os.Exit(1) os.Exit(1)
case err := <-probeErrCh:
fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err)
} }
} }

@ -108,4 +108,16 @@ spec:
- containerPort: 44134 - containerPort: 44134
name: tiller name: tiller
imagePullPolicy: Always imagePullPolicy: Always
livenessProbe:
httpGet:
path: /liveness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /readiness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
` `

Loading…
Cancel
Save