diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 5e93b0d7af..f9a600f1a7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.processing; import java.util.List; -import java.util.Objects; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; @@ -28,6 +27,7 @@ import io.javaoperatorsdk.operator.processing.event.EventSourceManager; import io.javaoperatorsdk.operator.processing.event.source.EventSource; +@SuppressWarnings({"unchecked"}) public class Controller implements Reconciler, LifecycleAware, EventSourceInitializer { private final Reconciler reconciler; @@ -165,6 +165,10 @@ public void start() throws OperatorException { final String controllerName = configuration.getName(); final var crdName = configuration.getResourceTypeName(); final var specVersion = "v1"; + + // fail early if we're missing the current namespace information + failOnMissingCurrentNS(); + try { // check that the custom resource is known by the cluster if configured that way final CustomResourceDefinition crd; // todo: check proper CRD spec version based on config @@ -188,12 +192,7 @@ public void start() throws OperatorException { configurationService(), kubernetesClient)) .forEach(eventSourceManager::registerEventSource); } - if (failOnMissingCurrentNS()) { - throw new OperatorException( - "Controller '" - + controllerName - + "' is configured to watch the current namespace but it couldn't be inferred from the current configuration."); - } + eventSourceManager.start(); } catch (MissingCRDException e) { throwMissingCRDException(crdName, specVersion, controllerName); @@ -231,19 +230,18 @@ private void throwMissingCRDException(String crdName, String specVersion, String } /** - * Determines whether we should fail because the current namespace is request as target namespace - * but is missing - * - * @return {@code true} if the current namespace is requested but is missing, {@code false} - * otherwise + * Throws an {@link OperatorException} if the controller is configured to watch the current + * namespace but it's absent from the configuration. */ - private boolean failOnMissingCurrentNS() { - if (configuration.watchCurrentNamespace()) { - final var effectiveNamespaces = configuration.getEffectiveNamespaces(); - return effectiveNamespaces.size() == 1 - && effectiveNamespaces.stream().allMatch(Objects::isNull); + private void failOnMissingCurrentNS() { + try { + configuration.getEffectiveNamespaces(); + } catch (OperatorException e) { + throw new OperatorException( + "Controller '" + + configuration.getName() + + "' is configured to watch the current namespace but it couldn't be inferred from the current configuration."); } - return false; } public EventSourceManager getEventSourceManager() { diff --git a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/AnnotationConfiguration.java b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/AnnotationConfiguration.java index 8977bf3ff8..a1cf34a010 100644 --- a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/AnnotationConfiguration.java +++ b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/AnnotationConfiguration.java @@ -110,8 +110,6 @@ public ResourceEventFilter getEventFilter() { : ResourceEventFilters.passthrough(); } - - @Override public Optional reconciliationMaxInterval() { if (annotation.reconciliationMaxInterval() != null) {