Skip to content

Commit 569cc7f

Browse files
authored
fix: Add annotations for headless service (#143)
* fix: Add annotations for headless service Signed-off-by: ymkc <sixth_brother@gmx.net>
1 parent bb30070 commit 569cc7f

File tree

7 files changed

+85
-4
lines changed

7 files changed

+85
-4
lines changed

CHANGELOG.md

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

3+
### 0.25.4
4+
5+
- fix: Add annotations for headless service
6+
37
### 0.25.3
48

59
- fix: Add extraPorts to server Service in ha

charts/openbao/Chart.yaml

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

44
apiVersion: v2
55
name: openbao
6-
version: 0.25.3
6+
version: 0.25.4
77
appVersion: v2.5.0
88
kubeVersion: ">= 1.30.0-0"
99
description: Official OpenBao Chart
@@ -28,7 +28,7 @@ annotations:
2828
artifacthub.io/changes: |
2929
- kind: changed
3030
description: |
31-
fix: Add extraPorts to server Service in ha
31+
fix: Add annotations for headless service
3232
maintainers:
3333
- name: OpenBao
3434
email: openbao-security@lists.openssf.org

charts/openbao/README.md

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

3-
![Version: 0.25.3](https://img.shields.io/badge/Version-0.25.3-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.4](https://img.shields.io/badge/Version-0.25.4-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

@@ -280,6 +280,7 @@ Kubernetes: `>= 1.30.0-0`
280280
| server.service.externalTrafficPolicy | string | `"Cluster"` | |
281281
| server.service.extraLabels | object | `{}` | |
282282
| 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. |
283+
| server.service.headless.annotations | object | `{}` | |
283284
| server.service.instanceSelector.enabled | bool | `true` | |
284285
| server.service.ipFamilies | list | `[]` | |
285286
| server.service.ipFamilyPolicy | string | `""` | |

charts/openbao/templates/_helpers.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,23 @@ Sets extra openbao server Service (standby) annotations
786786
{{- end }}
787787
{{- end -}}
788788

789+
{{/*
790+
Sets extra openbao server Service (headless) annotations
791+
*/}}
792+
{{- define "openbao.service.headless.annotations" -}}
793+
{{- $headless := .Values.server.service.headless.annotations -}}
794+
{{- $generic := .Values.server.service.annotations -}}
795+
{{- if or $headless $generic }}
796+
annotations:
797+
{{- if $headless }}
798+
{{- include "openbao.annotations.render.4" (list . $headless) -}}
799+
{{- end }}
800+
{{- if $generic }}
801+
{{- include "openbao.annotations.render.4" (list . $generic) -}}
802+
{{- end }}
803+
{{- end }}
804+
{{- end -}}
805+
789806
{{/*
790807
Sets PodSecurityPolicy annotations
791808
*/}}

charts/openbao/templates/server-headless-service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ metadata:
1919
app.kubernetes.io/instance: {{ .Release.Name }}
2020
app.kubernetes.io/managed-by: {{ .Release.Service }}
2121
openbao-internal: "true"
22-
{{ template "openbao.service.annotations" .}}
22+
{{- template "openbao.service.headless.annotations" .}}
2323
spec:
2424
{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
2525
{{- if .Values.server.service.ipFamilyPolicy }}

charts/openbao/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ server:
807807
# Extra labels for the service definition.
808808
# This should be a YAML map of the labels to apply to the standby service
809809
extraLabels: {}
810+
headless:
811+
# Extra annotations for the headless service definition. This can either be YAML or a
812+
# YAML-formatted multi-line templated string map of the annotations to apply
813+
# to the headless service.
814+
annotations: {}
810815
# If enabled, the service selectors will include `app.kubernetes.io/instance: {{ .Release.Name }}`
811816
# When disabled, services may select OpenBao pods not deployed from the chart.
812817
# Does not affect the headless openbao-internal service with `ClusterIP: None`

test/unit/server-headless-service.bats

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,57 @@ load _helpers
7474
yq '.spec.ipFamilies' -c | tee /dev/stderr)
7575
[ "${actual}" = '["IPv4","IPv6"]' ]
7676
}
77+
78+
@test "server/headless-Service: generic annotations string" {
79+
cd `chart_dir`
80+
local actual=$(helm template \
81+
--show-only templates/server-headless-service.yaml \
82+
--set 'server.service.annotations=openBaoIsAwesome: true' \
83+
. | tee /dev/stderr |
84+
yq -r '.metadata.annotations["openBaoIsAwesome"]' | tee /dev/stderr)
85+
[ "${actual}" = "true" ]
86+
}
87+
88+
@test "server/headless-Service: generic annotations yaml" {
89+
cd `chart_dir`
90+
local actual=$(helm template \
91+
--show-only templates/server-headless-service.yaml \
92+
--set 'server.service.annotations.openBaoIsAwesome=true' \
93+
. | tee /dev/stderr |
94+
yq -r '.metadata.annotations["openBaoIsAwesome"]' | tee /dev/stderr)
95+
[ "${actual}" = "true" ]
96+
}
97+
98+
@test "server/headless-Service: with headless annotations string" {
99+
cd `chart_dir`
100+
local actual=$(helm template \
101+
--show-only templates/server-headless-service.yaml \
102+
--set 'server.service.headless.annotations=openBaoIsAwesome: true' \
103+
. | tee /dev/stderr |
104+
yq -r '.metadata.annotations["openBaoIsAwesome"]' | tee /dev/stderr)
105+
[ "${actual}" = "true" ]
106+
}
107+
108+
@test "server/headless-Service: with headless annotations yaml" {
109+
cd `chart_dir`
110+
local actual=$(helm template \
111+
--show-only templates/server-headless-service.yaml \
112+
--set 'server.service.headless.annotations.openBaoIsAwesome=true' \
113+
. | tee /dev/stderr |
114+
yq -r '.metadata.annotations["openBaoIsAwesome"]' | tee /dev/stderr)
115+
[ "${actual}" = "true" ]
116+
}
117+
@test "server/headless-Service: with both annotations set" {
118+
cd `chart_dir`
119+
local object=$(helm template \
120+
--show-only templates/server-headless-service.yaml \
121+
--set 'server.service.headless.annotations=openBaoIsAwesome: true' \
122+
--set 'server.service.annotations=openbaoIsNotAwesome: false' \
123+
. | tee /dev/stderr |
124+
yq -r '.metadata' | tee /dev/stderr)
125+
126+
local actual=$(echo "$object" | yq '.annotations["openBaoIsAwesome"]' | tee /dev/stderr)
127+
[ "${actual}" = "true" ]
128+
actual=$(echo "$object" | yq '.annotations["openbaoIsNotAwesome"]' | tee /dev/stderr)
129+
[ "${actual}" = "false" ]
130+
}

0 commit comments

Comments
 (0)