Skip to content

Commit

Permalink
feat: auto restart deployment when config files change (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiming Guo <[email protected]>
  • Loading branch information
zhming0 authored Feb 2, 2024
1 parent f535ead commit 9493989
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/zot/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ appVersion: v2.0.1
description: A Helm chart for Kubernetes
name: zot
type: application
version: 0.1.46
version: 0.1.47
7 changes: 5 additions & 2 deletions charts/zot/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ spec:
{{- include "zot.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if and .Values.mountConfig .Values.configFiles }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}
labels:
{{- include "zot.selectorLabels" . | nindent 8 }}
spec:
Expand Down
23 changes: 23 additions & 0 deletions charts/zot/unittests/configmap_checksum_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
suite: configmap checksum in deployment
# Can't use global templates in this test suite as it will break the checksum calculation
# causing false negative test outcome.
# templates:
# - deployment.yaml
tests:
- it: has no checksum/config if no config
template: deployment.yaml
asserts:
- isNull:
path: spec.template.metadata.annotations.checksum/config
- it: generate checksum/config if config is present
template: deployment.yaml
set:
mountConfig: true
configFiles:
config.json: "{}"
asserts:
- isNotNull:
path: spec.template.metadata.annotations.checksum/config
- matchRegex:
path: spec.template.metadata.annotations.checksum/config
pattern: "^[a-f0-9]{64}$" # SHA256 hex output
2 changes: 2 additions & 0 deletions charts/zot/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ extraVolumeMounts: []
extraVolumes: []
# - name: data
# emptyDir: {}

podAnnotations: {}

0 comments on commit 9493989

Please sign in to comment.