Skip to content

Commit 1ab58ea

Browse files
authored
Merge pull request #280 from java-operator-sdk/index-core-dependency
fix: properly index otherwise ignored dependency
2 parents 9e5cb13 + e3e3e2f commit 1ab58ea

File tree

9 files changed

+215
-17
lines changed

9 files changed

+215
-17
lines changed

operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
2222
import io.quarkus.deployment.builditem.FeatureBuildItem;
2323
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
24+
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
2425
import io.quarkus.gizmo.ClassCreator;
2526
import io.quarkus.gizmo.ClassOutput;
2627
import io.quarkus.gizmo.MethodCreator;
@@ -55,6 +56,12 @@ FeatureBuildItem feature() {
5556
return new FeatureBuildItem(FEATURE);
5657
}
5758

59+
@BuildStep
60+
void indexSDKDependencies(BuildProducer<IndexDependencyBuildItem> indexDependency) {
61+
indexDependency.produce(
62+
new IndexDependencyBuildItem("io.javaoperatorsdk", "operator-framework-core"));
63+
}
64+
5865
@BuildStep
5966
@Record(ExecutionTime.RUNTIME_INIT)
6067
void createConfigurationServiceAndOperator(
@@ -133,6 +140,13 @@ private ControllerConfiguration createControllerConfiguration(
133140

134141
// generate configuration
135142
final var controllerAnnotation = info.classAnnotation(CONTROLLER);
143+
if (controllerAnnotation == null) {
144+
throw new IllegalArgumentException(
145+
resourceControllerClassName
146+
+ " is missing the "
147+
+ Controller.class.getCanonicalName()
148+
+ " annotation");
149+
}
136150
final var crdName =
137151
valueOrDefault(
138152
controllerAnnotation, "crdName", AnnotationValue::asString, EXCEPTION_SUPPLIER);

operator-framework-quarkus-extension/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<modules>
2828
<module>deployment</module>
2929
<module>runtime</module>
30+
<module>tests</module>
3031
</modules>
3132
<dependencyManagement>
3233
<dependencies>
@@ -47,6 +48,10 @@
4748
<artifactId>maven-compiler-plugin</artifactId>
4849
<version>${compiler-plugin.version}</version>
4950
</plugin>
51+
<plugin>
52+
<artifactId>maven-surefire-plugin</artifactId>
53+
<version>${maven.surefire.version}</version>
54+
</plugin>
5055
</plugins>
5156
</pluginManagement>
5257
</build>

operator-framework-quarkus-extension/runtime/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<groupId>io.javaoperatorsdk</groupId>
1919
<artifactId>operator-framework-core</artifactId>
2020
<version>${project.version}</version>
21-
<scope>compile</scope>
2221
</dependency>
2322
<dependency>
2423
<groupId>io.quarkus</groupId>
@@ -78,16 +77,6 @@
7877
</annotationProcessorPaths>
7978
</configuration>
8079
</plugin>
81-
<plugin>
82-
<artifactId>maven-surefire-plugin</artifactId>
83-
<version>${maven.surefire.version}</version>
84-
<configuration>
85-
<systemPropertyVariables>
86-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
87-
<maven.home>${maven.home}</maven.home>
88-
</systemPropertyVariables>
89-
</configuration>
90-
</plugin>
9180
</plugins>
9281
</build>
9382
</project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>operator-framework-quarkus-extension-parent</artifactId>
7+
<groupId>io.javaoperatorsdk</groupId>
8+
<version>1.6.2-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>operator-framework-quarkus-tests</artifactId>
13+
<name>Operator SDK - Quarkus Extension - Tests</name>
14+
15+
16+
<properties>
17+
<maven.compiler.source>11</maven.compiler.source>
18+
<maven.compiler.target>11</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.javaoperatorsdk</groupId>
24+
<artifactId>operator-framework-quarkus-extension</artifactId>
25+
<version>${project.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>io.quarkus</groupId>
29+
<artifactId>quarkus-resteasy-jackson</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-junit5-internal</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.rest-assured</groupId>
38+
<artifactId>rest-assured</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.assertj</groupId>
43+
<artifactId>assertj-core</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<configuration>
54+
<parameters>true</parameters>
55+
</configuration>
56+
</plugin>
57+
<plugin>
58+
<groupId>io.quarkus</groupId>
59+
<artifactId>quarkus-maven-plugin</artifactId>
60+
<version>${quarkus.version}</version>
61+
<executions>
62+
<execution>
63+
<goals>
64+
<goal>build</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-surefire-plugin</artifactId>
72+
<configuration>
73+
<systemPropertyVariables>
74+
<java.util.logging.manager>
75+
org.jboss.logmanager.LogManager
76+
</java.util.logging.manager>
77+
<maven.home>${maven.home}</maven.home>
78+
</systemPropertyVariables>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.javaoperatorsdk.quarkus.it;
2+
3+
import io.javaoperatorsdk.operator.api.Context;
4+
import io.javaoperatorsdk.operator.api.Controller;
5+
import io.javaoperatorsdk.operator.api.DeleteControl;
6+
import io.javaoperatorsdk.operator.api.ResourceController;
7+
import io.javaoperatorsdk.operator.api.UpdateControl;
8+
9+
@Controller(crdName = TestController.CRD_NAME, name = TestController.NAME)
10+
public class TestController implements ResourceController<TestResource> {
11+
public static final String NAME = "test";
12+
public static final String CRD_NAME = "test.example.com";
13+
14+
@Override
15+
public DeleteControl deleteResource(TestResource resource, Context<TestResource> context) {
16+
return null;
17+
}
18+
19+
@Override
20+
public UpdateControl<TestResource> createOrUpdateResource(
21+
TestResource resource, Context<TestResource> context) {
22+
return null;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.javaoperatorsdk.quarkus.it;
2+
3+
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
4+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
5+
import javax.inject.Inject;
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.Path;
8+
import javax.ws.rs.PathParam;
9+
10+
@Path("/operator")
11+
public class TestOperatorApp {
12+
13+
@Inject TestController controller;
14+
@Inject ConfigurationService configurationService;
15+
16+
@GET
17+
@Path("{name}")
18+
// @Produces(MediaType.TEXT_PLAIN)
19+
public boolean getController(@PathParam("name") String name) {
20+
return name.equals(controller.getName());
21+
}
22+
23+
@GET
24+
@Path("{name}/config")
25+
public ControllerConfiguration getConfig(@PathParam("name") String name) {
26+
return getController(name) ? configurationService.getConfigurationFor(controller) : null;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.javaoperatorsdk.quarkus.it;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
5+
public class TestResource extends CustomResource {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.javaoperatorsdk.quarkus.it;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static org.hamcrest.Matchers.equalTo;
5+
import static org.hamcrest.Matchers.is;
6+
7+
import io.quarkus.test.QuarkusProdModeTest;
8+
import org.jboss.shrinkwrap.api.ShrinkWrap;
9+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
/**
14+
* This tests creates and starts an application accessed over REST to assess that injected values
15+
* are present and what we expect.
16+
*/
17+
public class QuarkusExtensionProcessorTest {
18+
19+
@RegisterExtension
20+
static final QuarkusProdModeTest config =
21+
new QuarkusProdModeTest()
22+
.setArchiveProducer(
23+
() ->
24+
ShrinkWrap.create(JavaArchive.class)
25+
.addClasses(TestOperatorApp.class, TestController.class, TestResource.class))
26+
.setApplicationName("basic-app")
27+
.setApplicationVersion("0.1-SNAPSHOT")
28+
.setRun(true);
29+
30+
@Test
31+
void controllerShouldExist() {
32+
// first check that we're not always returning true for any controller name :)
33+
given().when().get("/operator/does_not_exist").then().statusCode(200).body(is("false"));
34+
35+
// given the name of the TestController, the app should reply true meaning that it is indeed
36+
// injected
37+
given().when().get("/operator/" + TestController.NAME).then().statusCode(200).body(is("true"));
38+
}
39+
40+
@Test
41+
void configurationForControllerShouldExist() {
42+
// check that the config for the test controller can be retrieved and is conform to our
43+
// expectations
44+
final var resourceName = TestResource.class.getCanonicalName();
45+
given()
46+
.when()
47+
.get("/operator/" + TestController.NAME + "/config")
48+
.then()
49+
.statusCode(200)
50+
.body(
51+
"customResourceClass", equalTo(resourceName),
52+
"doneableClass", equalTo(resourceName + "Doneable"),
53+
"name", equalTo(TestController.NAME),
54+
"crdName", equalTo(TestController.CRD_NAME));
55+
}
56+
}

operator-framework-spring-boot-starter-test/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
</dependencyManagement>
3333

3434
<dependencies>
35-
<dependency>
36-
<groupId>io.fabric8</groupId>
37-
<artifactId>kubernetes-server-mock</artifactId>
38-
<version>4.12.0</version>
39-
</dependency>
40-
4135
<dependency>
4236
<groupId>org.springframework.boot</groupId>
4337
<artifactId>spring-boot-starter</artifactId>

0 commit comments

Comments
 (0)