Skip to content

Commit 2008de2

Browse files
committed
fix(helm): address review comments on metrics ServiceMonitor
- Gate ServiceMonitor on Capabilities.APIVersions to avoid install failures on clusters without Prometheus Operator CRDs - Add scheme/tlsConfig to ServiceMonitor endpoint when secure=true - Document secure default and NodePort exposure in values.yaml Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
1 parent ec49ff3 commit 2008de2

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

helm/kagent/templates/controller-servicemonitor.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.controller.metrics.enabled .Values.controller.metrics.serviceMonitor.enabled }}
1+
{{- if and .Values.controller.metrics.enabled .Values.controller.metrics.serviceMonitor.enabled (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1/ServiceMonitor") }}
22
apiVersion: monitoring.coreos.com/v1
33
kind: ServiceMonitor
44
metadata:
@@ -17,4 +17,9 @@ spec:
1717
- port: metrics
1818
interval: {{ .Values.controller.metrics.serviceMonitor.interval }}
1919
scrapeTimeout: {{ .Values.controller.metrics.serviceMonitor.scrapeTimeout }}
20+
{{- if .Values.controller.metrics.secure }}
21+
scheme: https
22+
tlsConfig:
23+
insecureSkipVerify: true
24+
{{- end }}
2025
{{- end }}

helm/kagent/tests/controller-servicemonitor_test.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,40 @@ tests:
77
- hasDocuments:
88
count: 0
99

10-
- it: should not render when only metrics.enabled is true
10+
- it: should not render when CRD is not installed
1111
set:
1212
controller.metrics.enabled: true
13+
controller.metrics.serviceMonitor.enabled: true
1314
asserts:
1415
- hasDocuments:
1516
count: 0
1617

17-
- it: should render ServiceMonitor when both enabled
18+
- it: should render ServiceMonitor when both enabled and CRD present
1819
set:
1920
controller.metrics.enabled: true
2021
controller.metrics.serviceMonitor.enabled: true
22+
capabilities:
23+
apiVersions:
24+
- monitoring.coreos.com/v1/ServiceMonitor
2125
asserts:
2226
- isKind:
2327
of: ServiceMonitor
2428
- equal:
2529
path: spec.endpoints[0].port
2630
value: metrics
31+
32+
- it: should add TLS config when secure is true
33+
set:
34+
controller.metrics.enabled: true
35+
controller.metrics.serviceMonitor.enabled: true
36+
controller.metrics.secure: true
37+
capabilities:
38+
apiVersions:
39+
- monitoring.coreos.com/v1/ServiceMonitor
40+
asserts:
41+
- equal:
42+
path: spec.endpoints[0].scheme
43+
value: https
44+
- equal:
45+
path: spec.endpoints[0].tlsConfig.insecureSkipVerify
46+
value: true

helm/kagent/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ controller:
225225
metrics:
226226
enabled: false
227227
port: 9093
228+
# -- The controller binary defaults to secure=true. Set to false for plain HTTP scraping (most common).
229+
# Note: when the controller Service type is NodePort or LoadBalancer the metrics port will be externally reachable.
228230
secure: false
229231
serviceMonitor:
230232
enabled: false

0 commit comments

Comments
 (0)