Repository navigation
Commit 51bbe57
committed
feat(core): make the controller metrics bind address configurable
The manager is constructed with metricsserver.Options{BindAddress: "0"},
so the controller serves no Prometheus metrics and no env or flag can
change that. The Helm chart already renders METRICS_BIND_ADDRESS and
METRICS_SECURE from controller.metrics, and kagent-dev#2401 added a metrics
Service, a ServiceMonitor and the metrics-auth and metrics-reader
ClusterRoles for that endpoint, but nothing reads the variables: the
scrape target stays at up=0 because the port is never bound.
Register both variables in the env package next to LEADER_ELECT, where
they are documented and typed like every other controller variable, and
read them when building the manager options. METRICS_BIND_ADDRESS
defaults to "0", so an installation that sets nothing serves no metrics
exactly as before, and controller.metrics.enabled=false renders neither
variable. An empty value resolves to "0" as well: controller-runtime
reads an empty BindAddress as unset and falls back to :8080, so
METRICS_BIND_ADDRESS="" would otherwise open a metrics port nobody asked
for.
A secure endpoint also sets FilterProvider, so every scrape is
authenticated with a TokenReview and authorized with a
SubjectAccessReview on the /metrics nonResourceURL. Without it,
METRICS_SECURE=true would encrypt the endpoint but serve any caller that
reaches the port, and the chart's metrics-reader binding would grant
nothing. The tokenreviews and subjectaccessreviews create rules the
filter needs are not on the controller ClusterRole: the chart renders
them as a separate <fullname>-metrics-auth-role ClusterRole and its
ClusterRoleBinding, both gated on controller.metrics.enabled and
controller.metrics.secureServing.
The filters package adds two indirect requirements to go.mod, both new
to the module graph and both reached only through it:
pkg/metrics/filters pulls k8s.io/apiserver/pkg/authentication/
authenticatorfactory, which pulls k8s.io/component-base/metrics, which
pulls github.com/blang/semver/v4. No package of the main module imports
either one directly.
Signed-off-by: QuentinBisson <[email protected]>1 parent 7471879 commit 51bbe57
4 files changed
Lines changed: 74 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
219 | 230 | | |
220 | 231 | | |
221 | 232 | | |
222 | 233 | | |
223 | | - | |
| 234 | + | |
224 | 235 | | |
225 | 236 | | |
226 | 237 | | |
| |||
369 | 380 | | |
370 | 381 | | |
371 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
372 | 393 | | |
373 | 394 | | |
374 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
100 | 132 | | |
101 | 133 | | |
102 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
12 | 30 | | |
13 | 31 | | |
14 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
| |||
461 | 462 | | |
462 | 463 | | |
463 | 464 | | |
| 465 | + | |
464 | 466 | | |
465 | 467 | | |
466 | 468 | | |
| |||
0 commit comments