Add health and readiness probes to controller manager (#4459)

This commit is contained in:
Junya Okabe
2026-04-29 18:08:46 +02:00
committed by GitHub
parent 13a03302c8
commit 053b8f9ae5
8 changed files with 96 additions and 4 deletions
@@ -73,6 +73,9 @@ spec:
{{- if .Values.dockerGID }} {{- if .Values.dockerGID }}
- "--docker-gid={{ .Values.dockerGID }}" - "--docker-gid={{ .Values.dockerGID }}"
{{- end }} {{- end }}
{{- with .Values.healthProbeBindAddress }}
- "--health-probe-bind-address={{ . }}"
{{- end }}
command: command:
- "/manager" - "/manager"
env: env:
@@ -144,6 +147,20 @@ spec:
name: metrics-port name: metrics-port
protocol: TCP protocol: TCP
{{- end }} {{- end }}
{{- with .Values.healthProbeBindAddress }}
livenessProbe:
httpGet:
path: /healthz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 5
periodSeconds: 10
{{- end }}
resources: resources:
{{- toYaml .Values.resources | nindent 12 }} {{- toYaml .Values.resources | nindent 12 }}
securityContext: securityContext:
@@ -190,6 +190,10 @@ admissionWebHooks:
# There may be alternatives to setting `hostNetwork: true`, see # There may be alternatives to setting `hostNetwork: true`, see
# https://github.com/actions/actions-runner-controller/issues/1005#issuecomment-993097155 # https://github.com/actions/actions-runner-controller/issues/1005#issuecomment-993097155
# The address the health probe endpoint binds to. Disabled if empty.
# When set, liveness and readiness probes are added to the controller pod.
#healthProbeBindAddress: ":8081"
#hostNetwork: true #hostNetwork: true
# If you use `hostNetwork: true`, then you need dnsPolicy: ClusterFirstWithHostNet # If you use `hostNetwork: true`, then you need dnsPolicy: ClusterFirstWithHostNet
@@ -73,6 +73,9 @@ args:
{{- with .Values.controller.manager.config.k8sClientRateLimiterBurst }} {{- with .Values.controller.manager.config.k8sClientRateLimiterBurst }}
- "--k8s-client-rate-limiter-burst={{ . }}" - "--k8s-client-rate-limiter-burst={{ . }}"
{{- end }} {{- end }}
{{- with .Values.controller.manager.config.healthProbeBindAddress }}
- "--health-probe-bind-address={{ . }}"
{{- end }}
{{- with .Values.controller.manager.container.extraArgs }} {{- with .Values.controller.manager.container.extraArgs }}
{{- range . }} {{- range . }}
- "{{ . }}" - "{{ . }}"
@@ -92,6 +95,20 @@ args:
ports: ports:
{{- toYaml $ports | nindent 2 }} {{- toYaml $ports | nindent 2 }}
{{- end }} {{- end }}
{{- with .Values.controller.manager.config.healthProbeBindAddress }}
livenessProbe:
httpGet:
path: /healthz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 5
periodSeconds: 10
{{- end }}
env: env:
- name: CONTROLLER_MANAGER_CONTAINER_IMAGE - name: CONTROLLER_MANAGER_CONTAINER_IMAGE
value: "{{ .Values.controller.manager.container.image }}" value: "{{ .Values.controller.manager.container.image }}"
@@ -44,6 +44,10 @@ controller:
k8sClientRateLimiterQPS: null k8sClientRateLimiterQPS: null
k8sClientRateLimiterBurst: null k8sClientRateLimiterBurst: null
# The address the health probe endpoint binds to. Disabled if empty/null.
# When set, liveness and readiness probes are added to the controller pod.
# healthProbeBindAddress: ":8081"
container: container:
image: "ghcr.io/actions/gha-runner-scale-set-controller:latest" image: "ghcr.io/actions/gha-runner-scale-set-controller:latest"
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
@@ -101,6 +101,9 @@ spec:
- "--workqueue-rate-limiter={{ . }}" - "--workqueue-rate-limiter={{ . }}"
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- with .Values.flags.healthProbeBindAddress }}
- "--health-probe-bind-address={{ . }}"
{{- end }}
command: command:
- "/manager" - "/manager"
{{- if or .Values.metrics .Values.pprof.addr }} {{- if or .Values.metrics .Values.pprof.addr }}
@@ -116,6 +119,20 @@ spec:
protocol: TCP protocol: TCP
name: pprof name: pprof
{{- end }} {{- end }}
{{- with .Values.flags.healthProbeBindAddress }}
livenessProbe:
httpGet:
path: /healthz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: {{ regexFind "[0-9]+$" . }}
initialDelaySeconds: 5
periodSeconds: 10
{{- end }}
env: env:
- name: CONTROLLER_MANAGER_CONTAINER_IMAGE - name: CONTROLLER_MANAGER_CONTAINER_IMAGE
value: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" value: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
@@ -150,6 +150,10 @@ flags:
# Overrides the default `.Release.Namespace` for all resources in this chart. # Overrides the default `.Release.Namespace` for all resources in this chart.
namespaceOverride: "" namespaceOverride: ""
## The address the health probe endpoint binds to. Disabled if empty.
## When set, liveness and readiness probes are added to the controller pod.
# healthProbeBindAddress: ":8081"
## Defines the K8s client rate limiter parameters. ## Defines the K8s client rate limiter parameters.
# k8sClientRateLimiterQPS: 20 # k8sClientRateLimiterQPS: 20
# k8sClientRateLimiterBurst: 30 # k8sClientRateLimiterBurst: 30
+14
View File
@@ -56,6 +56,20 @@ spec:
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.namespace fieldPath: metadata.namespace
# To enable health probes, uncomment the following and add
# "--health-probe-bind-address=:8081" to the container args.
# livenessProbe:
# httpGet:
# path: /healthz
# port: 8081
# initialDelaySeconds: 15
# periodSeconds: 20
# readinessProbe:
# httpGet:
# path: /readyz
# port: 8081
# initialDelaySeconds: 5
# periodSeconds: 10
volumeMounts: volumeMounts:
- name: controller-manager - name: controller-manager
mountPath: "/etc/actions-runner-controller" mountPath: "/etc/actions-runner-controller"
+19 -4
View File
@@ -43,6 +43,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -86,6 +87,7 @@ func main() {
metricsAddr string metricsAddr string
pprofAddr string pprofAddr string
probeAddr string
autoScalingRunnerSetOnly bool autoScalingRunnerSetOnly bool
enableLeaderElection bool enableLeaderElection bool
disableAdmissionWebhook bool disableAdmissionWebhook bool
@@ -127,6 +129,7 @@ func main() {
flag.StringVar(&listenerMetricsEndpoint, "listener-metrics-endpoint", "/metrics", "The AutoscalingListener metrics server endpoint from which the metrics are collected") flag.StringVar(&listenerMetricsEndpoint, "listener-metrics-endpoint", "/metrics", "The AutoscalingListener metrics server endpoint from which the metrics are collected")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-addr", "", "The address the pprof endpoint binds to.") flag.StringVar(&pprofAddr, "pprof-addr", "", "The address the pprof endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "", "The address the health probe endpoint binds to. Disabled if empty.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&leaderElectionID, "leader-election-id", "actions-runner-controller", "Controller id for leader election.") flag.StringVar(&leaderElectionID, "leader-election-id", "actions-runner-controller", "Controller id for leader election.")
@@ -246,10 +249,11 @@ func main() {
SyncPeriod: &syncPeriod, SyncPeriod: &syncPeriod,
DefaultNamespaces: defaultNamespaces, DefaultNamespaces: defaultNamespaces,
}, },
PprofBindAddress: pprofAddr, PprofBindAddress: pprofAddr,
WebhookServer: webhookServer, WebhookServer: webhookServer,
LeaderElection: enableLeaderElection, HealthProbeBindAddress: probeAddr,
LeaderElectionID: leaderElectionID, LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionID,
Client: client.Options{ Client: client.Options{
Cache: &client.CacheOptions{ Cache: &client.CacheOptions{
DisableFor: []client.Object{ DisableFor: []client.Object{
@@ -264,6 +268,17 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if probeAddr != "" {
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
log.Error(err, "unable to set up ready check")
os.Exit(1)
}
}
if autoScalingRunnerSetOnly { if autoScalingRunnerSetOnly {
if err := actionsgithubcom.SetupIndexers(mgr); err != nil { if err := actionsgithubcom.SetupIndexers(mgr); err != nil {
log.Error(err, "unable to setup indexers") log.Error(err, "unable to setup indexers")