Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support selectively disabling active/standby services #811

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Unreleased

Features:
Changes:
* server: No longer apply Vault service discovery role and role binding when `server.serviceAccount.create` is set to false [GH-811](https://github.com/hashicorp/vault-helm/pull/811)

Improvements:
tomhjp marked this conversation as resolved.
Show resolved Hide resolved
* server: Add `extraLabels` for Vault server serviceAccount [GH-806](https://github.com/hashicorp/vault-helm/pull/806)
* server: Add `server.service.active.enabled` and `server.service.standby.enabled` options to selectively disable additional services [GH-811](https://github.com/hashicorp/vault-helm/pull/811)

## 0.22.1 (October 26th, 2022)

Expand Down
5 changes: 3 additions & 2 deletions templates/server-discovery-role.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ template "vault.mode" . }}
{{- if ne .mode "external" }}
tvoran marked this conversation as resolved.
Show resolved Hide resolved
{{- if .serverEnabled -}}
{{ template "vault.serverServiceAccountEnabled" . }}
{{- if eq .mode "ha" }}
{{- if .serverEnabled -}}
{{- if .serverServiceAccountEnabled -}}
tomhjp marked this conversation as resolved.
Show resolved Hide resolved
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down
5 changes: 3 additions & 2 deletions templates/server-discovery-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ template "vault.mode" . }}
{{- if ne .mode "external" }}
{{- if .serverEnabled -}}
{{ template "vault.serverServiceAccountEnabled" . }}
{{- if eq .mode "ha" }}
{{- if .serverEnabled -}}
{{- if .serverServiceAccountEnabled -}}
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1" -}}
apiVersion: rbac.authorization.k8s.io/v1
{{- else }}
Expand Down
2 changes: 2 additions & 0 deletions templates/server-ha-active-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{- template "vault.serverServiceEnabled" . -}}
{{- if .serverServiceEnabled -}}
{{- if eq .mode "ha" }}
{{- if eq (.Values.server.service.active.enabled | toString) "true" }}
# Service for active Vault pod
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -44,3 +45,4 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/server-ha-standby-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{- template "vault.serverServiceEnabled" . -}}
{{- if .serverServiceEnabled -}}
{{- if eq .mode "ha" }}
{{- if eq (.Values.server.service.standby.enabled | toString) "true" }}
# Service for standby Vault pod
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -42,4 +43,5 @@ spec:
vault-active: "false"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
1 change: 0 additions & 1 deletion templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ spec:
{{- if not .Values.global.openshift }}
hostNetwork: {{ .Values.server.hostNetwork }}
{{- end }}

volumes:
{{ template "vault.volumes" . }}
- name: home
Expand Down
41 changes: 41 additions & 0 deletions test/unit/server-discovery-rolebinding.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bats

load _helpers

@test "server/DiscoveryRoleBinding: enabled by default with ha" {
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/server-discovery-rolebinding.yaml \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]

local actual=$( (helm template \
--show-only templates/server-discovery-rolebinding.yaml \
--set 'server.ha.enabled=true' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/DiscoveryRoleBinding: can disable with server.enabled false" {
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/server-discovery-rolebinding.yaml \
--set 'server.enabled=false' \
--set 'server.ha.enabled=true' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/DiscoveryRoleBinding: can disable with server.serviceAccount.create false" {
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/server-discovery-rolebinding.yaml \
--set 'server.ha.enabled=true' \
--set 'server.serviceAccount.create=false' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
}
12 changes: 12 additions & 0 deletions test/unit/server-ha-active-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ load _helpers
[ "${actual}" = "false" ]
}

@test "server/ha-active-Service: disable with server.service.active.enabled false" {
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/server-ha-active-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.enabled=true' \
--set 'server.service.active.enabled=false' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/ha-active-Service: type empty by default" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
12 changes: 12 additions & 0 deletions test/unit/server-ha-standby-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ load _helpers
[ "${actual}" = "false" ]
}

@test "server/ha-standby-Service: disable with server.service.standby.enabled false" {
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/server-ha-standby-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.enabled=true' \
--set 'server.service.standby.enabled=false' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/ha-standby-Service: type empty by default" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
16 changes: 16 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,14 @@
"service": {
"type": "object",
"properties": {
"active": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"annotations": {
"type": [
"object",
Expand All @@ -869,6 +877,14 @@
"publishNotReadyAddresses": {
"type": "boolean"
},
"standby": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"targetPort": {
"type": "integer"
},
Expand Down
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ server:
# Enables a headless service to be used by the Vault Statefulset
service:
enabled: true
active:
enabled: true
standby:
enabled: true
tvoran marked this conversation as resolved.
Show resolved Hide resolved
# clusterIP controls whether a Cluster IP address is attached to the
# Vault service within Kubernetes. By default, the Vault service will
# be given a Cluster IP address, set to None to disable. When disabled
Expand Down