Skip to content

fix: Check CRD default to false #1063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ default Config getClientConfiguration() {
* @return {@code true} if CRDs should be checked (default), {@code false} otherwise
*/
default boolean checkCRDAndValidateLocalModel() {
return true;
return false;
}

int DEFAULT_RECONCILIATION_THREADS_NUMBER = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static boolean isValidateCustomResourcesEnvVarSet() {
}

public static boolean shouldCheckCRDAndValidateLocalModel() {
return getBooleanFromSystemPropsOrDefault(CHECK_CRD_ENV_KEY, true);
return getBooleanFromSystemPropsOrDefault(CHECK_CRD_ENV_KEY, false);
}

public static boolean debugThreadPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ void shouldProvideTheSetInstanceIfProvided() {
@Test
void shouldBePossibleToOverrideConfigOnce() {
final var config = new AbstractConfigurationService(null);
assertTrue(config.checkCRDAndValidateLocalModel());
assertFalse(config.checkCRDAndValidateLocalModel());

ConfigurationServiceProvider.set(config);
var instance = ConfigurationServiceProvider.instance();
assertEquals(config, instance);

ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false));
ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(true));
instance = ConfigurationServiceProvider.instance();
assertNotEquals(config, instance);
assertFalse(instance.checkCRDAndValidateLocalModel());
assertTrue(instance.checkCRDAndValidateLocalModel());

assertThrows(IllegalStateException.class,
() -> ConfigurationServiceProvider.overrideCurrent(o -> o.withCloseClientOnStop(false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
class UtilsTest {

@Test
void shouldCheckCRDAndValidateLocalModelByDefault() {
assertTrue(Utils.shouldCheckCRDAndValidateLocalModel());
void shouldNotCheckCRDAndValidateLocalModelByDefault() {
assertFalse(Utils.shouldCheckCRDAndValidateLocalModel());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -12,7 +11,6 @@
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")
Expand Down Expand Up @@ -47,19 +45,6 @@ void crdShouldNotBeCheckedForCustomResourcesIfDisabled() {
}
}

@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() {
Reconciler reconciler = mock(Reconciler.class, withSettings().extraInterfaces(Cleaner.class));
Expand Down