diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java index 12c6b4fe06..5175efb898 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Informable.java @@ -15,7 +15,10 @@ */ package io.javaoperatorsdk.operator.api.config; +import java.util.Optional; + import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; public interface Informable { @@ -29,4 +32,12 @@ default String getResourceTypeName() { default Class getResourceClass() { return getInformerConfig().getResourceClass(); } + + /** + * Optional, specific kubernetes client, typically to connect to a different cluster than the rest + * of the operator. Note that this is solely for multi cluster support. + */ + default Optional getKubernetesClient() { + return Optional.empty(); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java index b6f7939728..ae2b12fe16 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java @@ -83,14 +83,6 @@ default String name() { return getInformerConfig().getName(); } - /** - * Optional, specific kubernetes client, typically to connect to a different cluster than the rest - * of the operator. Note that this is solely for multi cluster support. - */ - default Optional getKubernetesClient() { - return Optional.empty(); - } - class DefaultInformerEventSourceConfiguration implements InformerEventSourceConfiguration { private final PrimaryToSecondaryMapper primaryToSecondaryMapper; diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java index 3908bbcf09..6caf39ccd9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java @@ -33,7 +33,6 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Informable; import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration; -import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration; import io.javaoperatorsdk.operator.health.InformerHealthIndicator; import io.javaoperatorsdk.operator.processing.event.ResourceID; import io.javaoperatorsdk.operator.processing.event.source.Cache; @@ -179,13 +178,11 @@ private KubernetesClient getTargetClient() { // to see the very same instance. ConfigurationService#getKubernetesClient is expected to return // a stable instance, but its default implementation does create a new client on every call. if (targetClient == null) { - targetClient = controllerConfiguration.getConfigurationService().getKubernetesClient(); - if (configuration instanceof InformerEventSourceConfiguration iesc) { - var remoteClient = iesc.getKubernetesClient().orElse(null); - if (remoteClient != null) { - targetClient = remoteClient; - } - } + targetClient = + configuration + .getKubernetesClient() + .orElseGet( + () -> controllerConfiguration.getConfigurationService().getKubernetesClient()); } return targetClient; }