|
8 | 8 | import io.javaoperatorsdk.operator.api.config.ResolvedControllerConfiguration;
|
9 | 9 | import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
|
10 | 10 | import io.javaoperatorsdk.operator.processing.Controller;
|
11 |
| -import io.javaoperatorsdk.operator.sample.simple.DuplicateCRController; |
12 | 11 | import io.javaoperatorsdk.operator.sample.simple.TestCustomReconciler;
|
13 |
| -import io.javaoperatorsdk.operator.sample.simple.TestCustomReconcilerOtherV1; |
14 | 12 | import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
|
15 |
| -import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceOtherV1; |
16 | 13 |
|
| 14 | +import static io.javaoperatorsdk.operator.ControllerManager.CANNOT_REGISTER_MULTIPLE_CONTROLLERS_WITH_SAME_NAME_MESSAGE; |
17 | 15 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
18 | 16 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
19 | 17 |
|
20 | 18 | class ControllerManagerTest {
|
21 | 19 |
|
22 | 20 | @Test
|
23 |
| - void shouldNotAddMultipleControllersForSameCustomResource() { |
24 |
| - final var registered = new TestControllerConfiguration<>(new TestCustomReconciler(null), |
25 |
| - TestCustomResource.class); |
26 |
| - final var duplicated = |
27 |
| - new TestControllerConfiguration<>(new DuplicateCRController(), TestCustomResource.class); |
28 |
| - |
29 |
| - checkException(registered, duplicated); |
30 |
| - } |
31 |
| - |
32 |
| - @Test |
33 |
| - void addingMultipleControllersForCustomResourcesWithSameVersionsShouldNotWork() { |
34 |
| - final var registered = new TestControllerConfiguration<>(new TestCustomReconciler(null), |
35 |
| - TestCustomResource.class); |
36 |
| - final var duplicated = new TestControllerConfiguration<>(new TestCustomReconcilerOtherV1(), |
37 |
| - TestCustomResourceOtherV1.class); |
38 |
| - |
39 |
| - checkException(registered, duplicated); |
40 |
| - } |
41 |
| - |
42 |
| - private <T extends HasMetadata, U extends HasMetadata> void checkException( |
43 |
| - TestControllerConfiguration<T> registered, |
44 |
| - TestControllerConfiguration<U> duplicated) { |
45 |
| - |
| 21 | + void addingReconcilerWithSameNameShouldNotWork() { |
| 22 | + final var controllerConfiguration = |
| 23 | + new TestControllerConfiguration<>(new TestCustomReconciler(null), |
| 24 | + TestCustomResource.class); |
| 25 | + var controller = new Controller<>(controllerConfiguration.reconciler, controllerConfiguration, |
| 26 | + MockKubernetesClient.client(controllerConfiguration.getResourceClass())); |
46 | 27 | ConfigurationService configurationService = new BaseConfigurationService();
|
| 28 | + final var controllerManager = |
| 29 | + new ControllerManager(configurationService.getExecutorServiceManager()); |
| 30 | + controllerManager.add(controller); |
47 | 31 |
|
48 |
| - final var exception = assertThrows(OperatorException.class, () -> { |
49 |
| - final var controllerManager = |
50 |
| - new ControllerManager(configurationService.getExecutorServiceManager()); |
51 |
| - controllerManager.add(new Controller<>(registered.controller, registered, |
52 |
| - MockKubernetesClient.client(registered.getResourceClass()))); |
53 |
| - controllerManager.add(new Controller<>(duplicated.controller, duplicated, |
54 |
| - MockKubernetesClient.client(duplicated.getResourceClass()))); |
| 32 | + var ex = assertThrows(OperatorException.class, () -> { |
| 33 | + controllerManager.add(controller); |
55 | 34 | });
|
56 |
| - final var msg = exception.getMessage(); |
57 | 35 | assertTrue(
|
58 |
| - msg.contains("Cannot register controller '" + duplicated.getName() + "'") |
59 |
| - && msg.contains(registered.getName()) |
60 |
| - && msg.contains(registered.getResourceTypeName())); |
| 36 | + ex.getMessage().contains(CANNOT_REGISTER_MULTIPLE_CONTROLLERS_WITH_SAME_NAME_MESSAGE)); |
61 | 37 | }
|
62 | 38 |
|
63 | 39 | private static class TestControllerConfiguration<R extends HasMetadata>
|
64 | 40 | extends ResolvedControllerConfiguration<R> {
|
65 |
| - private final Reconciler<R> controller; |
| 41 | + private final Reconciler<R> reconciler; |
66 | 42 |
|
67 |
| - public TestControllerConfiguration(Reconciler<R> controller, Class<R> crClass) { |
68 |
| - super(crClass, getControllerName(controller), controller.getClass(), |
| 43 | + public TestControllerConfiguration(Reconciler<R> reconciler, Class<R> crClass) { |
| 44 | + super(crClass, getControllerName(reconciler), reconciler.getClass(), |
69 | 45 | new BaseConfigurationService());
|
70 |
| - this.controller = controller; |
| 46 | + this.reconciler = reconciler; |
71 | 47 | }
|
72 | 48 |
|
73 | 49 | static <R extends HasMetadata> String getControllerName(
|
|
0 commit comments