diff --git a/src/main/java/io/kestra/plugin/kubernetes/runner/KubernetesTaskRunner.java b/src/main/java/io/kestra/plugin/kubernetes/runner/KubernetesTaskRunner.java index 96b3f4f..62cefee 100644 --- a/src/main/java/io/kestra/plugin/kubernetes/runner/KubernetesTaskRunner.java +++ b/src/main/java/io/kestra/plugin/kubernetes/runner/KubernetesTaskRunner.java @@ -227,7 +227,7 @@ public RunnerResult run(RunContext runContext, TaskCommands taskCommands, List 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) @@ -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 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 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 allLabels = this.labels == null ? new HashMap<>() : runContext.renderMap(this.labels); allLabels.putAll(ScriptService.labels(runContext, "kestra.io/"));