From 52dc53c071535b2ac91c4f27a00a9dd33bdb42fe Mon Sep 17 00:00:00 2001 From: Knative Prow Robot Date: Mon, 17 Oct 2022 06:34:57 +0100 Subject: [PATCH] Add readiness and liveness probes in controller (#6570) Co-authored-by: Lionel Villard --- cmd/controller/main.go | 26 +++++++++++++++++++++++++ config/core/deployments/controller.yaml | 19 ++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 1243fad399c..f594701fb69 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -20,6 +20,10 @@ import ( // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + "log" + "net/http" + "os" + "knative.dev/pkg/injection/sharedmain" "knative.dev/eventing/pkg/reconciler/apiserversource" @@ -36,6 +40,24 @@ import ( ) func main() { + // sets up liveness and readiness probes. + mux := http.NewServeMux() + + mux.HandleFunc("/", handler) + mux.HandleFunc("/health", handler) + mux.HandleFunc("/readiness", handler) + + port := os.Getenv("PROBES_PORT") + if port == "" { + port = "8080" + } + + go func() { + // start the web server on port and accept requests + log.Printf("Readiness and health check server listening on port %s", port) + log.Fatal(http.ListenAndServe(":"+port, mux)) + }() + sharedmain.Main("controller", // Messaging channel.NewController, @@ -60,3 +82,7 @@ func main() { sugartrigger.NewController, ) } + +func handler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) +} diff --git a/config/core/deployments/controller.yaml b/config/core/deployments/controller.yaml index cf35cfcbe36..304b230bd4c 100644 --- a/config/core/deployments/controller.yaml +++ b/config/core/deployments/controller.yaml @@ -98,8 +98,27 @@ spec: drop: - all + livenessProbe: + httpGet: + path: /health + port: probes + scheme: HTTP + initialDelaySeconds: 20 + periodSeconds: 10 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /readiness + port: probes + scheme: HTTP + initialDelaySeconds: 20 + periodSeconds: 10 + timeoutSeconds: 5 + ports: - name: metrics containerPort: 9090 - name: profiling containerPort: 8008 + - name: probes + containerPort: 8080