66import java .util .Map ;
77import java .util .Set ;
88import java .util .concurrent .ConcurrentHashMap ;
9+ import java .util .stream .Stream ;
910
1011public abstract class AbstractConfigurationService implements ConfigurationService {
1112
@@ -17,10 +18,21 @@ public AbstractConfigurationService(Version version) {
1718 }
1819
1920 protected <R extends CustomResource > void register (ControllerConfiguration <R > config ) {
21+ put (config , true );
22+ }
23+
24+ protected <R extends CustomResource > void replace (ControllerConfiguration <R > config ) {
25+ put (config , false );
26+ }
27+
28+ private <R extends CustomResource > void put (
29+ ControllerConfiguration <R > config , boolean failIfExisting ) {
2030 final var name = config .getName ();
21- final var existing = configurations .get (name );
22- if (existing != null ) {
23- throwExceptionOnNameCollision (config .getAssociatedControllerClassName (), existing );
31+ if (failIfExisting ) {
32+ final var existing = configurations .get (name );
33+ if (existing != null ) {
34+ throwExceptionOnNameCollision (config .getAssociatedControllerClassName (), existing );
35+ }
2436 }
2537 configurations .put (name , config );
2638 }
@@ -39,7 +51,19 @@ protected void throwExceptionOnNameCollision(
3951 @ Override
4052 public <R extends CustomResource > ControllerConfiguration <R > getConfigurationFor (
4153 ResourceController <R > controller ) {
42- return configurations .get (ControllerUtils .getNameFor (controller ));
54+ return configurations .get (keyFor (controller ));
55+ }
56+
57+ protected String keyFor (ResourceController controller ) {
58+ return ControllerUtils .getNameFor (controller );
59+ }
60+
61+ protected ControllerConfiguration getFor (String controllerName ) {
62+ return configurations .get (controllerName );
63+ }
64+
65+ protected Stream <ControllerConfiguration > controllerConfigurations () {
66+ return configurations .values ().stream ();
4367 }
4468
4569 @ Override
0 commit comments