5858import edu .umd .cs .findbugs .annotations .NonNull ;
5959import edu .umd .cs .findbugs .annotations .Nullable ;
6060
61+ import static io .kroxylicious .kubernetes .operator .ResourcesUtil .generation ;
62+ import static io .kroxylicious .kubernetes .operator .ResourcesUtil .name ;
63+ import static io .kroxylicious .kubernetes .operator .ResourcesUtil .namespace ;
64+
6165// @formatter:off
6266@ ControllerConfiguration (dependents = {
6367 @ Dependent (
@@ -142,7 +146,7 @@ private static KafkaProxy buildStatus(KafkaProxy primary,
142146 // @formatter:off
143147 return new KafkaProxyBuilder (primary )
144148 .editOrNewStatus ()
145- .withObservedGeneration (primary . getMetadata (). getGeneration ( ))
149+ .withObservedGeneration (generation ( primary ))
146150 .withConditions (effectiveReadyCondition (now , primary , exception ))
147151 .withClusters (clusterConditions (now , primary , context ))
148152 .endStatus ()
@@ -157,7 +161,7 @@ private static List<io.kroxylicious.kubernetes.api.v1alpha1.kafkaproxystatus.Clu
157161 ClusterCondition clusterCondition = SharedKafkaProxyContext .clusterCondition (context , cluster );
158162 var conditions = newClusterCondition (now , primary , clusterCondition );
159163 return new io .kroxylicious .kubernetes .api .v1alpha1 .kafkaproxystatus .ClustersBuilder ()
160- .withName (cluster . getMetadata (). getName ( ))
164+ .withName (name ( cluster ))
161165 .withConditions (conditions ).build ();
162166 }).toList ();
163167 }
@@ -186,16 +190,16 @@ private static Conditions effectiveReadyCondition(ZonedDateTime now,
186190 return newCondition (now , ConditionType .Ready , primary , exception );
187191 }
188192 else {
189- oldReady .setObservedGeneration (primary . getMetadata (). getGeneration ( ));
193+ oldReady .setObservedGeneration (generation ( primary ));
190194 return oldReady ;
191195 }
192196 }
193197
194198 static LoggingEventBuilder addResourceKeys (KafkaProxy primary , LoggingEventBuilder loggingEventBuilder ) {
195199 return loggingEventBuilder .addKeyValue ("kind" , primary .getKind ())
196200 .addKeyValue ("group" , primary .getGroup ())
197- .addKeyValue ("namespace" , primary . getMetadata (). getNamespace ( ))
198- .addKeyValue ("name" , primary . getMetadata (). getName ( ));
201+ .addKeyValue ("namespace" , namespace ( primary ))
202+ .addKeyValue ("name" , name ( primary ));
199203 }
200204
201205 private static void logException (KafkaProxy primary , Exception exception ) {
@@ -230,7 +234,7 @@ private static Conditions newCondition(
230234 return new ConditionsBuilder ()
231235 .withLastTransitionTime (now )
232236 .withMessage (conditionMessage (exception ))
233- .withObservedGeneration (primary . getMetadata (). getGeneration ( ))
237+ .withObservedGeneration (generation ( primary ))
234238 .withReason (conditionReason (exception ))
235239 .withStatus (exception == null ? Conditions .Status .TRUE : Conditions .Status .FALSE )
236240 .withType (conditionType .getValue ())
@@ -243,7 +247,7 @@ private static io.kroxylicious.kubernetes.api.v1alpha1.kafkaproxystatus.clusters
243247 return new io .kroxylicious .kubernetes .api .v1alpha1 .kafkaproxystatus .clusters .ConditionsBuilder ()
244248 .withLastTransitionTime (now )
245249 .withMessage (clusterCondition .message ())
246- .withObservedGeneration (primary . getMetadata (). getGeneration ( ))
250+ .withObservedGeneration (generation ( primary ))
247251 .withReason (clusterCondition .reason ())
248252 .withStatus (clusterCondition .status ())
249253 .withType (clusterCondition .type ().getValue ())
@@ -330,14 +334,14 @@ private static InformerEventSource<?, KafkaProxy> buildKafkaClusterRefInformer(E
330334 // find all virtual clusters that reference this kafkaClusterRef
331335
332336 var proxyNames = resourcesInSameNamespace (context , kafkaClusterRef , VirtualKafkaCluster .class )
333- .filter (vkc -> vkc .getSpec ().getTargetCluster ().getClusterRef ().getName ().equals (kafkaClusterRef . getMetadata (). getName ( )))
337+ .filter (vkc -> vkc .getSpec ().getTargetCluster ().getClusterRef ().getName ().equals (name ( kafkaClusterRef )))
334338 .map (VirtualKafkaCluster ::getSpec )
335339 .map (VirtualKafkaClusterSpec ::getProxyRef )
336340 .map (ProxyRef ::getName )
337341 .collect (Collectors .toSet ());
338342
339343 Set <ResourceID > proxyIds = filteredResourceIdsInSameNamespace (context , kafkaClusterRef , KafkaProxy .class ,
340- proxy -> proxyNames .contains (proxy . getMetadata (). getName ( )));
344+ proxy -> proxyNames .contains (name ( proxy )));
341345 LOGGER .debug ("Event source KafkaClusterRef SecondaryToPrimaryMapper got {}" , proxyIds );
342346 return proxyIds ;
343347 };
@@ -352,15 +356,15 @@ private static InformerEventSource<?, KafkaProxy> buildKafkaClusterRefInformer(E
352356 return primary -> {
353357 // Load all the virtual clusters for the KafkaProxy, then extract all the referenced KafkaClusterRef resource ids.
354358 var clusterRefNames = resourcesInSameNamespace (context , primary , VirtualKafkaCluster .class )
355- .filter (vkc -> vkc .getSpec ().getProxyRef ().getName ().equals (primary . getMetadata (). getName ( )))
359+ .filter (vkc -> vkc .getSpec ().getProxyRef ().getName ().equals (name ( primary )))
356360 .map (VirtualKafkaCluster ::getSpec )
357361 .map (VirtualKafkaClusterSpec ::getTargetCluster )
358362 .map (TargetCluster ::getClusterRef )
359363 .map (ClusterRef ::getName )
360364 .collect (Collectors .toSet ());
361365
362366 Set <ResourceID > kafkaClusterRefs = filteredResourceIdsInSameNamespace (context , primary , KafkaClusterRef .class ,
363- cluster -> clusterRefNames .contains (cluster . getMetadata (). getName ( )));
367+ cluster -> clusterRefNames .contains (name ( cluster )));
364368 LOGGER .debug ("Event source KafkaClusterRef PrimaryToSecondaryMapper got {}" , kafkaClusterRefs );
365369 return kafkaClusterRefs ;
366370 };
@@ -385,7 +389,7 @@ private static InformerEventSource<GenericKubernetesResource, KafkaProxy> eventS
385389 Set <ResourceID > filterReferences = resourcesInSameNamespace (context , proxy , VirtualKafkaCluster .class )
386390 .filter (matchesPrimary (proxy ))
387391 .flatMap (cluster -> cluster .getSpec ().getFilters ().stream ())
388- .map (filter -> new ResourceID (filter .getName (), proxy . getMetadata (). getNamespace ( )))
392+ .map (filter -> new ResourceID (filter .getName (), namespace ( proxy )))
389393 .collect (Collectors .toSet ());
390394 LOGGER .debug ("KafkaProxy {} has references to filters {}" , ResourceID .fromResource (proxy ), filterReferences );
391395 return filterReferences ;
@@ -434,14 +438,14 @@ private static <T extends HasMetadata> Set<ResourceID> filteredResourceIdsInSame
434438 private static <T extends HasMetadata > Stream <T > resourcesInSameNamespace (EventSourceContext <KafkaProxy > context , HasMetadata primary , Class <T > clazz ) {
435439 return context .getClient ()
436440 .resources (clazz )
437- .inNamespace (primary . getMetadata (). getNamespace ( ))
441+ .inNamespace (namespace ( primary ))
438442 .list ()
439443 .getItems ()
440444 .stream ();
441445 }
442446
443447 private static @ NonNull Predicate <VirtualKafkaCluster > matchesPrimary (HasMetadata primary ) {
444- return cluster -> cluster .getSpec ().getProxyRef ().getName ().equals (primary . getMetadata (). getName ( ));
448+ return cluster -> cluster .getSpec ().getProxyRef ().getName ().equals (name ( primary ));
445449 }
446450
447451}
0 commit comments