-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populate ingress fields (annotations and rules) for kind and minikube resources #43580
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
97 changes: 97 additions & 0 deletions
97
...uarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithKindIngress.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,97 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.networking.v1.Ingress; | ||
import io.fabric8.kubernetes.api.model.networking.v1.IngressRule; | ||
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 KubernetesWithKindIngress { | ||
|
||
private static final String LOCALHOST = "localhost"; | ||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName("kind-ingress") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.setLogFileName("k8s.log") | ||
// Configuration provided by issue: https://github.com/quarkusio/quarkus/issues/42294 | ||
.overrideConfigKey("quarkus.kubernetes.ingress.expose", "true") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.annotations.\"nginx.ingress.kubernetes.io/rewrite-target\"", "/$2") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.host", LOCALHOST) | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.path", "/game(/|$)(.*)") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.path-type", "ImplementationSpecific") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.ingress-class-name", "Nginx") | ||
.setForcedDependencies(Arrays.asList( | ||
Dependency.of("io.quarkus", "quarkus-kind", Version.getVersion()), | ||
Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion()))); | ||
private static final Logger log = LoggerFactory.getLogger(KubernetesWithKindIngress.class); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
void shouldCreateKindResourcesWithIngressAnnotationsCorrectly() throws IOException { | ||
final Path kubernetesFile = prodModeTestResults.getBuildDir().resolve("kubernetes").resolve("kind.yml"); | ||
List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesFile); | ||
|
||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(kubernetesList).filteredOn(k -> k.getKind().equals("Ingress")) | ||
.singleElement().isInstanceOfSatisfying(Ingress.class, ingress -> { | ||
|
||
softly.assertThat(ingress.getMetadata().getAnnotations()) | ||
.anySatisfy((key, value) -> { | ||
assertThat(key).isEqualTo("nginx.ingress.kubernetes.io/rewrite-target"); | ||
assertThat(value).isEqualTo("/$2"); | ||
}); | ||
|
||
softly.assertThat(ingress.getSpec()).satisfies(spec -> { | ||
|
||
softly.assertThat(spec.getIngressClassName()).isEqualTo("Nginx"); | ||
|
||
softly.assertThat(spec.getRules()).hasSize(2); | ||
|
||
softly.assertThat(spec.getRules()).filteredOn(byLocalhost()) | ||
.singleElement() | ||
.satisfies(rule -> { | ||
|
||
softly.assertThat(rule.getHttp().getPaths()).hasSize(1); | ||
softly.assertThat(rule.getHttp().getPaths().get(0)).satisfies(path -> { | ||
|
||
softly.assertThat(path.getPathType()).isEqualTo("ImplementationSpecific"); | ||
softly.assertThat(path.getPath()).isEqualTo("/game(/|$)(.*)"); | ||
softly.assertThat(path.getBackend().getService().getPort().getName()) | ||
.isEqualTo("http"); | ||
softly.assertThat(path.getBackend().getService().getName()) | ||
.isEqualTo("kind-ingress"); | ||
|
||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private static Predicate<IngressRule> byLocalhost() { | ||
return rule -> rule.getHost() != null && rule.getHost().equals(LOCALHOST); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...us-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithMinikubeIngress.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,94 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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.networking.v1.Ingress; | ||
import io.fabric8.kubernetes.api.model.networking.v1.IngressRule; | ||
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 KubernetesWithMinikubeIngress { | ||
|
||
private static final String LOCALHOST = "localhost"; | ||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName("kind-ingress") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.setLogFileName("k8s.log") | ||
// Configuration provided by issue: https://github.com/quarkusio/quarkus/issues/42294 | ||
.overrideConfigKey("quarkus.kubernetes.ingress.expose", "true") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.annotations.\"nginx.ingress.kubernetes.io/rewrite-target\"", "/$2") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.host", LOCALHOST) | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.path", "/game(/|$)(.*)") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.rules.1.path-type", "ImplementationSpecific") | ||
.overrideConfigKey("quarkus.kubernetes.ingress.ingress-class-name", "Nginx") | ||
.setForcedDependencies(Arrays.asList( | ||
Dependency.of("io.quarkus", "quarkus-minikube", Version.getVersion()), | ||
Dependency.of("io.quarkus", "quarkus-kubernetes", Version.getVersion()))); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
void shouldCreateKindResourcesWithIngressAnnotationsCorrectly() throws IOException { | ||
final Path kubernetesFile = prodModeTestResults.getBuildDir().resolve("kubernetes").resolve("minikube.yml"); | ||
List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesFile); | ||
|
||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(kubernetesList).filteredOn(k -> k.getKind().equals("Ingress")) | ||
.singleElement().isInstanceOfSatisfying(Ingress.class, ingress -> { | ||
|
||
softly.assertThat(ingress.getMetadata().getAnnotations()) | ||
.anySatisfy((key, value) -> { | ||
assertThat(key).isEqualTo("nginx.ingress.kubernetes.io/rewrite-target"); | ||
assertThat(value).isEqualTo("/$2"); | ||
}); | ||
|
||
softly.assertThat(ingress.getSpec()).satisfies(spec -> { | ||
|
||
softly.assertThat(spec.getIngressClassName()).isEqualTo("Nginx"); | ||
|
||
softly.assertThat(spec.getRules()).hasSize(2); | ||
|
||
softly.assertThat(spec.getRules()).filteredOn(byLocalhost()) | ||
.singleElement() | ||
.satisfies(rule -> { | ||
|
||
softly.assertThat(rule.getHttp().getPaths()).hasSize(1); | ||
softly.assertThat(rule.getHttp().getPaths().get(0)).satisfies(path -> { | ||
|
||
softly.assertThat(path.getPathType()).isEqualTo("ImplementationSpecific"); | ||
softly.assertThat(path.getPath()).isEqualTo("/game(/|$)(.*)"); | ||
softly.assertThat(path.getBackend().getService().getPort().getName()) | ||
.isEqualTo("http"); | ||
softly.assertThat(path.getBackend().getService().getName()) | ||
.isEqualTo("kind-ingress"); | ||
|
||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private static Predicate<IngressRule> byLocalhost() { | ||
return rule -> rule.getHost() != null && rule.getHost().equals(LOCALHOST); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also doing more than just dealing with the annotations since it also adds ingress rules (which is fine, by the way, at least in my opinion)