Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Annotate deployments with hashed extraconfig
Browse files Browse the repository at this point in the history
- When the extra config for a client or server is updated, it updates
  the underlying configMap but has no way of informing the server statefulSet or client daemonSet of the update.With this PR, the values for server.extraConfig & client.extraConfig
are saved as annotations on the server statefulSet spec and client
daemonsetSpec respectfully. If a user updates the extraConfig and
performs a `helm upgrade`, it will force a reconcile of the server and
client pods (depending on what changed) and will keep them updated with
the latest config.

Signed-off-by: Ashwin Venkatesh <[email protected]>
  • Loading branch information
Ashwin Venkatesh committed Jul 24, 2020
1 parent 6303775 commit 65a0941
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Unreleased

IMPROVEMENTS:

* Add server.extraConfig and client.extraConfig values as hashes on Server
StatefulSet and Client Daemonset annotations respectively. This recreates
the server/client pod when the server/client extraConfig is updated via `helm upgrade` [[GH-550](https://github.com/hashicorp/consul-helm/pull/550)]

## 0.23.1 (July 10, 2020)

BUG FIXES:
Expand Down
1 change: 1 addition & 0 deletions templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ spec:
hasDNS: "true"
annotations:
"consul.hashicorp.com/connect-inject": "false"
"consul.hashicorp.com/config-checksum": {{ .Values.client.extraConfig | sha256sum }}
{{- if .Values.client.annotations }}
{{- tpl .Values.client.annotations . | nindent 8 }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
hasDNS: "true"
annotations:
"consul.hashicorp.com/connect-inject": "false"
"consul.hashicorp.com/config-checksum": {{ .Values.server.extraConfig | sha256sum }}
{{- if .Values.server.annotations }}
{{- tpl .Values.server.annotations . | nindent 8 }}
{{- end }}
Expand Down
24 changes: 23 additions & 1 deletion test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ load _helpers
local actual=$(helm template \
-s templates/client-daemonset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject")' | tee /dev/stderr)
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject") | del(."consul.hashicorp.com/config-checksum")' | tee /dev/stderr)
[ "${actual}" = "{}" ]
}

Expand All @@ -369,6 +369,28 @@ load _helpers
[ "${actual}" = "bar" ]
}

#--------------------------------------------------------------------
# extraConfig

@test "client/DaemonSet: adds config-checksum annotation when extraConfig is blank" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356 ]
}

@test "client/DaemonSet: adds config-checksum annotation when extraConfig is provided" {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
--set 'client.extraConfig="{\"hello\": \"world\"}"' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = 83df36fdaf1b4acb815f1764f9ff2782c520ca012511f282ba9c57a04401a239 ]
}

#--------------------------------------------------------------------
# tolerations

Expand Down
23 changes: 22 additions & 1 deletion test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ load _helpers
local actual=$(helm template \
-s templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject")' | tee /dev/stderr)
yq -r '.spec.template.metadata.annotations | del(."consul.hashicorp.com/connect-inject") | del(."consul.hashicorp.com/config-checksum")' | tee /dev/stderr)
[ "${actual}" = "{}" ]
}

Expand All @@ -366,6 +366,27 @@ load _helpers
yq -r '.spec.template.metadata.annotations.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
#--------------------------------------------------------------------
# extraConfig

@test "server/StatefulSet: adds config-checksum annotation when extraConfig is blank" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356 ]
}

@test "server/StatefulSet: adds config-checksum annotation when extraConfig is provided" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'server.extraConfig="{\"hello\": \"world\"}"' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr)
[ "${actual}" = 83df36fdaf1b4acb815f1764f9ff2782c520ca012511f282ba9c57a04401a239 ]
}

#--------------------------------------------------------------------
# tolerations
Expand Down

0 comments on commit 65a0941

Please sign in to comment.