From 63b197d83c7d055280f550d50f3216cf695666b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= Date: Wed, 20 Mar 2024 14:14:47 +0100 Subject: [PATCH] Add pullPolicy configuration for image patcher --- .../theodolite/kubernetes/patcher/ImagePatcher.kt | 11 ++++++++++- .../theodolite/kubernetes/patcher/PatcherFactory.kt | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/ImagePatcher.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/ImagePatcher.kt index ce23aaa04..ea1b61609 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/ImagePatcher.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/ImagePatcher.kt @@ -10,23 +10,32 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSet * * @param container Container to be patched. */ -class ImagePatcher(private val container: String) : AbstractStringPatcher() { +class ImagePatcher(private val container: String, private val pullPolicy: String? = null) : AbstractStringPatcher() { override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata { when (resource) { is Deployment -> { resource.spec.template.spec.containers.filter { it.name == container }.forEach { it.image = value + if (pullPolicy != null) { + it.imagePullPolicy = pullPolicy + } } } is StatefulSet -> { resource.spec.template.spec.containers.filter { it.name == container }.forEach { it.image = value + if (pullPolicy != null) { + it.imagePullPolicy = pullPolicy + } } } is Pod -> { resource.spec.containers.filter { it.name == container }.forEach { it.image = value + if (pullPolicy != null) { + it.imagePullPolicy = pullPolicy + } } } } diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/PatcherFactory.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/PatcherFactory.kt index d996b5450..7d47dc8b6 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/PatcherFactory.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/patcher/PatcherFactory.kt @@ -75,7 +75,8 @@ class PatcherFactory { ?: throwInvalid(patcher) ) "ImagePatcher" -> ImagePatcher( - container = patcher.properties["container"] ?: throwInvalid(patcher) + container = patcher.properties["container"] ?: throwInvalid(patcher), + pullPolicy = patcher.properties["pullPolicy"] ) "ConfigMapYamlPatcher" -> DecoratingPatcher( ConfigMapYamlPatcher(