From 844beeca2257e0ccc91a470b0be8cf62a5daf68e Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Fri, 22 Sep 2023 12:59:02 +0300 Subject: [PATCH] refactor: use simpler naming for init task config --- .../kubernetes/deployment/InitTaskProcessor.java | 12 +++++++++--- ...KubernetesInitTaskWithCustomWaitForImageTest.java | 2 +- .../it/kubernetes/KubernetesWithFlywayInitTest.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) 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 3d7be4b9fe4ba2..cef2deabd61170 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 @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import io.dekorate.kubernetes.config.EnvBuilder; import io.dekorate.kubernetes.decorator.AddEnvVarDecorator; @@ -21,7 +22,7 @@ public class InitTaskProcessor { - private static final String INIT_CONTAINER_WAITER_NAME = "init"; + private static final String INIT_CONTAINER_WAITER_NAME = "wait-for-"; static void process( String target, // kubernetes, openshift, etc. @@ -40,6 +41,11 @@ static void process( boolean generateRoleForJobs = false; for (InitTaskBuildItem task : initTasks) { + String taskName = task.getName() + //Strip appplication.name prefix and init suffix (for compatibility with previous versions) + .replaceAll("^" + Pattern.quote(name + "-"), "") + .replaceAll(Pattern.quote("-init") + "$", ""); + String jobName = name + "-" + taskName + "-init"; InitTaskConfig config = initTasksConfig.getOrDefault(task.getName(), initTaskDefaults); if (config == null || config.enabled) { generateRoleForJobs = true; @@ -61,9 +67,9 @@ static void process( }); String waitForImage = config.image.orElse(config.waitForImage); - initContainers.produce(KubernetesInitContainerBuildItem.create(INIT_CONTAINER_WAITER_NAME, waitForImage) + initContainers.produce(KubernetesInitContainerBuildItem.create("wait-for-" + taskName, waitForImage) .withTarget(target) - .withArguments(List.of("job", task.getName()))); + .withArguments(List.of("job", jobName))); } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesInitTaskWithCustomWaitForImageTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesInitTaskWithCustomWaitForImageTest.java index b1926be6897fe1..095e4e8c4c24d9 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesInitTaskWithCustomWaitForImageTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesInitTaskWithCustomWaitForImageTest.java @@ -66,7 +66,7 @@ public void assertGeneratedResources() throws IOException { assertThat(deploymentSpec.getTemplate()).satisfies(t -> { assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getInitContainers()).singleElement().satisfies(container -> { - assertThat(container.getName()).isEqualTo("init"); + assertThat(container.getName()).isEqualTo("wait-for-flyway"); assertThat(container.getImage()).isEqualTo(WAIT_FOR_IMAGE); }); 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 fb7fe0aba6d618..b180f364628574 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 @@ -71,7 +71,7 @@ public void assertGeneratedResources() throws IOException { .satisfies(s -> assertThat(s.getName()).isEqualTo(IMAGE_PULL_SECRET)); assertThat(podSpec.getServiceAccountName()).isEqualTo(NAME); assertThat(podSpec.getInitContainers()).singleElement().satisfies(container -> { - assertThat(container.getName()).isEqualTo("init"); + assertThat(container.getName()).isEqualTo("wait-for-flyway"); assertThat(container.getImage()).isEqualTo("groundnuty/k8s-wait-for:no-root-v1.7"); });