From 6d7bc7f29d1abeb724c715e32f9fe61e7b61ff94 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 16 May 2023 12:32:12 +0200 Subject: [PATCH] Change default image for init container waiters To groundnuty/k8s-wait-for:no-root-v1.7. Related to https://github.com/quarkusio/quarkus/issues/33097#issuecomment-1532989601 --- .../spi/KubernetesInitContainerBuildItem.java | 4 ++-- .../deployment/InitTaskProcessor.java | 21 +++++++++++++------ .../KubernetesWithFlywayInitTest.java | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesInitContainerBuildItem.java b/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesInitContainerBuildItem.java index e295485449a7d3..5b9b026f1fe9e5 100644 --- a/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesInitContainerBuildItem.java +++ b/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesInitContainerBuildItem.java @@ -24,8 +24,8 @@ public final class KubernetesInitContainerBuildItem extends MultiBuildItem { private final boolean sharedEnvironment; private final boolean sharedFilesystem; - public static KubernetesInitContainerBuildItem create(String image) { - return new KubernetesInitContainerBuildItem("init", null, image, Collections.emptyList(), Collections.emptyList(), + public static KubernetesInitContainerBuildItem create(String name, String image) { + return new KubernetesInitContainerBuildItem(name, null, image, Collections.emptyList(), Collections.emptyList(), Collections.emptyMap(), false, false); } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/InitTaskProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/InitTaskProcessor.java index d99751102f5b4e..64dc6308db7cc4 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/InitTaskProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/InitTaskProcessor.java @@ -1,6 +1,6 @@ package io.quarkus.kubernetes.deployment; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -20,6 +20,9 @@ public class InitTaskProcessor { + private static final String INIT_CONTAINER_WAITER_NAME = "init"; + private static final String INIT_CONTAINER_WAITER_DEFAULT_IMAGE = "groundnuty/k8s-wait-for:no-root-v1.7"; + static void process( String target, // kubernetes, openshift, etc. String name, @@ -31,11 +34,11 @@ static void process( BuildProducer roleBindings, BuildProducer decorators) { - initTasks.forEach(task -> { - initContainers.produce(KubernetesInitContainerBuildItem.create("groundnuty/k8s-wait-for:1.3") - .withTarget(target) - .withArguments(Arrays.asList("job", task.getName()))); + List initContainerWaiterArgs = new ArrayList<>(initTasks.size() + 1); + initContainerWaiterArgs.add("job"); + initTasks.forEach(task -> { + initContainerWaiterArgs.add(task.getName()); jobs.produce(KubernetesJobBuildItem.create(image.getImage()) .withName(task.getName()) .withTarget(target) @@ -53,7 +56,9 @@ static void process( .build()))); }); + }); + if (!initTasks.isEmpty()) { roles.produce(new KubernetesRoleBuildItem("view-jobs", Collections.singletonList( new PolicyRule( Collections.singletonList("batch"), @@ -62,6 +67,10 @@ static void process( target)); roleBindings.produce(new KubernetesRoleBindingBuildItem(null, "view-jobs", false, target)); - }); + initContainers.produce(KubernetesInitContainerBuildItem.create(INIT_CONTAINER_WAITER_NAME, + INIT_CONTAINER_WAITER_DEFAULT_IMAGE) + .withTarget(target) + .withArguments(initContainerWaiterArgs)); + } } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithFlywayInitTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithFlywayInitTest.java index cad12e46331152..a6cde6e2997452 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithFlywayInitTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithFlywayInitTest.java @@ -67,6 +67,7 @@ public void assertGeneratedResources() throws IOException { assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getInitContainers()).singleElement().satisfies(container -> { assertThat(container.getName()).isEqualTo("init"); + assertThat(container.getImage()).isEqualTo("groundnuty/k8s-wait-for:no-root-v1.7"); }); });