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 support for setting VAULT_RAFT_NODE_ID environment variable #269

Merged
merged 3 commits into from
Apr 27, 2020
Merged
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
6 changes: 6 additions & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ spec:
fieldPath: metadata.name
- name: VAULT_CLUSTER_ADDR
value: "https://$(HOSTNAME).{{ template "vault.fullname" . }}-internal:8201"
{{- if and (eq (.Values.server.ha.raft.enabled | toString) "true") (eq (.Values.server.ha.raft.setNodeId | toString) "true") }}
- name: VAULT_RAFT_NODE_ID
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- end }}
{{ template "vault.envs" . }}
{{- include "vault.extraEnvironmentVars" .Values.server | nindent 12 }}
{{- include "vault.extraSecretEnvironmentVars" .Values.server | nindent 12 }}
Expand Down
25 changes: 23 additions & 2 deletions test/unit/server-ha-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ load _helpers
[ "${actual}" = "secret_key_1" ]
}


#--------------------------------------------------------------------
# VAULT_CLUSTER_ADDR renders

Expand All @@ -415,7 +414,7 @@ load _helpers
--set 'server.ha.raft.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.[9].name' | tee /dev/stderr)
[ "${actual}" = "VAULT_CLUSTER_ADDR" ]
Expand All @@ -425,6 +424,28 @@ load _helpers
[ "${actual}" = 'https://$(HOSTNAME).RELEASE-NAME-vault-internal:8201' ]
}

#--------------------------------------------------------------------
# VAULT_RAFT_NODE_ID renders

@test "server/ha-StatefulSet: raft node ID renders" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/server-statefulset.yaml \
--set 'server.ha.enabled=true' \
--set 'server.ha.raft.enabled=true' \
--set 'server.ha.raft.setNodeId=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.[10].name' | tee /dev/stderr)
[ "${actual}" = "VAULT_RAFT_NODE_ID" ]

local actual=$(echo $object |
yq -r '.[10].valueFrom.fieldRef.fieldPath' | tee /dev/stderr)
[ "${actual}" = 'metadata.name' ]
}

#--------------------------------------------------------------------
# storage class

Expand Down
12 changes: 7 additions & 5 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ injector:

# Configures the log format of the injector. Supported log formats: "standard", "json".
logFormat: "standard"

# Configures all Vault Agent sidecars to revoke their token when shutting down
revokeOnShutdown: false

Expand Down Expand Up @@ -338,15 +338,17 @@ server:
ha:
enabled: false
replicas: 3
# Enables Vault's integrated Raft storage. Unlike the typical HA modes where
# Vault's persistence is external (such as Consul), enabling Raft mode will create

# Enables Vault's integrated Raft storage. Unlike the typical HA modes where
# Vault's persistence is external (such as Consul), enabling Raft mode will create
# persistent volumes for Vault to store data according to the configuration under server.dataStorage.
# The Vault cluster will coordinate leader elections and failovers internally.
raft:

# Enables Raft integrated storage
enabled: false
# Set the Node Raft ID to the name of the pod
setNodeId: false
config: |
ui = true

Expand Down