Skip to content

Commit

Permalink
refactor: use simpler naming for init task config
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 22, 2023
1 parent c4a5b81 commit 844beec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down

0 comments on commit 844beec

Please sign in to comment.