Skip to content

Commit f15f26c

Browse files
jocelynthodepree
andauthored
feat: Allow ServiceMonitor port and scheme change (#139)
* feat: Allow ServiceMonitor port and scheme change Signed-off-by: Jocelyn Thode <jocelyn@thode.email> * feat: Add extraPorts to server Service Signed-off-by: Jocelyn Thode <jocelyn@thode.email> * chore: upgrade to 0.25.2 Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> --------- Signed-off-by: Jocelyn Thode <jocelyn@thode.email> Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> Co-authored-by: Pascal Reeb <pascal.reeb@secretz.io>
1 parent de4bc8f commit f15f26c

File tree

8 files changed

+91
-9
lines changed

8 files changed

+91
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Unreleased
22

3+
### 0.25.2
4+
5+
- feat: Allow ServiceMonitor port and scheme change
6+
- feat: Add extraPorts to server Service
7+
38
### 0.25.1
49

510
- fix(snapshotAgent): change extraVolumes to list instead of object

charts/openbao/Chart.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
apiVersion: v2
55
name: openbao
6-
version: 0.25.1
6+
version: 0.25.2
77
appVersion: v2.5.0
88
kubeVersion: ">= 1.30.0-0"
99
description: Official OpenBao Chart
@@ -26,12 +26,12 @@ annotations:
2626
charts.openshift.io/name: Openbao
2727
artifacthub.io/containsSecurityUpdates: "false"
2828
artifacthub.io/changes: |
29-
- kind: fixed
29+
- kind: changed
3030
description: |
31-
fix(snapshotAgent): change extraVolumes to list instead of object
32-
links:
33-
- name: OpenBao 2.5.0 Release
34-
url: https://github.com/openbao/openbao/releases/tag/v2.5.0
31+
feat: Allow ServiceMonitor port and scheme change
32+
- kind: changed
33+
description: |
34+
feat: Add extraPorts to server Service
3535
maintainers:
3636
- name: OpenBao
3737
email: openbao-security@lists.openssf.org

charts/openbao/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# openbao
22

3-
![Version: 0.25.1](https://img.shields.io/badge/Version-0.25.1-informational?style=flat-square) ![AppVersion: v2.5.0](https://img.shields.io/badge/AppVersion-v2.5.0-informational?style=flat-square)
3+
![Version: 0.25.2](https://img.shields.io/badge/Version-0.25.2-informational?style=flat-square) ![AppVersion: v2.5.0](https://img.shields.io/badge/AppVersion-v2.5.0-informational?style=flat-square)
44

55
Official OpenBao Chart
66

@@ -279,6 +279,7 @@ Kubernetes: `>= 1.30.0-0`
279279
| server.service.enabled | bool | `true` | |
280280
| server.service.externalTrafficPolicy | string | `"Cluster"` | |
281281
| server.service.extraLabels | object | `{}` | |
282+
| server.service.extraPorts | list | `[]` | extraPorts is a list of extra ports. Specified as a YAML list. This is useful if you need to add additional ports to the server service in dynamic way. |
282283
| server.service.instanceSelector.enabled | bool | `true` | |
283284
| server.service.ipFamilies | list | `[]` | |
284285
| server.service.ipFamilyPolicy | string | `""` | |
@@ -316,6 +317,8 @@ Kubernetes: `>= 1.30.0-0`
316317
| serverTelemetry.serviceMonitor.authorization | object | `{}` | |
317318
| serverTelemetry.serviceMonitor.enabled | bool | `false` | |
318319
| serverTelemetry.serviceMonitor.interval | string | `"30s"` | |
320+
| serverTelemetry.serviceMonitor.port | string | `""` | Port which Prometheus uses when scraping metrics. If empty will use `openbao.scheme` helper for its value |
321+
| serverTelemetry.serviceMonitor.scheme | string | `""` | scheme to use when Prometheus scrapes metrics. If empty will use `openbao.scheme` helper for its value |
319322
| serverTelemetry.serviceMonitor.scrapeClass | string | `""` | |
320323
| serverTelemetry.serviceMonitor.scrapeTimeout | string | `"10s"` | |
321324
| serverTelemetry.serviceMonitor.selectors | object | `{}` | |

charts/openbao/templates/prometheus-servicemonitor.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ spec:
3737
openbao-internal: "true"
3838
{{- end }}
3939
endpoints:
40-
- port: {{ include "openbao.scheme" . }}
40+
- port: {{ .Values.serverTelemetry.serviceMonitor.port | default (include "openbao.scheme" .) }}
4141
interval: {{ .Values.serverTelemetry.serviceMonitor.interval }}
4242
scrapeTimeout: {{ .Values.serverTelemetry.serviceMonitor.scrapeTimeout }}
43-
scheme: {{ include "openbao.scheme" . | lower }}
43+
scheme: {{ .Values.serverTelemetry.serviceMonitor.scheme | default (include "openbao.scheme" .) | lower }}
4444
path: /v1/sys/metrics
4545
params:
4646
format:

charts/openbao/templates/server-service.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ spec:
5151
- name: https-internal
5252
port: 8201
5353
targetPort: 8201
54+
{{- if .Values.server.service.extraPorts -}}
55+
{{ toYaml .Values.server.service.extraPorts | nindent 4}}
56+
{{- end }}
5457
selector:
5558
app.kubernetes.io/name: {{ include "openbao.name" . }}
5659
{{- if eq (.Values.server.service.instanceSelector.enabled | toString) "true" }}

charts/openbao/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,14 @@ server:
868868
port: 8200
869869
# Target port to which the service should be mapped to
870870
targetPort: 8200
871+
872+
# -- extraPorts is a list of extra ports. Specified as a YAML list.
873+
# This is useful if you need to add additional ports to the server service in dynamic way.
874+
extraPorts: []
875+
# - name: metrics
876+
# port: 9101
877+
# targetPort: 9101
878+
871879
# Extra annotations for the service definition. This can either be YAML or a
872880
# YAML-formatted multi-line templated string map of the annotations to apply
873881
# to the service.
@@ -1414,6 +1422,12 @@ serverTelemetry:
14141422
# release: prometheus
14151423
selectors: {}
14161424

1425+
# -- Port which Prometheus uses when scraping metrics. If empty will use `openbao.scheme` helper for its value
1426+
port: ""
1427+
1428+
# -- scheme to use when Prometheus scrapes metrics. If empty will use `openbao.scheme` helper for its value
1429+
scheme: ""
1430+
14171431
# Interval at which Prometheus scrapes metrics
14181432
interval: 30s
14191433

test/unit/prometheus-servicemonitor.bats

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ load _helpers
110110

111111
[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
112112
[ "$(echo "$output" | yq -r '.spec.endpoints[0].port')" = "http" ]
113+
[ "$(echo "$output" | yq -r '.spec.endpoints[0].scheme')" = "http" ]
113114
}
114115

115116
@test "prometheus/ServiceMonitor-server: assertEndpoints TLS" {
@@ -122,6 +123,31 @@ load _helpers
122123

123124
[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
124125
[ "$(echo "$output" | yq -r '.spec.endpoints[0].port')" = "https" ]
126+
[ "$(echo "$output" | yq -r '.spec.endpoints[0].scheme')" = "https" ]
127+
}
128+
129+
@test "prometheus/ServiceMonitor-server: assertEndpointsPort update" {
130+
cd `chart_dir`
131+
local output=$( (helm template \
132+
--show-only templates/prometheus-servicemonitor.yaml \
133+
--set 'serverTelemetry.serviceMonitor.enabled=true' \
134+
--set 'serverTelemetry.serviceMonitor.port=metrics-tls' \
135+
.) | tee /dev/stderr)
136+
137+
[ "$(echo "$output" | yq -r '.spec.endpoints[0].port')" = "metrics-tls" ]
138+
}
139+
140+
@test "prometheus/ServiceMonitor-server: assertEndpointsScheme update" {
141+
cd `chart_dir`
142+
local output=$( (helm template \
143+
--show-only templates/prometheus-servicemonitor.yaml \
144+
--set 'serverTelemetry.serviceMonitor.enabled=true' \
145+
--set 'global.tlsDisable=false' \
146+
--set 'serverTelemetry.serviceMonitor.scheme=http' \
147+
.) | tee /dev/stderr)
148+
149+
[ "$(echo "$output" | yq -r '.spec.endpoints[0].port')" = "https" ]
150+
[ "$(echo "$output" | yq -r '.spec.endpoints[0].scheme')" = "http" ]
125151
}
126152

127153
@test "prometheus/ServiceMonitor-server: tlsConfig default" {

test/unit/server-service.bats

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,37 @@ load _helpers
421421
[ "${actual}" = "https" ]
422422
}
423423

424+
@test "server/Service: extraPorts assert is empty by default" {
425+
cd `chart_dir`
426+
local actual=$(helm template \
427+
--show-only templates/server-service.yaml \
428+
. | tee /dev/stderr)
429+
[ "$(echo "$actual" | yq -r '.spec.ports | length')" = "2" ]
430+
}
431+
432+
@test "server/Service: adds extra ports" {
433+
cd `chart_dir`
434+
local object=$(helm template \
435+
--show-only templates/server-service.yaml \
436+
--set 'server.service.extraPorts[0].port=9101' \
437+
--set 'server.service.extraPorts[0].targetPort=9101' \
438+
--set 'server.service.extraPorts[0].name=metrics' \
439+
. | tee /dev/stderr |
440+
yq -r '.spec.ports[] | select(.name == "metrics")' | tee /dev/stderr)
441+
442+
local actual=$(echo $object |
443+
yq -r '.port' | tee /dev/stderr)
444+
[ "${actual}" = "9101" ]
445+
446+
local actual=$(echo $object |
447+
yq -r '.targetPort' | tee /dev/stderr)
448+
[ "${actual}" = "9101" ]
449+
450+
local actual=$(echo $object |
451+
yq -r '.name' | tee /dev/stderr)
452+
[ "${actual}" = "metrics" ]
453+
}
454+
424455
# duplicated in server-ha-active-service.bats
425456
@test "server/Service: NodePort assert externalTrafficPolicy" {
426457
cd `chart_dir`

0 commit comments

Comments
 (0)