Skip to content

Commit

Permalink
Switch webhook liveness/readiness probes to http ports
Browse files Browse the repository at this point in the history
  • Loading branch information
ywluogg authored and tekton-robot committed Oct 19, 2020
1 parent 075c233 commit 7559968
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
23 changes: 23 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"context"
"log"
"net/http"
"os"

defaultconfig "github.com/tektoncd/pipeline/pkg/apis/config"
Expand Down Expand Up @@ -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,
Expand All @@ -222,3 +241,7 @@ func main() {
newConversionController,
)
}

func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
17 changes: 13 additions & 4 deletions config/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7559968

Please sign in to comment.