Skip to content

Commit 1caf94a

Browse files
authored
fix: ExposedApp tests should now properly run (#572)
Get things ready to run in native mode as well, now building samples natively.
1 parent 8db46ce commit 1caf94a

File tree

12 files changed

+126
-73
lines changed

12 files changed

+126
-73
lines changed

.github/workflows/build-for-quarkus-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: mvn -B formatter:validate install --file pom.xml
4545

4646
- name: Build with Maven (Native)
47-
run: mvn -B formatter:validate install -Dnative --file pom.xml
47+
run: mvn -B formatter:validate install -Dnative --file pom.xml -pl '!docs'
4848

4949
- name: Kubernetes KinD Cluster
5050
uses: container-tools/kind-action@v2

core/runtime/src/main/java/io/quarkiverse/operatorsdk/runtime/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Version loadFromProperties() {
6363
log.warnf("Couldn't load extension version information: {0}", e.getMessage());
6464
}
6565
} else {
66-
log.warn("Couldn't find version.properties file. Default version information will be used.");
66+
log.warn("Couldn't find extension-version.properties file. Default version information will be used.");
6767
}
6868

6969
Date builtTime;

pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,53 @@
8585
<module>samples</module>
8686
</modules>
8787
</profile>
88+
<profile>
89+
<id>native-image</id>
90+
<activation>
91+
<property>
92+
<name>native</name>
93+
</property>
94+
</activation>
95+
<build>
96+
<plugins>
97+
<plugin>
98+
<artifactId>maven-surefire-plugin</artifactId>
99+
<configuration>
100+
<skipTests>${native.surefire.skip}</skipTests>
101+
<systemPropertyVariables>
102+
<java.util.logging.manager>org.jboss.logmanager.LogManager
103+
</java.util.logging.manager>
104+
<maven.home>${maven.home}</maven.home>
105+
</systemPropertyVariables>
106+
</configuration>
107+
</plugin>
108+
<plugin>
109+
<artifactId>maven-failsafe-plugin</artifactId>
110+
<executions>
111+
<execution>
112+
<goals>
113+
<goal>integration-test</goal>
114+
<goal>verify</goal>
115+
</goals>
116+
<configuration>
117+
<systemPropertyVariables>
118+
<native.image.path>
119+
${project.build.directory}/${project.build.finalName}-runner
120+
</native.image.path>
121+
<java.util.logging.manager>org.jboss.logmanager.LogManager
122+
</java.util.logging.manager>
123+
<maven.home>${maven.home}</maven.home>
124+
</systemPropertyVariables>
125+
</configuration>
126+
</execution>
127+
</executions>
128+
</plugin>
129+
</plugins>
130+
</build>
131+
<properties>
132+
<quarkus.package.type>native</quarkus.package.type>
133+
<skipDocs>true</skipDocs>
134+
</properties>
135+
</profile>
88136
</profiles>
89137
</project>

samples/exposedapp/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,4 @@
7575
</plugin>
7676
</plugins>
7777
</build>
78-
79-
<profiles>
80-
<profile>
81-
<id>native</id>
82-
<properties>
83-
<quarkus.package.type>native</quarkus.package.type>
84-
</properties>
85-
</profile>
86-
</profiles>
8778
</project>

samples/exposedapp/src/main/java/io/halkyon/ExposedAppReconciler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public UpdateControl<ExposedApp> reconcile(ExposedApp exposedApp, Context<Expose
4848
if (wrs.allDependentResourcesReady()) {
4949
final var url = IngressDependent.getExposedURL(
5050
context.getSecondaryResource(Ingress.class).orElseThrow());
51-
log.info("App {} is exposed and ready to be used at {}", name, url);
52-
exposedApp.setStatus(new ExposedAppStatus(url));
51+
exposedApp.setStatus(new ExposedAppStatus(url, exposedApp.getSpec().getEndpoint()));
52+
log.info("App {} is exposed and ready to be used at {}", name, exposedApp.getStatus().getHost());
5353
return UpdateControl.updateStatus(exposedApp);
5454
} else {
55-
final var duration = Duration.ofSeconds(5);
55+
final var duration = Duration.ofSeconds(1);
5656
log.info("App {} is not ready yet, rescheduling reconciliation after {}s", name, duration.toSeconds());
5757
return UpdateControl.<ExposedApp> noUpdate().rescheduleAfter(duration);
5858
}

samples/exposedapp/src/main/java/io/halkyon/ExposedAppSpec.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ public class ExposedAppSpec {
99
private String imageRef;
1010
private Map<String, String> env;
1111

12+
private String endpoint;
13+
14+
public String getEndpoint() {
15+
return endpoint;
16+
}
17+
18+
public void setEndpoint(String endpoint) {
19+
this.endpoint = endpoint;
20+
}
21+
1222
public String getImageRef() {
1323
return imageRef;
1424
}

samples/exposedapp/src/main/java/io/halkyon/ExposedAppStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public ExposedAppStatus() {
1313
message = "processing";
1414
}
1515

16-
public ExposedAppStatus(String hostname) {
16+
public ExposedAppStatus(String hostname, String endpoint) {
1717
this.message = "exposed";
18-
this.host = hostname;
18+
this.host = endpoint != null && !endpoint.isBlank() ? hostname + '/' + endpoint : hostname;
1919
ready = true;
2020
waitTime = System.currentTimeMillis() - waitTime;
2121
}

samples/exposedapp/src/main/java/io/halkyon/IngressDependent.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,41 @@
55

66
import java.util.Map;
77

8+
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
89
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
910
import io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder;
1011
import io.javaoperatorsdk.operator.api.reconciler.Context;
1112
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
13+
import io.javaoperatorsdk.operator.processing.dependent.Matcher;
1214
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;
15+
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesResourceMatcher;
16+
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceUpdatePreProcessor;
1317
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
1418

1519
public class IngressDependent extends CRUDKubernetesDependentResource<Ingress, ExposedApp> implements
16-
Condition<Ingress, ExposedApp> {
20+
Condition<Ingress, ExposedApp>, Matcher<Ingress, ExposedApp>, ResourceUpdatePreProcessor<Ingress> {
1721

1822
public IngressDependent() {
1923
super(Ingress.class);
2024
}
2125

26+
@Override
27+
public Result<Ingress> match(Ingress actualResource, ExposedApp primary,
28+
Context<ExposedApp> context) {
29+
return GenericKubernetesResourceMatcher.match(this, actualResource, primary, context, true);
30+
}
31+
2232
@Override
2333
@SuppressWarnings("unchecked")
2434
public Ingress desired(ExposedApp exposedApp, Context context) {
2535
final var labels = (Map<String, String>) context.managedDependentResourceContext()
2636
.getMandatory(LABELS_CONTEXT_KEY, Map.class);
2737
final var metadata = createMetadata(exposedApp, labels);
28-
metadata.setAnnotations(Map.of(
29-
"nginx.ingress.kubernetes.io/rewrite-target", "/",
30-
"kubernetes.io/ingress.class", "nginx"));
31-
38+
/*
39+
* metadata.setAnnotations(Map.of(
40+
* "nginx.ingress.kubernetes.io/rewrite-target", "/",
41+
* "kubernetes.io/ingress.class", "nginx"));
42+
*/
3243
return new IngressBuilder()
3344
.withMetadata(metadata)
3445
.withNewSpec()
@@ -77,4 +88,12 @@ public boolean isMet(DependentResource<Ingress, ExposedApp> dependentResource,
7788
return false;
7889
}).orElse(false);
7990
}
91+
92+
@Override
93+
public Ingress replaceSpecOnActual(Ingress actual, Ingress desired, Context<?> context) {
94+
final var metadata = new ObjectMetaBuilder(desired.getMetadata()).build();
95+
actual.setMetadata(metadata);
96+
actual.setSpec(desired.getSpec());
97+
return actual;
98+
}
8099
}

samples/exposedapp/src/main/resources/app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ kind: ExposedApp
33
metadata:
44
name: hello-quarkus
55
spec:
6-
imageRef: 'claprun/hello:1.0.0-SNAPSHOT'
6+
imageRef: 'quay.io/metacosm/hello:1.0.0-SNAPSHOT'

samples/exposedapp/src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
# set to true to automatically apply CRDs to the cluster when they get regenerated
55
quarkus.operator-sdk.crd.apply=true
66
quarkus.kubernetes-client.devservices.override-kubeconfig=true
7-
%test.quarkus.operator-sdk.close-client-on-stop=false
7+
%test.quarkus.operator-sdk.close-client-on-stop=false
8+
%test.quarkus.operator-sdk.start-operator=true
9+
quarkus.kubernetes-client.devservices.flavor=k3s

0 commit comments

Comments
 (0)