Skip to content

Commit

Permalink
Add readiness and liveness probes in controller (#6570)
Browse files Browse the repository at this point in the history
Co-authored-by: Lionel Villard <[email protected]>
  • Loading branch information
knative-prow-robot and lionelvillard authored Oct 17, 2022
1 parent 0bf545a commit 52dc53c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -60,3 +82,7 @@ func main() {
sugartrigger.NewController,
)
}

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

0 comments on commit 52dc53c

Please sign in to comment.