From 7559968f77f6adf7422420b8fdd1ab9cc4b80e31 Mon Sep 17 00:00:00 2001 From: ywluogg Date: Tue, 6 Oct 2020 20:00:51 -0400 Subject: [PATCH] Switch webhook liveness/readiness probes to http ports --- cmd/webhook/main.go | 23 +++++++++++++++++++++++ config/webhook.yaml | 17 +++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 4737b7addeb..974cdbd1627 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -18,6 +18,8 @@ package main import ( "context" + "log" + "net/http" "os" defaultconfig "github.com/tektoncd/pipeline/pkg/apis/config" @@ -213,6 +215,23 @@ func main() { SecretName: secretName, }) + 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.WebhookMainWithConfig(ctx, "webhook", sharedmain.ParseAndGetConfigOrDie(), certificates.NewController, @@ -222,3 +241,7 @@ func main() { newConversionController, ) } + +func handler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) +} diff --git a/config/webhook.yaml b/config/webhook.yaml index 20642ea9c90..04ebbae0393 100644 --- a/config/webhook.yaml +++ b/config/webhook.yaml @@ -91,17 +91,24 @@ spec: containerPort: 8008 - name: https-webhook containerPort: 8443 + - name: probes + containerPort: 8080 livenessProbe: - tcpSocket: - port: https-webhook + httpGet: + path: /health + port: probes + scheme: HTTP initialDelaySeconds: 5 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: - tcpSocket: - port: https-webhook + httpGet: + path: /readiness + port: probes + scheme: HTTP initialDelaySeconds: 5 periodSeconds: 10 + timeoutSeconds: 5 --- apiVersion: v1 kind: Service @@ -131,6 +138,8 @@ spec: - name: https-webhook port: 443 targetPort: 8443 + - name: probes + port: 8080 selector: app.kubernetes.io/name: webhook app.kubernetes.io/component: webhook