From c76809fdcfa16f69b7173adfda972708435397ab Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Mon, 2 Oct 2023 17:04:28 +0200 Subject: [PATCH] Make Helm chart cleanup job container image configurable We `parameters.backup_k8up.images.kubectl` and add a postprocessing filter which patches the cleanup job to use the image location specified in that image parameter. --- class/backup-k8up.yml | 3 ++ class/defaults.yml | 4 +++ postprocess/cleanup-job.jsonnet | 28 +++++++++++++++++++ .../k8up/templates/cleanup-hook.yaml | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 postprocess/cleanup-job.jsonnet diff --git a/class/backup-k8up.yml b/class/backup-k8up.yml index dee1935..f6b96e8 100644 --- a/class/backup-k8up.yml +++ b/class/backup-k8up.yml @@ -39,3 +39,6 @@ parameters: - type: jsonnet filter: postprocess/optional_global_config.jsonnet path: ${_instance}/01_k8up_helmchart/k8up/templates + - type: jsonnet + filter: postprocess/cleanup-job.jsonnet + path: ${_instance}/01_k8up_helmchart/k8up/templates diff --git a/class/defaults.yml b/class/defaults.yml index cd7f5e1..3d77e76 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -11,6 +11,10 @@ parameters: repository: k8up-io/k8up tag: v2.7.1 pullPolicy: IfNotPresent + kubectl: + registry: docker.io + repository: bitnami/kubectl + tag: latest helmReleaseName: k8up diff --git a/postprocess/cleanup-job.jsonnet b/postprocess/cleanup-job.jsonnet new file mode 100644 index 0000000..05fe464 --- /dev/null +++ b/postprocess/cleanup-job.jsonnet @@ -0,0 +1,28 @@ +local com = import 'lib/commodore.libjsonnet'; +local kube = import 'lib/kube.libjsonnet'; + +local inv = com.inventory(); +local params = inv.parameters.backup_k8up; + +local chart_output_dir = std.extVar('output_path'); + +local patch_registry(obj) = + if obj.kind == 'Job' then + obj { + spec+: { + template+: { + spec+: { + containers: [ + c { + image: '%(registry)s/%(repository)s:%(tag)s' % params.images.kubectl, + } + for c in super.containers + ], + }, + }, + }, + } + else + obj; + +com.fixupDir(chart_output_dir, patch_registry) diff --git a/tests/golden/defaults/backup-k8up/backup-k8up/01_k8up_helmchart/k8up/templates/cleanup-hook.yaml b/tests/golden/defaults/backup-k8up/backup-k8up/01_k8up_helmchart/k8up/templates/cleanup-hook.yaml index daf97e7..9d14024 100644 --- a/tests/golden/defaults/backup-k8up/backup-k8up/01_k8up_helmchart/k8up/templates/cleanup-hook.yaml +++ b/tests/golden/defaults/backup-k8up/backup-k8up/01_k8up_helmchart/k8up/templates/cleanup-hook.yaml @@ -100,7 +100,7 @@ spec: command: - sh - -c - image: bitnami/kubectl:latest + image: docker.io/bitnami/kubectl:latest name: k8up-cleanup restartPolicy: Never serviceAccountName: cleanup-service-account