diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/EmptyDirVolumeConverter.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/EmptyDirVolumeConverter.java new file mode 100644 index 0000000000000..496b87753643c --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/EmptyDirVolumeConverter.java @@ -0,0 +1,15 @@ + +package io.quarkus.kubernetes.deployment; + +import io.dekorate.kubernetes.config.EmptyDirVolume; +import io.dekorate.kubernetes.config.EmptyDirVolumeBuilder; + +public class EmptyDirVolumeConverter { + + public static EmptyDirVolume convert(String volumeName) { + EmptyDirVolumeBuilder b = new EmptyDirVolumeBuilder(); + b.withVolumeName(volumeName); + return b.build(); + } + +} diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java index e791b0f5c45de..b35367909fae0 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java @@ -1,5 +1,6 @@ package io.quarkus.kubernetes.deployment; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -156,6 +157,12 @@ public class KnativeConfig implements PlatformConfiguration { @ConfigItem Map configMapVolumes; + /** + * EmptyDir volumes + */ + @ConfigItem + Optional> emptyDirVolumes; + /** * Git Repository volumes */ @@ -315,6 +322,10 @@ public Map getConfigMapVolumes() { return configMapVolumes; } + public List getEmptyDirVolumes() { + return emptyDirVolumes.orElse(Collections.emptyList()); + } + public Map getGitRepoVolumes() { return gitRepoVolumes; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java index 072ed10cc3b98..21ce61640fe93 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeProcessor.java @@ -15,6 +15,7 @@ import io.dekorate.knative.decorator.AddAzureDiskVolumeToRevisionDecorator; import io.dekorate.knative.decorator.AddAzureFileVolumeToRevisionDecorator; import io.dekorate.knative.decorator.AddConfigMapVolumeToRevisionDecorator; +import io.dekorate.knative.decorator.AddEmptyDirVolumeToRevisionDecorator; import io.dekorate.knative.decorator.AddHostAliasesToRevisionDecorator; import io.dekorate.knative.decorator.AddPvcVolumeToRevisionDecorator; import io.dekorate.knative.decorator.AddSecretVolumeToRevisionDecorator; @@ -333,6 +334,11 @@ private static List createVolumeDecorators(Optional new AddConfigMapVolumeToRevisionDecorator(ConfigMapVolumeConverter.convert(e)))); }); + config.getEmptyDirVolumes().forEach(e -> { + result.add(new DecoratorBuildItem(KNATIVE, + new AddEmptyDirVolumeToRevisionDecorator(EmptyDirVolumeConverter.convert(e)))); + }); + config.getPvcVolumes().entrySet().forEach(e -> { result.add(new DecoratorBuildItem(KNATIVE, new AddPvcVolumeToRevisionDecorator(PvcVolumeConverter.convert(e)))); }); diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java index f3d48ef3c7bc9..2455face66843 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java @@ -30,6 +30,7 @@ import io.dekorate.kubernetes.decorator.AddAzureDiskVolumeDecorator; import io.dekorate.kubernetes.decorator.AddAzureFileVolumeDecorator; import io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator; +import io.dekorate.kubernetes.decorator.AddEmptyDirVolumeDecorator; import io.dekorate.kubernetes.decorator.AddEnvVarDecorator; import io.dekorate.kubernetes.decorator.AddHostAliasesDecorator; import io.dekorate.kubernetes.decorator.AddImagePullSecretDecorator; @@ -383,6 +384,10 @@ private static List createMountAndVolumeDecorators(Optional< result.add(new DecoratorBuildItem(target, new AddConfigMapVolumeDecorator(ConfigMapVolumeConverter.convert(e)))); }); + config.getEmptyDirVolumes().forEach(e -> { + result.add(new DecoratorBuildItem(target, new AddEmptyDirVolumeDecorator(EmptyDirVolumeConverter.convert(e)))); + }); + config.getPvcVolumes().entrySet().forEach(e -> { result.add(new DecoratorBuildItem(target, new AddPvcVolumeDecorator(PvcVolumeConverter.convert(e)))); }); 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 d2d59cca38738..bf1c97572b8d5 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,6 +3,7 @@ import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT; import static io.quarkus.kubernetes.deployment.Constants.STATEFULSET; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -191,6 +192,12 @@ public enum DeploymentResourceKind { @ConfigItem Map configMapVolumes; + /** + * EmptyDir volumes + */ + @ConfigItem + Optional> emptyDirVolumes; + /** * Git Repository volumes */ @@ -453,6 +460,10 @@ public Map getConfigMapVolumes() { return configMapVolumes; } + public List getEmptyDirVolumes() { + return emptyDirVolumes.orElse(Collections.emptyList()); + } + public Map getGitRepoVolumes() { return gitRepoVolumes; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java index 549163563f006..e12d0fa1aca9c 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/OpenshiftConfig.java @@ -11,6 +11,7 @@ import static io.quarkus.kubernetes.deployment.Constants.S2I; import static io.quarkus.kubernetes.deployment.Constants.STATEFULSET; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -220,6 +221,12 @@ public static enum DeploymentResourceKind { @ConfigItem Map configMapVolumes; + /** + * EmptyDir volumes + */ + @ConfigItem + Optional> emptyDirVolumes; + /** * Git Repository volumes */ @@ -406,6 +413,10 @@ public Map getConfigMapVolumes() { return configMapVolumes; } + public List getEmptyDirVolumes() { + return emptyDirVolumes.orElse(Collections.emptyList()); + } + public Map getGitRepoVolumes() { return gitRepoVolumes; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java index 810d2f6549cb2..b0673552fc354 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PlatformConfiguration.java @@ -56,6 +56,8 @@ public interface PlatformConfiguration extends EnvVarHolder { Map getConfigMapVolumes(); + List getEmptyDirVolumes(); + Map getGitRepoVolumes(); Map getPvcVolumes(); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithEmptyDirVolumesTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithEmptyDirVolumesTest.java new file mode 100644 index 0000000000000..495ae2b8bf016 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithEmptyDirVolumesTest.java @@ -0,0 +1,66 @@ + +package io.quarkus.it.kubernetes; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.apps.Deployment; +import io.quarkus.builder.Version; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.ProdBuildResults; +import io.quarkus.test.ProdModeTestResults; +import io.quarkus.test.QuarkusProdModeTest; + +public class KubernetesWithEmptyDirVolumesTest { + + private static final String NAME = "kubernetes-with-emptydir-volumes"; + + @RegisterExtension + static final QuarkusProdModeTest config = new QuarkusProdModeTest() + .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) + .setApplicationName(NAME) + .setApplicationVersion("0.1-SNAPSHOT") + .withConfigurationResource(NAME + ".properties") + .setLogFileName("k8s.log") + .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion()))); + + @ProdBuildResults + private ProdModeTestResults prodModeTestResults; + + @Test + public void assertGeneratedResources() throws IOException { + final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); + assertThat(kubernetesDir) + .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) + .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); + List kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); + assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> { + assertThat(m.getName()).isEqualTo(NAME); + }); + + assertThat(d.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getSpec()).satisfies(podSpec -> { + assertThat(podSpec.getVolumes()).isNotEmpty(); + assertThat(podSpec.getVolumes()).anySatisfy(volume -> { + assertThat(volume.getName()).isEqualTo("cache-volume"); + assertThat(volume.getEmptyDir()).isNotNull(); + }); + assertThat(podSpec.getVolumes()).anySatisfy(volume -> { + assertThat(volume.getName()).isEqualTo("app-data"); + assertThat(volume.getEmptyDir()).isNotNull(); + }); + }); + }); + }); + }); + } +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-emptydir-volumes.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-emptydir-volumes.properties new file mode 100644 index 0000000000000..237c2e241a786 --- /dev/null +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-emptydir-volumes.properties @@ -0,0 +1,3 @@ +quarkus.kubernetes.mounts.cache-volume.path=/cache +quarkus.kubernetes.mounts.app-data.path=/data +quarkus.kubernetes.empty-dir-volumes=cache-volume,app-data \ No newline at end of file