Skip to content

Commit b46805c

Browse files
committed
fix: multiple versions should actually not be supported
See #94
1 parent 7f87c44 commit b46805c

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.net.ConnectException;
44
import java.util.ArrayList;
5-
import java.util.Collections;
65
import java.util.HashMap;
76
import java.util.List;
87
import java.util.Map;
@@ -168,10 +167,6 @@ static class ControllerManager implements LifecycleAware {
168167
private final Map<String, ConfiguredController> controllers = new HashMap<>();
169168
private boolean started = false;
170169

171-
synchronized Map<String, ConfiguredController> getControllers() {
172-
return Collections.unmodifiableMap(controllers);
173-
}
174-
175170
public synchronized void shouldStart() {
176171
if (started) {
177172
return;
@@ -202,15 +197,13 @@ public synchronized void stop() {
202197
public synchronized void add(ConfiguredController configuredController) {
203198
final var configuration = configuredController.getConfiguration();
204199
final var crdName = configuration.getCRDName();
205-
final var version = configuration.getCustomResourceVersion();
206-
final var key = crdName + "/" + version;
207-
final var existing = controllers.get(key);
200+
final var existing = controllers.get(crdName);
208201
if (existing != null) {
209202
throw new OperatorException("Cannot register controller '" + configuration.getName()
210-
+ "': another controller (" + existing.getConfiguration().getName()
211-
+ ") is already registered for CRD '" + crdName + "' (version: " + version + ")");
203+
+ "': another controller named '" + existing.getConfiguration().getName()
204+
+ "' is already registered for CRD '" + crdName + "'");
212205
}
213-
this.controllers.put(key, configuredController);
206+
this.controllers.put(crdName, configuredController);
214207
if (started) {
215208
configuredController.start();
216209
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ default String getName() {
2020
default String getCRDName() {
2121
return CustomResource.getCRDName(getCustomResourceClass());
2222
}
23-
24-
default String getCustomResourceVersion() {
25-
return HasMetadata.getVersion(getCustomResourceClass());
26-
}
27-
23+
2824
default String getFinalizer() {
2925
return ControllerUtils.getDefaultFinalizerName(getCRDName());
3026
}

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerManagerTest.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceControllerV2;
1414
import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceV2;
1515

16-
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
1816
public class ControllerManagerTest {
1917

2018
@Test(expected = OperatorException.class)
@@ -27,17 +25,15 @@ public void shouldNotAddMultipleControllersForSameCustomResource() {
2725
config(TestCustomResource.class), null));
2826
}
2927

30-
@Test
31-
public void addingMultipleControllersForCustomResourcesWithDifferentVersionsShouldWork() {
28+
@Test(expected = OperatorException.class)
29+
public void addingMultipleControllersForCustomResourcesWithDifferentVersionsShouldNotWork() {
3230
final var controllerManager = new ControllerManager();
3331
controllerManager
3432
.add(new ConfiguredController<>(new TestCustomResourceController(null),
3533
config(TestCustomResource.class), null));
3634
controllerManager
3735
.add(new ConfiguredController<>(new TestCustomResourceControllerV2(), config(
3836
TestCustomResourceV2.class), null));
39-
final var controllers = controllerManager.getControllers();
40-
assertEquals(2, controllers.size());
4137
}
4238

4339
private <R extends CustomResource<?, ?>> ControllerConfiguration<R> config(Class<R> crClass) {

0 commit comments

Comments
 (0)