Skip to content

Commit

Permalink
Merge pull request #28310 from Sgitario/fix_kubernetes_protocol
Browse files Browse the repository at this point in the history
Not to ignore the property `quarkus.kubernetes.ports.<name>.protocol`
  • Loading branch information
Sgitario authored Oct 4, 2022
2 parents 28b0d97 + 7b9a896 commit edbdf1a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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())));

Expand All @@ -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<ContainerPort> 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!");
});
});
});
Expand All @@ -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!");
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
quarkus.kubernetes.ports.http.name=http
quarkus.kubernetes.ports.http.host-port=8080
quarkus.kubernetes.ports.http.container-port=8080
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

0 comments on commit edbdf1a

Please sign in to comment.