diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java index 7ed0e25aca..79cf21bab9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java @@ -24,7 +24,7 @@ /** * Dispatches events to the Controller and handles Finalizers for a single type of Custom Resource. */ -class EventDispatcher> { +public class EventDispatcher> { private static final Logger log = LoggerFactory.getLogger(EventDispatcher.class); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java index ff7ba37b15..3aad5131f8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java @@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.client.CustomResource; -import io.fabric8.kubernetes.client.KubernetesClientException; import io.javaoperatorsdk.operator.MissingCRDException; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.processing.ConfiguredController; @@ -85,16 +84,10 @@ public final void registerEventSource(String name, EventSource eventSource) eventSource.setEventHandler(defaultEventHandler); eventSource.start(); } catch (Throwable e) { - if (e instanceof IllegalStateException) { + if (e instanceof IllegalStateException || e instanceof MissingCRDException) { // leave untouched throw e; } - if (e instanceof KubernetesClientException) { - KubernetesClientException ke = (KubernetesClientException) e; - if (404 == ke.getCode()) { - throw new MissingCRDException(null, null); - } - } throw new OperatorException("Couldn't register event source named '" + name + "'", e); } finally { lock.unlock(); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java index 5c9f97621d..89f81efdf2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/internal/CustomResourceEventSource.java @@ -11,10 +11,12 @@ import io.fabric8.kubernetes.api.model.ListOptions; import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.Watch; import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.WatcherException; import io.fabric8.kubernetes.client.utils.Utils; +import io.javaoperatorsdk.operator.MissingCRDException; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.processing.ConfiguredController; import io.javaoperatorsdk.operator.processing.CustomResourceCache; @@ -54,17 +56,31 @@ public void start() { options.setLabelSelector(labelSelector); } - if (ControllerConfiguration.allNamespacesWatched(targetNamespaces)) { - var w = client.inAnyNamespace().watch(options, this); - watches.add(w); - log.debug("Registered {} -> {} for any namespace", controller, w); - } else { - targetNamespaces.forEach( - ns -> { - var w = client.inNamespace(ns).watch(options, this); - watches.add(w); - log.debug("Registered {} -> {} for namespace: {}", controller, w, ns); - }); + try { + if (ControllerConfiguration.allNamespacesWatched(targetNamespaces)) { + var w = client.inAnyNamespace().watch(options, this); + watches.add(w); + log.debug("Registered {} -> {} for any namespace", controller, w); + } else { + targetNamespaces.forEach( + ns -> { + var w = client.inNamespace(ns).watch(options, this); + watches.add(w); + log.debug("Registered {} -> {} for namespace: {}", controller, w, ns); + }); + } + } catch (Exception e) { + if (e instanceof KubernetesClientException) { + KubernetesClientException ke = (KubernetesClientException) e; + if (404 == ke.getCode()) { + // only throw MissingCRDException if the 404 error occurs on the target CRD + final var targetCRDName = controller.getConfiguration().getCRDName(); + if (targetCRDName.equals(ke.getFullResourceName())) { + throw new MissingCRDException(targetCRDName, null); + } + } + } + throw e; } } diff --git a/pom.xml b/pom.xml index db32e5c2cc..52edf21105 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ ${java.version} 5.8.1 - 5.7.2 + 5.8.0 1.7.32 2.14.1 3.12.4