Skip to content

Commit

Permalink
server: Allow disabling the instance selector for services (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhjp authored Nov 17, 2022
1 parent 21ce524 commit c13151a
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Features:
* 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)
* server: Add `server.serviceAccount.serviceDiscovery.enabled` option to selectively disable a Vault service discovery role and role binding [GH-811](https://github.com/hashicorp/vault-helm/pull/811)
* server: Add `server.service.instanceSelector.enabled` option to allow selecting pods outside the helm chart deployment [GH-813](https://github.com/hashicorp/vault-helm/pull/813)

Bugs:
* server: Quote `.server.ha.clusterAddr` value [GH-810](https://github.com/hashicorp/vault-helm/pull/810)
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 @@ -39,7 +39,9 @@ spec:
targetPort: 8201
selector:
app.kubernetes.io/name: {{ include "vault.name" . }}
{{- if eq (.Values.server.service.instanceSelector.enabled | toString) "true" }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
component: server
vault-active: "true"
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions templates/server-ha-standby-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ spec:
targetPort: 8201
selector:
app.kubernetes.io/name: {{ include "vault.name" . }}
{{- if eq (.Values.server.service.instanceSelector.enabled | toString) "true" }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
component: server
vault-active: "false"
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions templates/server-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ spec:
targetPort: 8201
selector:
app.kubernetes.io/name: {{ include "vault.name" . }}
{{- if eq (.Values.server.service.instanceSelector.enabled | toString) "true" }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
component: server
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions test/unit/server-ha-active-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,21 @@ load _helpers
yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/ha-active-Service: instance selector can be disabled" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-ha-active-service.yaml \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "release-name" ]

local actual=$(helm template \
--show-only templates/server-ha-active-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.instanceSelector.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
18 changes: 18 additions & 0 deletions test/unit/server-ha-standby-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,21 @@ load _helpers
yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/ha-standby-Service: instance selector can be disabled" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-ha-standby-service.yaml \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "release-name" ]

local actual=$(helm template \
--show-only templates/server-ha-standby-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.instanceSelector.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
18 changes: 18 additions & 0 deletions test/unit/server-headless-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ load _helpers
yq -r '.spec.publishNotReadyAddresses' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "server/headless-Service: instance selector cannot be disabled" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "release-name" ]

local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.instanceSelector.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "release-name" ]
}
17 changes: 17 additions & 0 deletions test/unit/server-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,20 @@ load _helpers
[ "${actual}" = "null" ]
}

@test "server/Service: instance selector can be disabled" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "release-name" ]

local actual=$(helm template \
--show-only templates/server-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.instanceSelector.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
8 changes: 8 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,14 @@
"externalTrafficPolicy": {
"type": "string"
},
"instanceSelector": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"port": {
"type": "integer"
},
Expand Down
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ server:
# have labelled themselves as a cluster follower with `vault-active: "false"`
standby:
enabled: true
# If enabled, the service selectors will include `app.kubernetes.io/instance: {{ .Release.Name }}`
# When disabled, services may select Vault pods not deployed from the chart.
# Does not affect the headless vault-internal service with `ClusterIP: None`
instanceSelector:
enabled: true
# 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

0 comments on commit c13151a

Please sign in to comment.