Skip to content

Commit

Permalink
Add pullPolicy configuration for image patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
SoerenHenning committed Mar 20, 2024
1 parent 5a94331 commit 63b197d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 63b197d

Please sign in to comment.