Skip to content

Commit

Permalink
Support UI service annotations (hashicorp#19)
Browse files Browse the repository at this point in the history
* support ui service annotations

* Update templates/ui-service.yaml

Co-Authored-By: Dat Truong <[email protected]>

* fix service annotation indent and write unit tests
  • Loading branch information
amoskyler authored and jasonodonnell committed Aug 16, 2019
1 parent a049b48 commit e312f00
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Set's the node selector for pod placement when running in standalone and HA mode
{{/*
Set's extra pod annotations
Sets extra pod annotations
*/}}
{{- define "vault.annotations" -}}
{{- if and (ne .mode "dev") .Values.server.annotations }}
Expand All @@ -249,6 +249,17 @@ Set's extra pod annotations
{{- end }}
{{- end -}}
{{/*
Sets extra ui service annotations
*/}}
{{- define "vault.ui.annotations" -}}
{{- if and (ne .mode "dev") .Values.ui.annotations }}
annotations:
{{- toYaml .Values.ui.annotations | nindent 4 }}
{{- end }}
{{- end -}}
{{/*
Set's the container resources if the user has set any.
*/}}
Expand Down
5 changes: 5 additions & 0 deletions templates/ui-service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{ template "vault.mode" . }}
{{- if and (ne .mode "") (eq (.Values.global.enabled | toString) "true") }}
# Headless service for Vault server DNS entries. This service should only
# point to Vault servers. For access to an agent, one should assume that
# the agent is installed locally on the node and the NODE_IP should be used.
Expand All @@ -14,6 +16,7 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
{{- template "vault.ui.annotations" . }}
spec:
selector:
app.kubernetes.io/name: {{ include "vault.name" . }}
Expand All @@ -25,3 +28,5 @@ spec:
targetPort: 8200
type: {{ .Values.ui.serviceType | default "ClusterIP" }}
{{- end -}}

{{ end }}
32 changes: 32 additions & 0 deletions test/unit/ui-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,35 @@ load _helpers
yq -r '.spec.type' | tee /dev/stderr)
[ "${actual}" = "LoadBalancer" ]
}

@test "ui/Service: specify annotations" {
cd `chart_dir`
local actual=$(helm template \
-x templates/ui-service.yaml \
--set 'server.dev.enabled=true' \
--set 'ui.serviceType=LoadBalancer' \
--set 'ui.enabled=true' \
--set 'ui.annotations.foo=bar' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["foo"]' | tee /dev/stderr)
[ "${actual}" = "null" ]

local actual=$(helm template \
-x templates/ui-service.yaml \
--set 'server.ha.enabled=true' \
--set 'ui.serviceType=LoadBalancer' \
--set 'ui.enabled=true' \
--set 'ui.annotations.foo=bar' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["foo"]' | tee /dev/stderr)
[ "${actual}" = "bar" ]

local actual=$(helm template \
-x templates/ui-service.yaml \
--set 'server.ha.enabled=true' \
--set 'ui.serviceType=LoadBalancer' \
--set 'ui.enabled=true' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["foo"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,8 @@ ui:
# balancer (for supported K8S installations) to access the UI.
enabled: false
serviceType: "ClusterIP"

# Extra annotations to attach to the ui service
# This should be a multi-line string mapping directly to the a map of
# the annotations to apply to the ui service
annotations: {}

0 comments on commit e312f00

Please sign in to comment.