diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PortConverter.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PortConverter.java index 4faf8ce1efdae..18193cf8540b6 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PortConverter.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/PortConverter.java @@ -17,6 +17,7 @@ private static PortBuilder convert(PortConfig port) { port.path.ifPresent(v -> b.withPath(v)); port.hostPort.ifPresent(v -> b.withHostPort(v)); port.containerPort.ifPresent(v -> b.withContainerPort(v)); + b.withProtocol(port.protocol); return b; } } diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesServiceMappingTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesServiceMappingTest.java index b92724bb86fe2..d316e93cfaeab 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesServiceMappingTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesServiceMappingTest.java @@ -2,7 +2,7 @@ package io.quarkus.it.kubernetes; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.file.Path; @@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.fabric8.kubernetes.api.model.ContainerPort; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.apps.Deployment; @@ -22,12 +23,14 @@ public class KubernetesServiceMappingTest { + private static final String APP_NAME = "kubernetes-service-mapping"; + @RegisterExtension static final QuarkusProdModeTest config = new QuarkusProdModeTest() .withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) - .setApplicationName("kubernetes-service-mapping") + .setApplicationName(APP_NAME) .setApplicationVersion("0.1-SNAPSHOT") - .withConfigurationResource("kubernetes-service-mapping.properties") + .withConfigurationResource(APP_NAME + ".properties") .setLogFileName("k8s.log") .setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion()))); @@ -51,7 +54,16 @@ public void assertGeneratedResources() throws IOException { assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getTemplate()).satisfies(t -> { assertThat(t.getSpec()).satisfies(podSpec -> { - + List ports = podSpec.getContainers().get(0).getPorts(); + assertThat(ports.size()).isEqualTo(2); + assertTrue(ports.stream().anyMatch(port -> "http".equals(port.getName()) + && port.getContainerPort() == 8080 + && "TCP".equals(port.getProtocol())), + () -> "http port not found in the pod containers!"); + assertTrue(ports.stream().anyMatch(port -> "debug".equals(port.getName()) + && port.getContainerPort() == 5005 + && "UDP".equals(port.getProtocol())), + () -> "debug port not found in the pod containers!"); }); }); }); @@ -62,10 +74,19 @@ public void assertGeneratedResources() throws IOException { assertThat(m.getName()).isEqualTo("kubernetes-service-mapping"); }); assertThat(s.getSpec()).satisfies(serviceSpec -> { - assertThat(serviceSpec.getPorts()).singleElement().satisfies(p -> { - assertEquals(8080, p.getTargetPort().getIntVal()); - assertEquals(8080, p.getPort()); - }); + assertThat(serviceSpec.getPorts().size()).isEqualTo(2); + assertTrue(serviceSpec.getPorts().stream().anyMatch(port -> "http".equals(port.getName()) + && port.getTargetPort().getIntVal() == 8080 + // Dekorate issue: https://github.com/dekorateio/dekorate/issues/1068 + // && "TCP".equals(port.getProtocol()) + && port.getPort() == 8080), + () -> "http port not found in the service!"); + assertTrue(serviceSpec.getPorts().stream().anyMatch(port -> "debug".equals(port.getName()) + && port.getTargetPort().getIntVal() == 5005 + // Dekorate issue: https://github.com/dekorateio/dekorate/issues/1068 + // && "UDP".equals(port.getProtocol()) + && port.getPort() == 5005), + () -> "debug port not found in the service!"); }); }); diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-service-mapping.properties b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-service-mapping.properties index af2fb047ef34e..856bf738bb7bb 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-service-mapping.properties +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-service-mapping.properties @@ -1,3 +1,7 @@ quarkus.kubernetes.ports.http.name=http quarkus.kubernetes.ports.http.host-port=8080 -quarkus.kubernetes.ports.http.container-port=8080 \ No newline at end of file +quarkus.kubernetes.ports.http.container-port=8080 +quarkus.kubernetes.ports.debug.name=debug +quarkus.kubernetes.ports.debug.host-port=5005 +quarkus.kubernetes.ports.debug.container-port=5005 +quarkus.kubernetes.ports.debug.protocol=UDP \ No newline at end of file