From 949398975867f1f96796e3f73fcdcc6f60df9a20 Mon Sep 17 00:00:00 2001 From: Zhiming Guo Date: Sat, 3 Feb 2024 05:56:43 +1100 Subject: [PATCH] feat: auto restart deployment when config files change (#36) Signed-off-by: Zhiming Guo --- charts/zot/Chart.yaml | 2 +- charts/zot/templates/deployment.yaml | 7 ++++-- .../unittests/configmap_checksum_test.yaml | 23 +++++++++++++++++++ charts/zot/values.yaml | 2 ++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 charts/zot/unittests/configmap_checksum_test.yaml diff --git a/charts/zot/Chart.yaml b/charts/zot/Chart.yaml index 70b15a5..675b701 100644 --- a/charts/zot/Chart.yaml +++ b/charts/zot/Chart.yaml @@ -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 diff --git a/charts/zot/templates/deployment.yaml b/charts/zot/templates/deployment.yaml index e8c0574..0d29c5c 100644 --- a/charts/zot/templates/deployment.yaml +++ b/charts/zot/templates/deployment.yaml @@ -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: diff --git a/charts/zot/unittests/configmap_checksum_test.yaml b/charts/zot/unittests/configmap_checksum_test.yaml new file mode 100644 index 0000000..9d366e4 --- /dev/null +++ b/charts/zot/unittests/configmap_checksum_test.yaml @@ -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 diff --git a/charts/zot/values.yaml b/charts/zot/values.yaml index ad32913..2d8940c 100644 --- a/charts/zot/values.yaml +++ b/charts/zot/values.yaml @@ -171,3 +171,5 @@ extraVolumeMounts: [] extraVolumes: [] # - name: data # emptyDir: {} + +podAnnotations: {}