Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VC-36444: Add a health check and liveness probe #580

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions deploy/charts/venafi-kubernetes-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ spec:
- containerPort: 8081
name: http-metrics
{{- end }}
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
36 changes: 25 additions & 11 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,32 @@ func Run(cmd *cobra.Command, args []string) {
}
}()
}
if Flags.Prometheus {
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus server on port :8081")
go func() {

go func() {
server := http.NewServeMux()

if Flags.Prometheus {
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus on port :8081")
prometheus.MustRegister(metricPayloadSize)
metricsServer := http.NewServeMux()
metricsServer.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":8081", metricsServer)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
logs.Log.Fatalf("failed to run prometheus server: %s", err)
}
}()
}
server.Handle("/metrics", promhttp.Handler())
}

// Health check endpoint. Since we haven't figured a good way of knowning
// what "ready" means for the agent, we just return 200 OK inconditionally.
// The goal is to satisfy some Kubernetes distributions, like OpenShift,
// that require a liveness and health probe to be present for each pod.
server.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
server.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

err := http.ListenAndServe(":8081", server)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
logs.Log.Fatalf("failed to run the health check server: %s", err)
}
}()

_, isVenConn := preflightClient.(*client.VenConnClient)
if isVenConn {
Expand Down
Loading