2018-08-18 05:08:03 +00:00
|
|
|
{{/*
|
|
|
|
Create a default fully qualified app name.
|
|
|
|
We truncate at 63 chars because some Kubernetes name fields are limited to
|
|
|
|
this (by the DNS naming spec). If release name contains chart name it will
|
|
|
|
be used as a full name.
|
|
|
|
*/}}
|
2018-09-28 20:56:48 +00:00
|
|
|
{{- define "vault.fullname" -}}
|
2018-08-18 21:38:33 +00:00
|
|
|
{{- if .Values.fullnameOverride -}}
|
|
|
|
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
|
|
|
|
{{- else -}}
|
2018-08-18 05:08:03 +00:00
|
|
|
{{- $name := default .Chart.Name .Values.nameOverride -}}
|
|
|
|
{{- if contains $name .Release.Name -}}
|
|
|
|
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
2018-08-18 21:38:33 +00:00
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
Create chart name and version as used by the chart label.
|
|
|
|
*/}}
|
2018-09-28 20:56:48 +00:00
|
|
|
{{- define "vault.chart" -}}
|
2018-08-18 21:38:33 +00:00
|
|
|
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
Expand the name of the chart.
|
|
|
|
*/}}
|
2018-09-28 20:56:48 +00:00
|
|
|
{{- define "vault.name" -}}
|
2018-08-18 21:38:33 +00:00
|
|
|
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
|
|
|
|
{{- end -}}
|
2018-08-18 05:08:03 +00:00
|
|
|
|
|
|
|
{{/*
|
|
|
|
Compute the maximum number of unavailable replicas for the PodDisruptionBudget.
|
|
|
|
This defaults to (n/2)-1 where n is the number of members of the server cluster.
|
2018-12-03 17:30:50 +00:00
|
|
|
Add a special case for replicas=1, where it should default to 0 as well.
|
2018-08-18 05:08:03 +00:00
|
|
|
*/}}
|
2018-09-28 20:56:48 +00:00
|
|
|
{{- define "vault.pdb.maxUnavailable" -}}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- if eq (int .Values.server.ha.replicas) 1 -}}
|
2018-12-03 17:30:50 +00:00
|
|
|
{{ 0 }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- else if .Values.server.ha.disruptionBudget.maxUnavailable -}}
|
|
|
|
{{ .Values.server.ha.disruptionBudget.maxUnavailable -}}
|
2018-08-18 05:08:03 +00:00
|
|
|
{{- else -}}
|
2019-10-21 13:51:02 +00:00
|
|
|
{{- div (sub (div (mul (int .Values.server.ha.replicas) 10) 2) 1) 10 -}}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set the variable 'mode' to the server mode requested by the user to simplify
|
2019-07-31 18:26:12 +00:00
|
|
|
template logic.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.mode" -}}
|
2020-02-21 16:16:33 +00:00
|
|
|
{{- if .Values.injector.externalVaultAddr -}}
|
|
|
|
{{- $_ := set . "mode" "external" -}}
|
|
|
|
{{- else if eq (.Values.server.dev.enabled | toString) "true" -}}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- $_ := set . "mode" "dev" -}}
|
|
|
|
{{- else if eq (.Values.server.ha.enabled | toString) "true" -}}
|
|
|
|
{{- $_ := set . "mode" "ha" -}}
|
|
|
|
{{- else if or (eq (.Values.server.standalone.enabled | toString) "true") (eq (.Values.server.standalone.enabled | toString) "-") -}}
|
|
|
|
{{- $_ := set . "mode" "standalone" -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $_ := set . "mode" "" -}}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
Set's the replica count based on the different modes configured by user
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.replicas" -}}
|
|
|
|
{{ if eq .mode "standalone" }}
|
|
|
|
{{- default 1 -}}
|
|
|
|
{{ else if eq .mode "ha" }}
|
|
|
|
{{- .Values.server.ha.replicas | default 3 -}}
|
|
|
|
{{ else }}
|
|
|
|
{{- default 1 -}}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set's up configmap mounts if this isn't a dev deployment and the user
|
|
|
|
defined a custom configuration. Additionally iterates over any
|
2019-07-31 18:26:12 +00:00
|
|
|
extra volumes the user may have specified (such as a secret with TLS).
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.volumes" -}}
|
|
|
|
{{- if and (ne .mode "dev") (or (ne .Values.server.standalone.config "") (ne .Values.server.ha.config "")) }}
|
2019-08-21 15:15:47 +00:00
|
|
|
- name: config
|
|
|
|
configMap:
|
|
|
|
name: {{ template "vault.fullname" . }}-config
|
2019-07-31 18:26:12 +00:00
|
|
|
{{ end }}
|
|
|
|
{{- range .Values.server.extraVolumes }}
|
2019-08-21 15:15:47 +00:00
|
|
|
- name: userconfig-{{ .name }}
|
|
|
|
{{ .type }}:
|
|
|
|
{{- if (eq .type "configMap") }}
|
|
|
|
name: {{ .name }}
|
|
|
|
{{- else if (eq .type "secret") }}
|
|
|
|
secretName: {{ .name }}
|
|
|
|
{{- end }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set's a command to override the entrypoint defined in the image
|
|
|
|
so we can make the user experience nicer. This works in with
|
2019-07-31 18:26:12 +00:00
|
|
|
"vault.args" to specify what commands /bin/sh should run.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.command" -}}
|
|
|
|
{{ if or (eq .mode "standalone") (eq .mode "ha") }}
|
|
|
|
- "/bin/sh"
|
|
|
|
- "-ec"
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set's the args for custom command to render the Vault configuration
|
|
|
|
file with IP addresses to make the out of box experience easier
|
2019-07-31 18:26:12 +00:00
|
|
|
for users looking to use this chart with Consul Helm.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.args" -}}
|
|
|
|
{{ if or (eq .mode "standalone") (eq .mode "ha") }}
|
|
|
|
- |
|
2019-08-22 15:05:31 +00:00
|
|
|
sed -E "s/HOST_IP/${HOST_IP?}/g" /vault/config/extraconfig-from-values.hcl > /tmp/storageconfig.hcl;
|
2019-07-31 18:26:12 +00:00
|
|
|
sed -Ei "s/POD_IP/${POD_IP?}/g" /tmp/storageconfig.hcl;
|
2020-01-14 15:09:20 +00:00
|
|
|
/usr/local/bin/docker-entrypoint.sh vault server -config=/tmp/storageconfig.hcl {{ .Values.server.extraArgs }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
Set's additional environment variables based on the mode.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.envs" -}}
|
|
|
|
{{ if eq .mode "dev" }}
|
|
|
|
- name: VAULT_DEV_ROOT_TOKEN_ID
|
|
|
|
value: "root"
|
|
|
|
{{ end }}
|
2020-03-18 19:49:14 +00:00
|
|
|
{{ if and (eq .mode "ha") (eq (.Values.server.ha.raft.enabled | toString) "true") }}
|
|
|
|
- name: VAULT_CLUSTER_ADDR
|
|
|
|
value: "https://$(HOSTNAME).vault-internal:8201"
|
|
|
|
{{ end }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set's which additional volumes should be mounted to the container
|
2019-07-31 18:26:12 +00:00
|
|
|
based on the mode configured.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.mounts" -}}
|
2019-10-10 14:03:44 +00:00
|
|
|
{{ if eq (.Values.server.auditStorage.enabled | toString) "true" }}
|
2019-07-31 18:26:12 +00:00
|
|
|
- name: audit
|
|
|
|
mountPath: /vault/audit
|
2019-10-10 14:03:44 +00:00
|
|
|
{{ end }}
|
2020-03-18 19:49:14 +00:00
|
|
|
{{ if or (eq .mode "standalone") (and (eq .mode "ha") (eq (.Values.server.ha.raft.enabled | toString) "true")) }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{ if eq (.Values.server.dataStorage.enabled | toString) "true" }}
|
|
|
|
- name: data
|
|
|
|
mountPath: /vault/data
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
{{ if and (ne .mode "dev") (or (ne .Values.server.standalone.config "") (ne .Values.server.ha.config "")) }}
|
|
|
|
- name: config
|
|
|
|
mountPath: /vault/config
|
|
|
|
{{ end }}
|
|
|
|
{{- range .Values.server.extraVolumes }}
|
|
|
|
- name: userconfig-{{ .name }}
|
|
|
|
readOnly: true
|
2019-08-14 20:29:07 +00:00
|
|
|
mountPath: {{ .path | default "/vault/userconfig" }}/{{ .name }}
|
2019-07-31 18:26:12 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
2019-08-22 15:05:31 +00:00
|
|
|
Set's up the volumeClaimTemplates when data or audit storage is required. HA
|
|
|
|
might not use data storage since Consul is likely it's backend, however, audit
|
2019-07-31 18:26:12 +00:00
|
|
|
storage might be desired by the user.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.volumeclaims" -}}
|
|
|
|
{{- if and (ne .mode "dev") (or .Values.server.dataStorage.enabled .Values.server.auditStorage.enabled) }}
|
|
|
|
volumeClaimTemplates:
|
2020-03-18 19:49:14 +00:00
|
|
|
{{- if and (eq (.Values.server.dataStorage.enabled | toString) "true") (or (eq .mode "standalone") (eq (.Values.server.ha.raft.enabled | toString ) "true" )) }}
|
2019-07-31 18:26:12 +00:00
|
|
|
- metadata:
|
|
|
|
name: data
|
|
|
|
spec:
|
|
|
|
accessModes:
|
|
|
|
- {{ .Values.server.dataStorage.accessMode | default "ReadWriteOnce" }}
|
|
|
|
resources:
|
|
|
|
requests:
|
|
|
|
storage: {{ .Values.server.dataStorage.size }}
|
|
|
|
{{- if .Values.server.dataStorage.storageClass }}
|
|
|
|
storageClassName: {{ .Values.server.dataStorage.storageClass }}
|
|
|
|
{{- end }}
|
|
|
|
{{ end }}
|
|
|
|
{{- if eq (.Values.server.auditStorage.enabled | toString) "true" }}
|
|
|
|
- metadata:
|
|
|
|
name: audit
|
|
|
|
spec:
|
|
|
|
accessModes:
|
|
|
|
- {{ .Values.server.auditStorage.accessMode | default "ReadWriteOnce" }}
|
|
|
|
resources:
|
|
|
|
requests:
|
|
|
|
storage: {{ .Values.server.auditStorage.size }}
|
|
|
|
{{- if .Values.server.auditStorage.storageClass }}
|
|
|
|
storageClassName: {{ .Values.server.auditStorage.storageClass }}
|
|
|
|
{{- end }}
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{/*
|
|
|
|
Set's the affinity for pod placement when running in standalone and HA modes.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.affinity" -}}
|
2019-08-05 16:31:06 +00:00
|
|
|
{{- if and (ne .mode "dev") .Values.server.affinity }}
|
2019-07-31 18:26:12 +00:00
|
|
|
affinity:
|
|
|
|
{{ tpl .Values.server.affinity . | nindent 8 | trim }}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2020-03-20 05:43:52 +00:00
|
|
|
{{/*
|
|
|
|
Sets the injector affinity for pod placement
|
|
|
|
*/}}
|
|
|
|
{{- define "injector.affinity" -}}
|
|
|
|
{{- if .Values.injector.affinity }}
|
|
|
|
affinity:
|
|
|
|
{{ tpl .Values.injector.affinity . | nindent 8 | trim }}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-08-05 16:31:06 +00:00
|
|
|
{{/*
|
|
|
|
Set's the toleration for pod placement when running in standalone and HA modes.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.tolerations" -}}
|
|
|
|
{{- if and (ne .mode "dev") .Values.server.tolerations }}
|
|
|
|
tolerations:
|
|
|
|
{{ tpl .Values.server.tolerations . | nindent 8 | trim }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2020-03-20 05:43:52 +00:00
|
|
|
{{/*
|
|
|
|
Sets the injector toleration for pod placement
|
|
|
|
*/}}
|
|
|
|
{{- define "injector.tolerations" -}}
|
|
|
|
{{- if .Values.injector.tolerations }}
|
|
|
|
tolerations:
|
|
|
|
{{ tpl .Values.injector.tolerations . | nindent 8 | trim }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-08-05 16:31:06 +00:00
|
|
|
{{/*
|
|
|
|
Set's the node selector for pod placement when running in standalone and HA modes.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.nodeselector" -}}
|
|
|
|
{{- if and (ne .mode "dev") .Values.server.nodeSelector }}
|
|
|
|
nodeSelector:
|
|
|
|
{{ tpl .Values.server.nodeSelector . | indent 8 | trim }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2020-03-20 05:43:52 +00:00
|
|
|
{{/*
|
|
|
|
Sets the injector node selector for pod placement
|
|
|
|
*/}}
|
|
|
|
{{- define "injector.nodeselector" -}}
|
|
|
|
{{- if .Values.injector.nodeSelector }}
|
|
|
|
nodeSelector:
|
|
|
|
{{ tpl .Values.injector.nodeSelector . | indent 8 | trim }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-08-05 16:31:06 +00:00
|
|
|
{{/*
|
2019-08-16 15:59:51 +00:00
|
|
|
Sets extra pod annotations
|
2019-08-05 16:31:06 +00:00
|
|
|
*/}}
|
|
|
|
{{- define "vault.annotations" -}}
|
|
|
|
{{- if and (ne .mode "dev") .Values.server.annotations }}
|
|
|
|
annotations:
|
|
|
|
{{- tpl .Values.server.annotations . | nindent 8 }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-08-16 15:59:51 +00:00
|
|
|
{{/*
|
|
|
|
Sets extra ui service annotations
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.ui.annotations" -}}
|
2019-09-27 16:16:35 +00:00
|
|
|
{{- if .Values.ui.annotations }}
|
2019-08-16 15:59:51 +00:00
|
|
|
annotations:
|
|
|
|
{{- toYaml .Values.ui.annotations | nindent 4 }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-09-06 14:48:12 +00:00
|
|
|
{{/*
|
|
|
|
Sets extra service account annotations
|
|
|
|
*/}}
|
2019-12-11 21:04:57 +00:00
|
|
|
{{- define "vault.serviceAccount.annotations" -}}
|
|
|
|
{{- if and (ne .mode "dev") .Values.server.serviceAccount.annotations }}
|
2019-09-06 14:48:12 +00:00
|
|
|
annotations:
|
2019-12-11 21:04:57 +00:00
|
|
|
{{- toYaml .Values.server.serviceAccount.annotations | nindent 4 }}
|
2019-09-06 14:48:12 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end -}}
|
2019-08-16 15:59:51 +00:00
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
{{/*
|
|
|
|
Set's the container resources if the user has set any.
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.resources" -}}
|
|
|
|
{{- if .Values.server.resources -}}
|
|
|
|
resources:
|
|
|
|
{{ toYaml .Values.server.resources | indent 12}}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-12-19 15:57:51 +00:00
|
|
|
{{/*
|
|
|
|
Sets the container resources if the user has set any.
|
|
|
|
*/}}
|
|
|
|
{{- define "injector.resources" -}}
|
|
|
|
{{- if .Values.injector.resources -}}
|
|
|
|
resources:
|
|
|
|
{{ toYaml .Values.injector.resources | indent 12}}
|
|
|
|
{{ end }}
|
|
|
|
{{- end -}}
|
|
|
|
|
2019-07-31 18:26:12 +00:00
|
|
|
{{/*
|
|
|
|
Inject extra environment vars in the format key:value, if populated
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.extraEnvironmentVars" -}}
|
|
|
|
{{- if .extraEnvironmentVars -}}
|
|
|
|
{{- range $key, $value := .extraEnvironmentVars }}
|
2020-03-19 04:30:22 +00:00
|
|
|
- name: {{ printf "%s" $key | replace "." "_" | upper | quote }}
|
2019-07-31 18:26:12 +00:00
|
|
|
value: {{ $value | quote }}
|
2020-03-19 04:30:22 +00:00
|
|
|
{{- end }}
|
2018-08-18 05:08:03 +00:00
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
2019-08-14 20:29:07 +00:00
|
|
|
|
|
|
|
{{/*
|
|
|
|
Inject extra environment populated by secrets, if populated
|
|
|
|
*/}}
|
|
|
|
{{- define "vault.extraSecretEnvironmentVars" -}}
|
|
|
|
{{- if .extraSecretEnvironmentVars -}}
|
|
|
|
{{- range .extraSecretEnvironmentVars }}
|
|
|
|
- name: {{ .envName }}
|
|
|
|
valueFrom:
|
|
|
|
secretKeyRef:
|
|
|
|
name: {{ .secretName }}
|
|
|
|
key: {{ .secretKey }}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
2019-08-20 15:40:47 +00:00
|
|
|
|
|
|
|
{{/* Scheme for health check and local endpoint */}}
|
|
|
|
{{- define "vault.scheme" -}}
|
|
|
|
{{- if .Values.global.tlsDisable -}}
|
|
|
|
{{ "http" }}
|
|
|
|
{{- else -}}
|
|
|
|
{{ "https" }}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|