Skip to content

Commit

Permalink
Fail helm upgrades if partition name is updated.
Browse files Browse the repository at this point in the history
- This does not cause the parition-init job from running or the agents
  from attempting to join the new partition, but the helm upgrade stays
in a failed state until an upgrade is run with the partition name
reverted.
  • Loading branch information
Ashwin Venkatesh committed Sep 14, 2021
1 parent 8910fd3 commit 7bb77a2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/consul/templates/partition-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "2"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
spec:
Expand Down
18 changes: 18 additions & 0 deletions charts/consul/templates/partition-name-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- $serverEnabled := (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) -}}
{{- if (and .Values.global.adminPartitions.enabled (not $serverEnabled)) }}
# Immutable ConfigMap which saves the partition name. Attempting to update this configmap
# with a new Admin Partition name will cause the helm upgrade to fail
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "consul.fullname" . }}-partition-configmap
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "consul.name" . }}
chart: {{ template "consul.chart" . }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
immutable: true
data:
partitionName: {{ .Values.global.adminPartitions.name }}
{{- end }}
47 changes: 47 additions & 0 deletions charts/consul/test/unit/partition-name-configmap.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

load _helpers

@test "partitionName/ConfigMap: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-role.yaml \
.
}

@test "partitionName/ConfigMap: enabled with global.adminPartitions.enabled=true and servers = false" {
cd `chart_dir`
local actual=$(helm template \
-s templates/partition-init-role.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'server.enabled=false' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "partitionName/ConfigMap: disabled with global.adminPartitions.enabled=true and servers = true" {
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-role.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'server.enabled=true' \
.
}

@test "partitionName/ConfigMap: disabled with global.adminPartitions.enabled=true and global.enabled = true" {
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-role.yaml \
--set 'global.adminPartitions.enabled=true' \
--set 'global.enabled=true' \
.
}

@test "partitionName/ConfigMap: disabled with global.adminPartitions.enabled=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-role.yaml \
--set 'global.adminPartitions.enabled=false' \
.
}

0 comments on commit 7bb77a2

Please sign in to comment.