Repository navigation
Add initial /health probe - #583
Merged
Merged
Conversation
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces HTTP health endpoints to the local-path-provisioner process and wires them into the upstream YAML manifests and Helm chart so Kubernetes can perform startup/liveness/readiness probing (per issue #208).
Changes:
- Add an internal health HTTP server with
/health(liveness/startup) and/ready(readiness) endpoints. - Update static deployment manifests to expose a health port and configure startup/liveness/readiness probes.
- Add Helm values and template support to enable/disable probes and override probe definitions/port.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| main.go | Adds health server, CLI/env configuration, and readiness checks implemented via Kubernetes API calls. |
| health_test.go | Adds handler-level unit tests for /health. |
| deploy/provisioner.yaml | Exposes health port and configures probes + HEALTH_PORT env var in the static manifest. |
| deploy/local-path-storage.yaml | Same as above for the namespaced install manifest. |
| deploy/chart/local-path-provisioner/values.yaml | Adds health.* values for configuring probes/port in Helm. |
| deploy/chart/local-path-provisioner/templates/deployment.yaml | Renders health env var, port, and probes when enabled via values. |
Comments suppressed due to low confidence (5)
main.go:10
- The health server improvements below require the time package, but main.go doesn't import it yet. Add the standard-library "time" import so the code compiles once timeouts/shutdown logic are introduced.
This issue also appears in the following locations of the same file:
- line 244
- line 356
- line 374
- line 383
"path/filepath"
"syscall"
main.go:245
- health-port isn't validated. Values like 0, negative numbers, or >65535 will result in an unexpected bind address (or immediate listen failure) while the process continues running, which will make Kubernetes probes fail silently.
healthPort := c.Int(FlagHealthPort)
startHealthServer(ctx, healthPort, kubeClient, namespace)
main.go:372
- startHealthServer ignores the provided context and uses http.ListenAndServe without any timeouts. This can leak the server goroutine during shutdown and leaves the endpoint more vulnerable to slowloris-style connections. Prefer an http.Server with ReadHeaderTimeout and shut it down when ctx is cancelled.
func startHealthServer(ctx context.Context, port int, kubeClient clientset.Interface, namespace string) {
mux := http.NewServeMux()
mux.HandleFunc("/health", healthHandler)
mux.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
readyHandler(ctx, kubeClient, namespace, w, r)
})
address := fmt.Sprintf(":%d", port)
go func() {
if err := http.ListenAndServe(address, mux); err != nil {
logrus.Errorf("Failed to start health server: %v", err)
}
}()
logrus.Infof("Health server started on %s", address)
}
main.go:392
- readyHandler uses the daemon-level ctx for API calls, which ignores client disconnects and provides no per-request deadline. A hung apiserver call can stall probe requests and accumulate goroutines. Use r.Context() with a short timeout, and apply the same method filtering as /health.
func readyHandler(ctx context.Context, kubeClient clientset.Interface, namespace string, w http.ResponseWriter, r *http.Request) {
err := checkReadiness(ctx, kubeClient, namespace)
if err != nil {
logrus.Warnf("Readiness check failed: %v", err)
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("Ready"))
}
main.go:381
- healthHandler always writes a response body even for HEAD/OPTIONS. For correctness (and to make it easier to test), only write the body for GET and set an Allow header on 405 responses.
func healthHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead && r.Method != http.MethodOptions {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+37
to
+41
| if tt.body != "" { | ||
| body, err := io.ReadAll(resp.Body) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.body, string(body)) | ||
| } |
Comment on lines
+95
to
+99
| {{- if .Values.health.enabled }} | ||
| ports: | ||
| - name: health | ||
| containerPort: {{ .Values.health.port | default 8080 }} | ||
| protocol: TCP |
Comment on lines
+394
to
+418
| func checkReadiness(ctx context.Context, kubeClient clientset.Interface, namespace string) error { | ||
| tests := []struct { | ||
| name string | ||
| check func(context.Context) error | ||
| }{ | ||
| {"configmaps", func(ctx context.Context) error { | ||
| _, err := kubeClient.CoreV1().ConfigMaps(namespace).List(ctx, metav1.ListOptions{Limit: 1}) | ||
| return err | ||
| }}, | ||
| {"pods", func(ctx context.Context) error { | ||
| _, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{Limit: 1}) | ||
| return err | ||
| }}, | ||
| {"persistentvolumeclaims", func(ctx context.Context) error { | ||
| _, err := kubeClient.CoreV1().PersistentVolumeClaims(namespace).List(ctx, metav1.ListOptions{Limit: 1}) | ||
| return err | ||
| }}, | ||
| {"persistentvolumes", func(ctx context.Context) error { | ||
| _, err := kubeClient.CoreV1().PersistentVolumes().List(ctx, metav1.ListOptions{Limit: 1}) | ||
| return err | ||
| }}, | ||
| {"storageclasses", func(ctx context.Context) error { | ||
| _, err := kubeClient.StorageV1().StorageClasses().List(ctx, metav1.ListOptions{Limit: 1}) | ||
| return err | ||
| }}, |
1 task
This was referenced Nov 4, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a trivial health probes per #208