diff --git a/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesOutputDirectoryBuildItem.java b/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesOutputDirectoryBuildItem.java new file mode 100644 index 0000000000000..4f1697b59f5e2 --- /dev/null +++ b/extensions/kubernetes/spi/src/main/java/io/quarkus/kubernetes/spi/KubernetesOutputDirectoryBuildItem.java @@ -0,0 +1,20 @@ +package io.quarkus.kubernetes.spi; + +import java.nio.file.Path; + +import io.quarkus.builder.item.SimpleBuildItem; + +/** + * Contains the effective output directory where to find the generated kubernetes resources. + */ +public final class KubernetesOutputDirectoryBuildItem extends SimpleBuildItem { + private final Path outputDirectory; + + public KubernetesOutputDirectoryBuildItem(Path outputDirectory) { + this.outputDirectory = outputDirectory; + } + + public Path getOutputDirectory() { + return outputDirectory; + } +} diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java index 5067221b90ca9..3a4a79888d640 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesConfig.java @@ -3,11 +3,8 @@ import static io.quarkus.kubernetes.deployment.Constants.CRONJOB; import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT; import static io.quarkus.kubernetes.deployment.Constants.JOB; -import static io.quarkus.kubernetes.deployment.Constants.KUBERNETES; import static io.quarkus.kubernetes.deployment.Constants.STATEFULSET; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Map; @@ -617,17 +614,4 @@ public KubernetesConfig.DeploymentResourceKind getDeploymentResourceKind(Capabil return DeploymentResourceKind.Deployment; } - - /** - * Resolve the effective output directory where to generate the Kubernetes manifests. - * If the `quarkus.kubernetes.output-directory` property is not provided, then the default project output directory will be - * used. - * - * @param projectOutputDirectory The project output target. - * @return the effective output directory. - */ - public Path getEffectiveOutputDirectory(Path projectOutputDirectory) { - return outputDirectory.map(d -> Paths.get("").toAbsolutePath().resolve(d)) - .orElse(projectOutputDirectory.resolve(KUBERNETES)); - } } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java index 26917e6738d6e..8e82e3351b9a4 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java @@ -55,6 +55,7 @@ import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem; import io.quarkus.kubernetes.spi.KubernetesDeploymentClusterBuildItem; import io.quarkus.kubernetes.spi.KubernetesOptionalResourceDefinitionBuildItem; +import io.quarkus.kubernetes.spi.KubernetesOutputDirectoryBuildItem; public class KubernetesDeployer { @@ -110,7 +111,7 @@ public void deploy(KubernetesClientBuildItem kubernetesClientBuilder, List deploymentClusters, Optional selectedDeploymentTarget, OutputTargetBuildItem outputTarget, - KubernetesConfig kubernetesConfig, + KubernetesOutputDirectoryBuildItem outputDirectoryBuildItem, OpenshiftConfig openshiftConfig, ContainerImageConfig containerImageConfig, ApplicationInfoBuildItem applicationInfo, @@ -139,7 +140,7 @@ public void deploy(KubernetesClientBuildItem kubernetesClientBuilder, try (final KubernetesClient client = kubernetesClientBuilder.buildClient()) { deploymentResult .produce(deploy(selectedDeploymentTarget.get().getEntry(), client, - kubernetesConfig.getEffectiveOutputDirectory(outputTarget.getOutputDirectory()), + outputDirectoryBuildItem.getOutputDirectory(), openshiftConfig, applicationInfo, optionalResourceDefinitions)); } } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java index 8ae07053633d2..338948577a38a 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java @@ -55,6 +55,7 @@ import io.quarkus.kubernetes.spi.DekorateOutputBuildItem; import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem; import io.quarkus.kubernetes.spi.KubernetesDeploymentTargetBuildItem; +import io.quarkus.kubernetes.spi.KubernetesOutputDirectoryBuildItem; import io.quarkus.kubernetes.spi.KubernetesPortBuildItem; import io.quarkus.runtime.LaunchMode; @@ -113,7 +114,8 @@ public void build(ApplicationInfoBuildItem applicationInfo, BuildProducer dekorateSessionProducer, Optional customProjectRoot, BuildProducer generatedResourceProducer, - BuildProducer generatedKubernetesResourceProducer) { + BuildProducer generatedKubernetesResourceProducer, + BuildProducer outputDirectoryBuildItemBuildProducer) { List allConfigurators = new ArrayList<>(configurators); List allConfigurationSuppliers = new ArrayList<>(configurationSuppliers); @@ -183,7 +185,10 @@ public void build(ApplicationInfoBuildItem applicationInfo, } }); - Path targetDirectory = kubernetesConfig.getEffectiveOutputDirectory(outputTarget.getOutputDirectory()); + Path targetDirectory = getEffectiveOutputDirectory(kubernetesConfig, project.getRoot(), + outputTarget.getOutputDirectory()); + + outputDirectoryBuildItemBuildProducer.produce(new KubernetesOutputDirectoryBuildItem(targetDirectory)); // write the generated resources to the filesystem generatedResourcesMap = session.close(); @@ -277,4 +282,19 @@ private Path getRunner(OutputTargetBuildItem outputTarget, return buildDir.resolve(QUARKUS_RUN_JAR); } + + /** + * Resolve the effective output directory where to generate the Kubernetes manifests. + * If the `quarkus.kubernetes.output-directory` property is not provided, then the default project output directory will be + * used. + * + * @param config The Kubernetes configuration. + * @param projectLocation The project location. + * @param projectOutputDirectory The project output target. + * @return the effective output directory. + */ + private Path getEffectiveOutputDirectory(KubernetesConfig config, Path projectLocation, Path projectOutputDirectory) { + return config.outputDirectory.map(d -> projectLocation.resolve(d)) + .orElse(projectOutputDirectory.resolve(KUBERNETES)); + } }