add health check

This commit adds a liveness probe to the manager rc and
a healthz endpoint that returns 200 OK.
pull/197/head
Michelle Noorali 9 years ago
parent 5343c35b7e
commit f897dc5b1d

@ -147,6 +147,13 @@ spec:
containers: containers:
- env: [] - env: []
image: gcr.io/dm-k8s-testing/manager:latest image: gcr.io/dm-k8s-testing/manager:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 1
name: manager name: manager
ports: ports:
- containerPort: 8080 - containerPort: 8080

@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"github.com/kubernetes/deployment-manager/util"
"github.com/kubernetes/deployment-manager/version" "github.com/kubernetes/deployment-manager/version"
"flag" "flag"
@ -38,7 +39,9 @@ type Route struct {
Type string Type string
} }
var routes = []Route{} var routes = []Route{
{"HealthCheck", "/healthz", "GET", healthCheckHandlerFunc, ""},
}
// port to listen on // port to listen on
var port = flag.Int("port", 8080, "The port to listen on") var port = flag.Int("port", 8080, "The port to listen on")
@ -80,3 +83,9 @@ func main() {
log.Printf("Listening on port %d...", *port) log.Printf("Listening on port %d...", *port)
log.Fatal(http.ListenAndServe(address, handler)) log.Fatal(http.ListenAndServe(address, handler))
} }
func healthCheckHandlerFunc(w http.ResponseWriter, r *http.Request) {
handler := "manager: get health"
util.LogHandlerEntry(handler, r)
util.LogHandlerExitWithText(handler, w, "OK", http.StatusOK)
}

@ -129,6 +129,15 @@ func LogAndReturnError(handler string, statusCode int, err error, w http.Respons
http.Error(w, err.Error(), statusCode) http.Error(w, err.Error(), statusCode)
} }
// LogHandlerExitWithText converts the given string to []byte,
// writes it to the response body, returns the given status,
// and then logs the response
func LogHandlerExitWithText(handler string, w http.ResponseWriter, v string, statusCode int) {
msg := []byte(v)
WriteResponse(handler, w, msg, "text/plain; charset=UTF-8", statusCode)
LogHandlerExit(handler, statusCode, string(msg), w)
}
// LogHandlerExitWithJSON marshals the given object as JSON, // LogHandlerExitWithJSON marshals the given object as JSON,
// writes it to the response body, returns the given status, and then logs the // writes it to the response body, returns the given status, and then logs the
// response. // response.

Loading…
Cancel
Save