Skip to content

Commit

Permalink
Add configuration options for Vault UI service (hashicorp#285)
Browse files Browse the repository at this point in the history
* Add configuration options for Vault UI service

- Configure to select active Vault pod only
- Configure to not publish unready address

* Create active label only on HA
  • Loading branch information
lawliet89 authored Aug 20, 2020
1 parent f0c073e commit 5dc29f6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
14 changes: 6 additions & 8 deletions templates/ui-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
{{- if ne .mode "external" }}
{{- if and (ne .mode "") (eq (.Values.global.enabled | toString) "true") }}
{{- if eq (.Values.ui.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.
# If the node can't run a Vault agent, then this service can be used to
# communicate directly to a server agent.
apiVersion: v1
kind: Service
metadata:
Expand All @@ -23,7 +18,10 @@ spec:
app.kubernetes.io/name: {{ include "vault.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
component: server
publishNotReadyAddresses: true
{{- if and (.Values.ui.activeVaultPodOnly) (eq .mode "ha") }}
vault-active: "true"
{{- end }}
publishNotReadyAddresses: {{ .Values.ui.publishNotReadyAddresses }}
ports:
- name: {{ include "vault.scheme" . }}
port: {{ .Values.ui.externalPort }}
Expand All @@ -43,5 +41,5 @@ spec:
{{- end }}
{{- end -}}

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

@test "ui/Service: publishNotReadyAddresses set true by default" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "ui/Service: publishNotReadyAddresses can be set to false" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
--set 'ui.publishNotReadyAddresses=false' \
. | tee /dev/stderr |
yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr)
[ "${actual}" = 'false' ]
}

@test "ui/Service: active pod only selector not set by default" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["vault-active"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "ui/Service: active pod only selector can be set on HA" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
--set 'ui.activeVaultPodOnly=true' \
--set 'server.dev.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["vault-active"]' | tee /dev/stderr)
[ "${actual}" = 'null' ]

local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
--set 'ui.activeVaultPodOnly=true' \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["vault-active"]' | tee /dev/stderr)
[ "${actual}" = 'true' ]
}
3 changes: 3 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ ui:
# example, setting this to "LoadBalancer" will create an external load
# balancer (for supported K8S installations) to access the UI.
enabled: false
publishNotReadyAddresses: true
# The service should only contain selectors for active Vault pod
activeVaultPodOnly: false
serviceType: "ClusterIP"
serviceNodePort: null
externalPort: 8200
Expand Down

0 comments on commit 5dc29f6

Please sign in to comment.