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

add configuration for active/standy services for server #546

Closed
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,34 @@ Sets extra vault server Service annotations
{{- end }}
{{- end -}}

{{/*
Sets extra vault server Service (active) annotations
*/}}
{{- define "vault.service.active.annotations" -}}
{{- if .Values.server.service.active.annotations }}
{{- $tp := typeOf .Values.server.service.active.annotations }}
{{- if eq $tp "string" }}
{{- tpl .Values.server.service.active.annotations . | nindent 4 }}
{{- else }}
{{- toYaml .Values.server.service.active.annotations | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
Sets extra vault server Service annotations
*/}}
{{- define "vault.service.standby.annotations" -}}
{{- if .Values.server.service.standby.annotations }}
{{- $tp := typeOf .Values.server.service.standby.annotations }}
{{- if eq $tp "string" }}
{{- tpl .Values.server.service.standby.annotations . | nindent 4 }}
{{- else }}
{{- toYaml .Values.server.service.standby.annotations | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
Sets PodSecurityPolicy annotations
*/}}
Expand Down
14 changes: 10 additions & 4 deletions templates/server-ha-active-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
{{ template "vault.service.annotations" .}}
{{ template "vault.service.active.annotations" .}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to include the previous annotations as well in both the active and standby. (Both because of backwards compatibility and because we might want to have common annotations in the vault.service.annotations template.)

spec:
{{- if .Values.server.service.type}}
{{- if .Values.server.service.active.type}}
type: {{ .Values.server.service.active.type }}
{{- else if .Values.server.service.type }}
type: {{ .Values.server.service.type }}
{{- end}}
{{- if .Values.server.service.clusterIP }}
{{- if .Values.server.service.active.clusterIP }}
clusterIP: {{ .Values.server.service.active.clusterIP }}
{{- else if .Values.server.service.clusterIP }}
clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
publishNotReadyAddresses: true
ports:
- name: {{ include "vault.scheme" . }}
port: {{ .Values.server.service.port }}
targetPort: {{ .Values.server.service.targetPort }}
{{- if and (.Values.server.service.nodePort) (eq (.Values.server.service.type | toString) "NodePort") }}
{{- if and (.Values.server.service.active.nodePort) (eq (.Values.server.service.active.type | toString) "NodePort") }}
nodePort: {{ .Values.server.service.active.nodePort }}
{{- else if and (.Values.server.service.nodePort) (eq (.Values.server.service.type | toString) "NodePort") }}
nodePort: {{ .Values.server.service.nodePort }}
{{- end }}
- name: https-internal
Expand Down
16 changes: 11 additions & 5 deletions templates/server-ha-standby-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
{{ template "vault.service.annotations" .}}
{{ template "vault.service.standby.annotations" .}}
spec:
{{- if .Values.server.service.type}}
{{- if .Values.server.service.standby.type}}
type: {{ .Values.server.service.standby.type }}
{{- else if .Values.server.service.type }}
type: {{ .Values.server.service.type }}
{{- end}}
{{- if .Values.server.service.clusterIP }}
{{- if .Values.server.service.standby.clusterIP }}
clusterIP: {{ .Values.server.service.standby.clusterIP }}
{{- else if .Values.server.service.clusterIP }}
clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
publishNotReadyAddresses: true
ports:
- name: {{ include "vault.scheme" . }}
port: {{ .Values.server.service.port }}
targetPort: {{ .Values.server.service.targetPort }}
{{- if and (.Values.server.service.nodePort) (eq (.Values.server.service.type | toString) "NodePort") }}
{{- if and (.Values.server.service.standby.nodePort) (eq (.Values.server.service.standby.type | toString) "NodePort") }}
nodePort: {{ .Values.server.service.standby.nodePort }}
{{- else if and (.Values.server.service.nodePort) (eq (.Values.server.service.type | toString) "NodePort") }}
nodePort: {{ .Values.server.service.nodePort }}
{{- end }}
- name: https-internal
Expand All @@ -38,4 +44,4 @@ spec:
component: server
vault-active: "false"
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion test/unit/server-ha-active-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load _helpers
local actual=$(helm template \
--show-only templates/server-ha-active-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.annotations=vaultIsAwesome: true' \
--set 'server.service.active.annotations=vaultIsAwesome: true' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server-ha-standby-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load _helpers
local actual=$(helm template \
--show-only templates/server-ha-standby-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.annotations=vaultIsAwesome: true' \
--set 'server.service.standby.annotations=vaultIsAwesome: true' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
Expand All @@ -18,7 +18,7 @@ load _helpers
local actual=$(helm template \
--show-only templates/server-ha-standby-service.yaml \
--set 'server.ha.enabled=true' \
--set 'server.service.annotations.vaultIsAwesome=true' \
--set 'server.service.standby.annotations.vaultIsAwesome=true' \
. | tee /dev/stderr |
yq -r '.metadata.annotations["vaultIsAwesome"]' | tee /dev/stderr)
[ "${actual}" = "true" ]
Expand Down
22 changes: 22 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,28 @@
},
"targetPort": {
"type": "integer"
},
"active": {
"type": "object",
"properties": {
"annotations": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These appear to be missing entries for type, nodePort, clusterIP`.

"type": [
"object",
"string"
]
}
}
},
"standby": {
"type": "object",
"properties": {
"annotations": {
"type": [
"object",
"string"
]
}
}
}
}
},
Expand Down
46 changes: 46 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,52 @@ server:
# to the service.
annotations: {}

# Enables a headless service that contains the active pod only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sections don't enable this behavior, so I would remove this comment.

active:
# clusterIP controls whether a Cluster IP address is attached to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment about these values defaulting to the values.server.service values if missing, except annotations (which will be appended)?

# Vault service within Kubernetes. By default the Vault service will
# be given a Cluster IP address, set to None to disable. When disabled
# Kubernetes will create a "headless" service. Headless services can be
# used to communicate with pods directly through DNS instead of a round robin
# load balancer.
# clusterIP: None

# Configures the service type for the active Vault service. Can be ClusterIP
# or NodePort.
#type: ClusterIP

# If type is set to "NodePort", a specific nodePort value can be configured,
# will be random if left blank.
#nodePort: 30000

# Extra annotations for the service definition. This can either be YAML or a
# YAML-formatted multi-line templated string map of the annotations to apply
# to the service.
annotations: {}

# Enables a headless service that contains standby pods only
standby:
# 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
# Kubernetes will create a "headless" service. Headless services can be
# used to communicate with pods directly through DNS instead of a round robin
# load balancer.
# clusterIP: None

# Configures the service type for the standby Vault service. Can be ClusterIP
# or NodePort.
#type: ClusterIP

# If type is set to "NodePort", a specific nodePort value can be configured,
# will be random if left blank.
#nodePort: 30000

# Extra annotations for the service definition. This can either be YAML or a
# YAML-formatted multi-line templated string map of the annotations to apply
# to the service.
annotations: {}

# This configures the Vault Statefulset to create a PVC for data
# storage when using the file or raft backend storage engines.
# See https://www.vaultproject.io/docs/configuration/storage/index.html to know more
Expand Down