1515 */
1616@ SuppressWarnings ("rawtypes" )
1717public class AbstractConfigurationService implements ConfigurationService {
18- private final Map <String , ControllerConfiguration > configurations = new ConcurrentHashMap <>();
18+ private final Map <String , Configured > configurations = new ConcurrentHashMap <>();
1919 private final Version version ;
2020 private KubernetesClient client ;
2121 private Cloner cloner ;
@@ -88,12 +88,14 @@ private <R extends HasMetadata> void put(
8888 ControllerConfiguration <R > config , boolean failIfExisting ) {
8989 final var name = config .getName ();
9090 if (failIfExisting ) {
91- final var existing = configurations . get (name );
91+ final var existing = getFor (name );
9292 if (existing != null ) {
9393 throwExceptionOnNameCollision (config .getAssociatedReconcilerClassName (), existing );
9494 }
9595 }
96- configurations .put (name , config );
96+ // record the configuration but mark is as un-configured in case a reconciler wants to override
97+ // the configuration when registering
98+ configurations .put (name , new Configured (false , config ));
9799 }
98100
99101 protected <R extends HasMetadata > void throwExceptionOnNameCollision (
@@ -112,22 +114,32 @@ protected <R extends HasMetadata> void throwExceptionOnNameCollision(
112114 public <R extends HasMetadata > ControllerConfiguration <R > getConfigurationFor (
113115 Reconciler <R > reconciler ) {
114116 final var key = keyFor (reconciler );
115- var configuration = configurations .get (key );
116- if (configuration == null ) {
117+ var configured = configurations .get (key );
118+ if (configured == null ) {
117119 logMissingReconcilerWarning (key , getReconcilersNameMessage ());
118- } else {
119- // if a reconciler is also a ConfigurableReconciler, update and replace its configuration
120+ return null ;
121+ }
122+
123+ var config = configured .config ;
124+ // if a reconciler is also a ConfigurableReconciler, update and replace its configuration if it
125+ // hasn't already been configured
126+ if (!configured .configured ) {
120127 if (reconciler instanceof ConfigurableReconciler <?> configurableReconciler ) {
121- final var overrider = ControllerConfigurationOverrider .override (configuration );
128+
129+ final var overrider = ControllerConfigurationOverrider .override (config );
122130 configurableReconciler .updateConfigurationFrom (overrider );
123- configuration = overrider .build ();
124- configurations .put (key , configuration );
131+ config = overrider .build ();
125132 }
133+ // mark the reconciler as configured so that we don't attempt to do so again next time the
134+ // configuration is requested
135+ configurations .put (key , new Configured (true , config ));
126136 }
127137
128- return configuration ;
138+ return config ;
129139 }
130140
141+ private record Configured (boolean configured , ControllerConfiguration config ) {}
142+
131143 protected void logMissingReconcilerWarning (String reconcilerKey , String reconcilersNameMessage ) {
132144 log .warn ("Cannot find reconciler named '{}'. {}" , reconcilerKey , reconcilersNameMessage );
133145 }
@@ -142,14 +154,14 @@ protected <R extends HasMetadata> String keyFor(Reconciler<R> reconciler) {
142154 return ReconcilerUtils .getNameFor (reconciler );
143155 }
144156
145- @ SuppressWarnings ("unused" )
146157 protected ControllerConfiguration getFor (String reconcilerName ) {
147- return configurations .get (reconcilerName );
158+ final var configured = configurations .get (reconcilerName );
159+ return configured != null ? configured .config : null ;
148160 }
149161
150162 @ SuppressWarnings ("unused" )
151163 protected Stream <ControllerConfiguration > controllerConfigurations () {
152- return configurations .values ().stream ();
164+ return configurations .values ().stream (). map ( Configured :: config ) ;
153165 }
154166
155167 @ Override
0 commit comments