diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index bfc4c6c588..e6a78a0e4d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -65,8 +65,4 @@ protected boolean createIfNeeded() { return true; } - @Override - public boolean checkCRDAndValidateLocalModel() { - return Utils.shouldCheckCRDAndValidateLocalModel(); - } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java index f13ae118f8..9c30e36e76 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java @@ -65,21 +65,6 @@ default Config getClientConfiguration() { */ Version getVersion(); - /** - * Whether the operator should query the CRD to make sure it's deployed and validate - * {@link CustomResource} implementations before attempting to register the associated - * reconcilers. - * - * <p> - * Note that this might require elevating the privileges associated with the operator to gain read - * access on the CRD resources. - * - * @return {@code true} if CRDs should be checked (default), {@code false} otherwise - */ - default boolean checkCRDAndValidateLocalModel() { - return true; - } - int DEFAULT_RECONCILIATION_THREADS_NUMBER = 5; /** diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java index 9beb583d76..f22fc920ab 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java @@ -12,7 +12,6 @@ public class ConfigurationServiceOverrider { private final ConfigurationService original; private Metrics metrics; private Config clientConfig; - private boolean checkCR; private int threadNumber; private Cloner cloner; private int timeoutSeconds; @@ -22,7 +21,6 @@ public class ConfigurationServiceOverrider { ConfigurationServiceOverrider(ConfigurationService original) { this.original = original; this.clientConfig = original.getClientConfiguration(); - this.checkCR = original.checkCRDAndValidateLocalModel(); this.threadNumber = original.concurrentReconciliationThreads(); this.cloner = original.getResourceCloner(); this.timeoutSeconds = original.getTerminationTimeoutSeconds(); @@ -36,11 +34,6 @@ public ConfigurationServiceOverrider withClientConfiguration(Config configuratio return this; } - public ConfigurationServiceOverrider checkingCRDAndValidateLocalModel(boolean check) { - this.checkCR = check; - return this; - } - public ConfigurationServiceOverrider withConcurrentReconciliationThreads(int threadNumber) { this.threadNumber = threadNumber; return this; @@ -83,11 +76,6 @@ public Config getClientConfiguration() { return clientConfig; } - @Override - public boolean checkCRDAndValidateLocalModel() { - return checkCR; - } - @Override public int concurrentReconciliationThreads() { return threadNumber; 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 7ee63d760f..671a595475 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 @@ -9,12 +9,9 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; -import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; -import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.javaoperatorsdk.operator.CustomResourceUtils; import io.javaoperatorsdk.operator.MissingCRDException; import io.javaoperatorsdk.operator.OperatorException; import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider; @@ -261,27 +258,10 @@ public void start() throws OperatorException { 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 - if (ConfigurationServiceProvider.instance().checkCRDAndValidateLocalModel() - && CustomResource.class.isAssignableFrom(resClass)) { - crd = kubernetesClient.apiextensions().v1().customResourceDefinitions().withName(crdName) - .get(); - if (crd == null) { - throwMissingCRDException(crdName, specVersion, controllerName); - } - - // Apply validations that are not handled by fabric8 - CustomResourceUtils.assertCustomResource(resClass, crd); - } - final var context = new EventSourceContext<>( eventSourceManager.getControllerResourceEventSource(), configuration, kubernetesClient); - prepareEventSources(context).forEach(eventSourceManager::registerEventSource); - eventSourceManager.start(); - log.info("'{}' controller started, pending event sources initialization", controllerName); } catch (MissingCRDException e) { throwMissingCRDException(crdName, specVersion, controllerName); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProviderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProviderTest.java index f69dd0bc29..082eacab72 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProviderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProviderTest.java @@ -3,6 +3,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static io.javaoperatorsdk.operator.api.config.ConfigurationService.DEFAULT_RECONCILIATION_THREADS_NUMBER; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.junit.jupiter.api.Assertions.*; class ConfigurationServiceProviderTest { @@ -35,16 +37,17 @@ void shouldProvideTheSetInstanceIfProvided() { @Test void shouldBePossibleToOverrideConfigOnce() { final var config = new AbstractConfigurationService(null); - assertTrue(config.checkCRDAndValidateLocalModel()); + assertThat(config.concurrentReconciliationThreads()) + .isEqualTo(DEFAULT_RECONCILIATION_THREADS_NUMBER); ConfigurationServiceProvider.set(config); var instance = ConfigurationServiceProvider.instance(); assertEquals(config, instance); - ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false)); + ConfigurationServiceProvider.overrideCurrent(o -> o.withConcurrentReconciliationThreads(10)); instance = ConfigurationServiceProvider.instance(); assertNotEquals(config, instance); - assertFalse(instance.checkCRDAndValidateLocalModel()); + assertThat(instance.concurrentReconciliationThreads()).isEqualTo(10); assertThrows(IllegalStateException.class, () -> ConfigurationServiceProvider.overrideCurrent(o -> o.withCloseClientOnStop(false))); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/ControllerTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/ControllerTest.java index 2f5b9bf4ba..16343240c3 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/ControllerTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/ControllerTest.java @@ -3,62 +3,19 @@ import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.Secret; -import io.javaoperatorsdk.operator.MissingCRDException; import io.javaoperatorsdk.operator.MockKubernetesClient; -import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.reconciler.Cleaner; import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; @SuppressWarnings("unchecked") class ControllerTest { final ControllerConfiguration configuration = mock(ControllerConfiguration.class); - final Reconciler reconciler = mock(Reconciler.class); - - @Test - void crdShouldNotBeCheckedForNativeResources() { - final var client = MockKubernetesClient.client(Secret.class); - - when(configuration.getResourceClass()).thenReturn(Secret.class); - - final var controller = new Controller<Secret>(reconciler, configuration, client); - controller.start(); - verify(client, never()).apiextensions(); - } - - @Test - void crdShouldNotBeCheckedForCustomResourcesIfDisabled() { - final var client = MockKubernetesClient.client(TestCustomResource.class); - when(configuration.getResourceClass()).thenReturn(TestCustomResource.class); - - try { - ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false)); - final var controller = new Controller<TestCustomResource>(reconciler, configuration, client); - controller.start(); - verify(client, never()).apiextensions(); - } finally { - ConfigurationServiceProvider.reset(); - } - } - - @Test - void crdShouldBeCheckedForCustomResourcesByDefault() { - ConfigurationServiceProvider.reset(); - final var client = MockKubernetesClient.client(TestCustomResource.class); - when(configuration.getResourceClass()).thenReturn(TestCustomResource.class); - - final var controller = new Controller<TestCustomResource>(reconciler, configuration, client); - // since we're not really connected to a cluster and the CRD wouldn't be deployed anyway, we - // expect a MissingCRDException to be thrown - assertThrows(MissingCRDException.class, controller::start); - verify(client, times(1)).apiextensions(); - } @Test void usesFinalizerIfThereIfReconcilerImplementsCleaner() { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index ccf218d3d0..805854f733 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -65,13 +65,12 @@ static void classSetup() { * implemented on TestCustomResourceSpec or TestCustomResourceStatus */ ConfigurationServiceProvider.overrideCurrent(overrider -> { - overrider.checkingCRDAndValidateLocalModel(false) - .withResourceCloner(new Cloner() { - @Override - public <R extends HasMetadata> R clone(R object) { - return object; - } - }); + overrider.withResourceCloner(new Cloner() { + @Override + public <R extends HasMetadata> R clone(R object) { + return object; + } + }); }); } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/CustomResourceSelectorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/CustomResourceSelectorTest.java index 2d943deb80..94c32ba8fb 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/CustomResourceSelectorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/CustomResourceSelectorTest.java @@ -53,7 +53,6 @@ void setUpResources() { ConfigurationServiceProvider.reset(); configurationService = spy(ConfigurationService.class); - when(configurationService.checkCRDAndValidateLocalModel()).thenReturn(false); when(configurationService.getVersion()).thenReturn(new Version("1", "1", new Date())); when(configurationService.getConfigurationFor(any(MyController.class))) .thenReturn(new MyConfiguration());