docs: Update configHash tip to use insertTemplate function

An advantage of this method over the previous one is that any edits to
the ConfigMap yaml file will also trigger a rolling update.

It also keeps knowledge of what the ConfigMap contains inside its yaml
file instead of the Deployment needing to know which variables to hash.
This commit is contained in:
Jude Venn 2019-04-30 10:05:09 +01:00 committed by Vincent Ambo
parent c422686f84
commit 75a3cd2534

View file

@ -17,24 +17,26 @@ of Deployments and other resource types when `ConfigMap` or `Secret` objects
are updated. are updated.
It is possible to make use of annotations and templating functions in It is possible to make use of annotations and templating functions in
Kontemplate to force updates to these resources anyways (assuming that the Kontemplate to force updates to these resources anyways.
`ConfigMap` or `Secret` contains interpolated variables).
For example: For example:
```yaml ```yaml
# A ConfigMap that contains some data structure in JSON format # A ConfigMap that contains some configuration for your app
--- ---
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: app-config name: app-config
data: data:
configFile: {{ .appConfig | json }} app.conf: |
name: {{ .appName }}
foo: bar
``` ```
Now whenever the `appConfig` variable changes we would like to update the Now whenever the `appName` variable changes or we make an edit to the
`Deployment` making use of it, too. We can do this by adding a hash of the `ConfigMap` we would like to update the `Deployment` making use of it, too. We
configuration to the annotations of the created `Pod` objects: can do this by adding a hash of the parsed template to the annotations of the
created `Pod` objects:
```yaml ```yaml
@ -46,7 +48,7 @@ spec:
template: template:
metadata: metadata:
annotations: annotations:
configHash: {{ .appConfig | json | sha256sum }} configHash: {{ insertTemplate "app-config.yaml" | sha256sum }}
spec: spec:
containers: containers:
- name: app - name: app
@ -60,9 +62,9 @@ spec:
name: app-config name: app-config
``` ```
Now if the `ConfigMap` object appears first in the resource files, `kubectl` Now any change to the `ConfigMap` - either by directly editing the yaml file or
will apply the resources sequentially and the updated annotation will cause via a changed template variable - will cause the annotation to change,
a rolling update of all relevant pods. triggering a rolling update of all relevant pods.
## direnv & pass ## direnv & pass