Skip to content

Commit 364066a

Browse files
committed
fix: tests
The new naming algorithm makes it impossible to use the default name for to identify a controller in application.yaml files because FQNs are interpreted as composite paths instead of single names. This makes things more cumbersome, imo.
1 parent 8bae9ab commit 364066a

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@
66

77
public interface ResourceController<R extends CustomResource> {
88

9-
static String getDefaultNameFor(ResourceController controller) {
10-
return getDefaultNameFor(controller.getClass());
11-
}
12-
13-
static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) {
14-
return getDefaultResourceControllerName(controllerClass.getCanonicalName());
15-
}
16-
17-
static String getDefaultResourceControllerName(String rcControllerClassName) {
18-
if (rcControllerClassName.indexOf('.') < 0) {
19-
throw new IllegalArgumentException(
20-
"Must provide a fully-qualified resource controller class name, was: "
21-
+ rcControllerClassName);
22-
}
23-
return rcControllerClassName.toLowerCase(Locale.ROOT);
24-
}
25-
269
/**
2710
* The implementation should delete the associated component(s). Note that this is method is
2811
* called when an object is marked for deletion. After its executed the custom resource finalizer
@@ -57,10 +40,12 @@ static String getDefaultResourceControllerName(String rcControllerClassName) {
5740
default void init(EventSourceManager eventSourceManager) {}
5841

5942
default String getName() {
60-
final var clazz = getClass();
43+
return getNameFor(this);
44+
}
6145

46+
static String getNameFor(Class<? extends ResourceController> controllerClass) {
6247
// if the controller annotation has a name attribute, use it
63-
final var annotation = clazz.getAnnotation(Controller.class);
48+
final var annotation = controllerClass.getAnnotation(Controller.class);
6449
if (annotation != null) {
6550
final var name = annotation.name();
6651
if (!Controller.NULL.equals(name)) {
@@ -69,6 +54,27 @@ default String getName() {
6954
}
7055

7156
// otherwise, use the lower-cased full class name
72-
return getDefaultNameFor(this);
57+
return getDefaultNameFor(controllerClass);
58+
}
59+
60+
static String getNameFor(ResourceController controller) {
61+
return getNameFor(controller.getClass());
62+
}
63+
64+
static String getDefaultNameFor(ResourceController controller) {
65+
return getDefaultNameFor(controller.getClass());
66+
}
67+
68+
static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) {
69+
return getDefaultResourceControllerName(controllerClass.getCanonicalName());
70+
}
71+
72+
static String getDefaultResourceControllerName(String rcControllerClassName) {
73+
if (rcControllerClassName.indexOf('.') < 0) {
74+
throw new IllegalArgumentException(
75+
"Must provide a fully-qualified resource controller class name, was: "
76+
+ rcControllerClassName);
77+
}
78+
return rcControllerClassName.toLowerCase(Locale.ROOT);
7379
}
7480
}

operator-framework-spring-boot-starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/AutoConfigurationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public void loadsKubernetesClientPropertiesProperly() {
3838
@Test
3939
public void loadsRetryPropertiesProperly() {
4040
final var retryProperties =
41-
config
42-
.getControllers()
43-
.get(ResourceController.getDefaultNameFor(TestController.class))
44-
.getRetry();
41+
config.getControllers().get(ResourceController.getNameFor(TestController.class)).getRetry();
4542
assertEquals(3, retryProperties.getMaxAttempts());
4643
assertEquals(1000, retryProperties.getInitialInterval());
4744
assertEquals(1.5, retryProperties.getIntervalMultiplier());

operator-framework-spring-boot-starter/src/test/java/io/javaoperatorsdk/operator/springboot/starter/TestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.springframework.stereotype.Component;
1010

1111
@Component
12-
@Controller(crdName = "name")
12+
@Controller(crdName = "name", name = "name_must_be_changed")
1313
public class TestController implements ResourceController {
1414

1515
@Override

operator-framework-spring-boot-starter/src/test/resources/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ javaoperatorsdk:
55
masterUrl: http://master.url
66

77
controllers:
8-
testcontroller:
8+
name_must_be_changed:
99
retry:
1010
maxAttempts: 3
1111
initialInterval: 1000

0 commit comments

Comments
 (0)