forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override target port used when creating openshift route
- Loading branch information
Alasdair Preston
committed
Sep 14, 2022
1 parent
b60ad38
commit 71ae072
Showing
7 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...loyment/src/main/java/io/quarkus/kubernetes/deployment/ApplyRouteTargetPortDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.dekorate.kubernetes.decorator.NamedResourceDecorator; | ||
import io.fabric8.kubernetes.api.model.IntOrString; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.openshift.api.model.RoutePort; | ||
import io.fabric8.openshift.api.model.RouteSpecFluent; | ||
|
||
public class ApplyRouteTargetPortDecorator extends NamedResourceDecorator<RouteSpecFluent<?>> { | ||
|
||
private IntOrString targetPort; | ||
|
||
public ApplyRouteTargetPortDecorator(Integer port) { | ||
super(ANY); | ||
targetPort = new IntOrString(port); | ||
} | ||
|
||
public ApplyRouteTargetPortDecorator(String port) { | ||
super(ANY); | ||
targetPort = new IntOrString(port); | ||
} | ||
|
||
@Override | ||
public void andThenVisit(RouteSpecFluent routeSpecFluent, ObjectMeta objectMeta) { | ||
routeSpecFluent.withPort(new RoutePort(targetPort)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...test/java/io/quarkus/it/kubernetes/OpenshiftWithRoutePropertiesCustomServicePortTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
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.Service; | ||
import io.fabric8.openshift.api.model.Route; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class OpenshiftWithRoutePropertiesCustomServicePortTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName("openshift") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("openshift-with-route-custom-service-port.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(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { | ||
assertThat(h).isInstanceOfSatisfying(Service.class, s -> { | ||
assertThat(s.getMetadata()).satisfies(m -> { | ||
assertThat(m.getNamespace()).isEqualTo("applications"); | ||
}); | ||
|
||
assertThat(s.getSpec()).satisfies(spec -> { | ||
assertThat(spec.getSelector()).contains(entry("app.kubernetes.io/name", "test-it")); | ||
assertThat(spec.getPorts()).hasSize(1).singleElement().satisfies(p -> { | ||
assertThat(p.getPort()).isEqualTo(80); | ||
assertThat(p.getTargetPort().getIntVal()).isEqualTo(9090); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
assertThat(openshiftList).filteredOn(i -> "Route".equals(i.getKind())).singleElement().satisfies(i -> { | ||
assertThat(i).isInstanceOfSatisfying(Route.class, r -> { | ||
//Check that labels and annotations are also applied to Routes (#10260) | ||
assertThat(r.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo("test-it"); | ||
assertThat(m.getLabels()).contains(entry("foo", "bar")); | ||
assertThat(m.getAnnotations()).contains(entry("bar", "baz")); | ||
assertThat(m.getAnnotations()).contains(entry("kubernetes.io/tls-acme", "true")); | ||
assertThat(m.getNamespace()).isEqualTo("applications"); | ||
}); | ||
assertThat(r.getSpec().getPort().getTargetPort().getStrVal()).isEqualTo("my-port"); | ||
assertThat(r.getSpec().getHost()).isEqualTo("foo.bar.io"); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...arkus-standard-way/src/test/resources/openshift-with-route-custom-service-port.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
quarkus.http.port=9090 | ||
quarkus.kubernetes.deployment-target=openshift | ||
quarkus.openshift.name=test-it | ||
quarkus.openshift.namespace=applications | ||
quarkus.openshift.labels.foo=bar | ||
quarkus.openshift.annotations.bar=baz | ||
quarkus.openshift.group=grp | ||
|
||
quarkus.openshift.route.expose=true | ||
quarkus.openshift.route.host=foo.bar.io | ||
quarkus.openshift.route.annotations."kubernetes.io/tls-acme"=true | ||
quarkus.openshift.route-target-port=my-port | ||
|
||
quarkus.s2i.registry=quay.io |