Skip to content

Commit 8be8b1d

Browse files
authored
Merge pull request #31752 from Sgitario/31723
Rename AddJobResourceDecorator2 to CreateJobResourceFromImageDecorator
2 parents 777e35b + a055a07 commit 8be8b1d

File tree

4 files changed

+61
-94
lines changed

4 files changed

+61
-94
lines changed

extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddJobResourceDecorator2.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public final class Constants {
1414
public static final String INGRESS = "Ingress";
1515
public static final String BATCH_GROUP = "batch";
1616
public static final String BATCH_VERSION = "v1";
17+
public static final String JOB_API_VERSION = BATCH_GROUP + "/" + BATCH_VERSION;
1718

1819
static final String DOCKER = "docker";
1920

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
package io.quarkus.kubernetes.deployment;
3+
4+
import static io.quarkus.kubernetes.deployment.Constants.JOB;
5+
import static io.quarkus.kubernetes.deployment.Constants.JOB_API_VERSION;
6+
7+
import java.util.List;
8+
9+
import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator;
10+
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
11+
import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
12+
13+
/**
14+
* Create a new Job resource using an image, the command, and arguments.
15+
**/
16+
public class CreateJobResourceFromImageDecorator extends ResourceProvidingDecorator<KubernetesListBuilder> {
17+
18+
private static final String DEFAULT_RESTART_POLICY = "OnFailure";
19+
private static final String DEFAULT_COMPLETION_MODE = "OnFailure";
20+
21+
private final String name;
22+
private final String image;
23+
private final List<String> command;
24+
private final List<String> arguments;
25+
26+
public CreateJobResourceFromImageDecorator(String name, String image, List<String> command, List<String> arguments) {
27+
this.name = name;
28+
this.image = image;
29+
this.command = command;
30+
this.arguments = arguments;
31+
}
32+
33+
@Override
34+
public void visit(KubernetesListBuilder list) {
35+
if (!contains(list, JOB_API_VERSION, JOB, name)) {
36+
list.addToItems(new JobBuilder()
37+
.withNewMetadata()
38+
.withName(name)
39+
.endMetadata()
40+
.withNewSpec()
41+
.withCompletionMode(DEFAULT_COMPLETION_MODE)
42+
.withNewTemplate()
43+
.withNewSpec()
44+
.withRestartPolicy(DEFAULT_RESTART_POLICY)
45+
.addNewContainer()
46+
.withName(name)
47+
.withImage(image)
48+
.withCommand(command)
49+
.withArgs(arguments)
50+
.endContainer()
51+
.endSpec()
52+
.endTemplate()
53+
.endSpec()
54+
.build());
55+
}
56+
}
57+
}

extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,10 @@ public void andThenVisit(ContainerBuilder builder, ObjectMeta meta) {
467467
}
468468

469469
}
470+
470471
result.add(new DecoratorBuildItem(target,
471-
new AddJobResourceDecorator2(item.getName(), item.getImage(), item.getCommand(), item.getArguments())));
472+
new CreateJobResourceFromImageDecorator(item.getName(), item.getImage(), item.getCommand(),
473+
item.getArguments())));
472474
});
473475
return result;
474476
}

0 commit comments

Comments
 (0)