Skip to content

Commit

Permalink
Merge pull request #29120 from Sgitario/route_named_port
Browse files Browse the repository at this point in the history
Allow to configure target port in OpenShift routes
  • Loading branch information
iocanel authored Nov 9, 2022
2 parents 6ba114c + bf99b15 commit 97f6616
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public void visit(OpenshiftConfigFluent config) {
routeBuilder.withHost(routeConfig.host.get());
}

if (routeConfig.targetPort.isPresent()) {
routeBuilder.withTargetPort(routeConfig.targetPort.get());
}

routeBuilder.endRoute();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class RouteConfig {
@ConfigItem
Optional<String> host;

/**
* The target named port. If not provided, it will be deducted from the Service resource ports.
*/
@ConfigItem
Optional<String> targetPort;

/**
* Custom annotations to add to exposition (route or ingress) resources
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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.openshift.api.model.Route;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;

public class OpenshiftWithRouteTargetPortTest {

private static final String APP_NAME = "openshift-with-route-target-port";

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class))
.setApplicationName(APP_NAME)
.setApplicationVersion("0.1-SNAPSHOT")
.withConfigurationResource(APP_NAME + ".properties");

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir)
.isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json"))
.isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
List<HasMetadata> openshiftList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("openshift.yml"));

assertThat(openshiftList).filteredOn(i -> "Route".equals(i.getKind())).singleElement().satisfies(i -> {
assertThat(i).isInstanceOfSatisfying(Route.class, r -> {
assertThat(r.getSpec().getPort().getTargetPort().getStrVal()).isEqualTo("my-port");
assertThat(r.getSpec().getHost()).isEqualTo("foo.bar.io");
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkus.kubernetes.deployment-target=openshift
quarkus.openshift.route.expose=true
quarkus.openshift.route.host=foo.bar.io
quarkus.openshift.route.target-port=my-port

0 comments on commit 97f6616

Please sign in to comment.