From d017d6ca2e59571361fca7f07602703f8844d5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20B=C3=B8hmer?= Date: Mon, 27 Apr 2026 12:21:18 +0200 Subject: [PATCH] feat(common): make imagePullPolicy configurable Adds support for overriding imagePullPolicy globally and per container. Useful for local Kubernetes cluster testing (e.g. kind) where images are loaded directly into the cluster and should not be pulled from a remote registry. --- charts/common/templates/cron.yaml | 3 +- charts/common/templates/deployment.yaml | 3 +- charts/common/tests/cron_test.yaml | 26 +++++++++++++++++- charts/common/tests/deployment_test.yaml | 35 ++++++++++++++++++++++++ charts/common/values.yaml | 6 ++++ 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/charts/common/templates/cron.yaml b/charts/common/templates/cron.yaml index def2e8f..0cf9851 100644 --- a/charts/common/templates/cron.yaml +++ b/charts/common/templates/cron.yaml @@ -10,6 +10,7 @@ {{- $postgres := .Values.postgres -}} {{- $secrets := .Values.secrets -}} {{- $cronjob := .Values.cron -}} +{{- $globalPullPolicy := .Values.imagePullPolicy | default "Always" -}} {{- if $cronjob.enabled -}} {{- /* YAML Spec */}} @@ -57,7 +58,7 @@ spec: {{- printf "\n " -}} - name: {{ .name | default $app }} image: {{ $image }} - imagePullPolicy: Always + imagePullPolicy: {{ .pullPolicy | default $globalPullPolicy }} {{- if .command }} command: {{ .command }} {{- end }} diff --git a/charts/common/templates/deployment.yaml b/charts/common/templates/deployment.yaml index b4ea0f1..e8f6cfb 100644 --- a/charts/common/templates/deployment.yaml +++ b/charts/common/templates/deployment.yaml @@ -23,6 +23,7 @@ {{- $maxSurge := .Values.deployment.maxSurge | default "25%" }} {{- $maxUnavailable := .Values.deployment.maxUnavailable | default "25%" }} {{- $hpa := .Values.hpa | default dict }} +{{- $globalPullPolicy := .Values.imagePullPolicy | default "Always" }} {{- if $enabled }} {{- /* YAML Spec */}} apiVersion: apps/v1 @@ -82,7 +83,7 @@ spec: {{- printf "\n " -}} - name: {{ .name | default $app }} image: {{ $image }} - imagePullPolicy: Always + imagePullPolicy: {{ .pullPolicy | default $globalPullPolicy }} {{- if .command }} command: {{ .command }} {{- end }} diff --git a/charts/common/tests/cron_test.yaml b/charts/common/tests/cron_test.yaml index b2ce8b3..87a2f6a 100644 --- a/charts/common/tests/cron_test.yaml +++ b/charts/common/tests/cron_test.yaml @@ -239,4 +239,28 @@ tests: asserts: - equal: path: spec.jobTemplate.spec.activeDeadlineSeconds - value: 1200 \ No newline at end of file + value: 1200 + - it: imagePullPolicy defaults to Always + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].imagePullPolicy + value: Always + - it: imagePullPolicy can be overridden globally + set: + imagePullPolicy: Never + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].imagePullPolicy + value: Never + - it: per-container pullPolicy takes precedence over global imagePullPolicy + set: + imagePullPolicy: Never + containers: + - image: img + pullPolicy: IfNotPresent + probes: + enabled: false + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].imagePullPolicy + value: IfNotPresent \ No newline at end of file diff --git a/charts/common/tests/deployment_test.yaml b/charts/common/tests/deployment_test.yaml index 47fa305..bf05231 100644 --- a/charts/common/tests/deployment_test.yaml +++ b/charts/common/tests/deployment_test.yaml @@ -592,6 +592,41 @@ tests: - equal: path: spec.minReadySeconds value: 10 + - it: imagePullPolicy defaults to Always + asserts: + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: Always + - it: imagePullPolicy can be overridden globally + set: + imagePullPolicy: Never + asserts: + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: Never + - it: imagePullPolicy can be overridden per container + set: + containers: + - image: img + pullPolicy: IfNotPresent + probes: + enabled: false + asserts: + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: IfNotPresent + - it: per-container pullPolicy takes precedence over global imagePullPolicy + set: + imagePullPolicy: Never + containers: + - image: img + pullPolicy: Always + probes: + enabled: false + asserts: + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: Always - it: can set initContainers set: initContainers: diff --git a/charts/common/values.yaml b/charts/common/values.yaml index a6f412e..a1b1375 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -13,6 +13,10 @@ releaseName: # @default -- `{ app shortname team common:version environment }` labels: {} +# -- Override image pull policy for all containers. Useful for local cluster testing (kind/k3s) where images are loaded directly. Valid values: Always, IfNotPresent, Never +# @default -- Always +imagePullPolicy: + ingress: # -- Enable or disable the ingress enabled: true @@ -139,6 +143,8 @@ container: # -- Name of container # @default -- .app name: + # -- Override image pull policy for this container. Overrides the global `imagePullPolicy`. Valid values: Always, IfNotPresent, Never + pullPolicy: # -- Add labels to your pods labels: {} # -- Optionally set the command that will run in the pod. If not set, the entrypoint for the container-image is used (recommended for most Java-apps).