Skip to content

Commit

Permalink
fix: don't create the init container if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Apr 16, 2024
1 parent 8302dbf commit d53b0ce
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public RunnerResult run(RunContext runContext, TaskCommands taskCommands, List<S
}
if (pod == null) {
Container container = createContainer(runContext, taskCommands);
pod = createPod(runContext, container);
pod = createPod(runContext, container, !ListUtils.isEmpty(filesToUploadWithOutputDir), !ListUtils.isEmpty(filesToDownload) || outputDirectoryEnabled);
resource = client.pods().inNamespace(namespace).resource(pod);
pod = resource.create();
logger.info("Pod '{}' is created ", pod.getMetadata().getName());
Expand Down Expand Up @@ -364,7 +364,7 @@ private Map<String, Quantity> buildResource(Resource resource) {
return quantities;
}

private Pod createPod(RunContext runContext, Container mainContainer) throws IllegalVariableEvaluationException {
private Pod createPod(RunContext runContext, Container mainContainer, boolean initContainer, boolean sidecarContainer) throws IllegalVariableEvaluationException {
VolumeMount volumeMount = new VolumeMountBuilder()
.withMountPath("/kestra")
.withName(FILES_VOLUME_NAME)
Expand All @@ -375,27 +375,33 @@ private Pod createPod(RunContext runContext, Container mainContainer) throws Ill
.withRestartPolicy("Never")
.build();

spec.getContainers()
.add(filesContainer(runContext, volumeMount, true));

spec.getInitContainers()
.add(filesContainer(runContext, volumeMount, false));

spec.getContainers()
.forEach(container -> {
List<VolumeMount> volumeMounts = container.getVolumeMounts();
volumeMounts.add(volumeMount);
container.setVolumeMounts(volumeMounts);
container.setWorkingDir(WORKING_DIR.toString());
});

spec.getVolumes()
.add(new VolumeBuilder()
.withName(FILES_VOLUME_NAME)
.withNewEmptyDir()
.endEmptyDir()
.build()
);
if (sidecarContainer) {
spec.getContainers()
.add(filesContainer(runContext, volumeMount, true));
}

if (initContainer) {
spec.getInitContainers()
.add(filesContainer(runContext, volumeMount, false));
}

if (initContainer || sidecarContainer) {
spec.getContainers()
.forEach(container -> {
List<VolumeMount> volumeMounts = container.getVolumeMounts();
volumeMounts.add(volumeMount);
container.setVolumeMounts(volumeMounts);
container.setWorkingDir(WORKING_DIR.toString());
});

spec.getVolumes()
.add(new VolumeBuilder()
.withName(FILES_VOLUME_NAME)
.withNewEmptyDir()
.endEmptyDir()
.build()
);
}

Map<String, String> allLabels = this.labels == null ? new HashMap<>() : runContext.renderMap(this.labels);
allLabels.putAll(ScriptService.labels(runContext, "kestra.io/"));
Expand Down

0 comments on commit d53b0ce

Please sign in to comment.