diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java index fc37c1780f..f9cbea5095 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java @@ -11,6 +11,7 @@ import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import org.slf4j.Logger; @@ -48,6 +49,10 @@ public ConfigurationService getConfigurationService() { return configurationService; } + public List getControllers() { + return Collections.unmodifiableList(controllers); + } + /** * Finishes the operator startup process. This is mostly used in injection-aware applications * where there is no obvious entrypoint to the application which can trigger the injection process @@ -253,7 +258,7 @@ private static boolean failOnMissingCurrentNS( return false; } - private static class ControllerRef { + public static class ControllerRef { public final ResourceController controller; public final ControllerConfiguration configuration; @@ -261,5 +266,13 @@ public ControllerRef(ResourceController controller, ControllerConfiguration conf this.controller = controller; this.configuration = configuration; } + + public ResourceController getController() { + return controller; + } + + public ControllerConfiguration getConfiguration() { + return configuration; + } } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java similarity index 94% rename from operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java rename to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 6560ef9e55..dba3de879e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -10,7 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractConfigurationService implements ConfigurationService { +public class BaseConfigurationService implements ConfigurationService { public static final String LOGGER_NAME = "Default ConfigurationService implementation"; protected static final Logger log = LoggerFactory.getLogger(LOGGER_NAME); @@ -18,7 +18,7 @@ public abstract class AbstractConfigurationService implements ConfigurationServi private final Map configurations = new ConcurrentHashMap<>(); private final Version version; - public AbstractConfigurationService(Version version) { + public BaseConfigurationService(Version version) { this.version = version; } @@ -54,6 +54,7 @@ protected void throwExceptionOnNameCollision( + newControllerClassName); } + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public ControllerConfiguration getConfigurationFor( ResourceController controller) { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index d47837593b..8d35422bd0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -37,10 +37,14 @@ public static Version loadFromProperties() { Date builtTime; try { - builtTime = - // RFC 822 date is the default format used by git-commit-id-plugin - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") - .parse(properties.getProperty("git.build.time")); + String time = properties.getProperty("git.build.time"); + if (time != null) { + builtTime = + // RFC 822 date is the default format used by git-commit-id-plugin + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(time); + } else { + builtTime = Date.from(Instant.EPOCH); + } } catch (ParseException e) { builtTime = Date.from(Instant.EPOCH); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java index 6af60412b4..5f6a634039 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java @@ -1,10 +1,13 @@ package io.javaoperatorsdk.operator.api.config; +import java.time.Instant; import java.util.Date; /** A class encapsulating the version information associated with this SDK instance. */ public class Version { + public static final Version UNKNOWN = new Version("unknown", "unknown", Date.from(Instant.EPOCH)); + private final String sdk; private final String commit; private final Date builtTime; diff --git a/operator-framework-junit5/pom.xml b/operator-framework-junit5/pom.xml new file mode 100644 index 0000000000..0c4a251d55 --- /dev/null +++ b/operator-framework-junit5/pom.xml @@ -0,0 +1,46 @@ + + + + java-operator-sdk + io.javaoperatorsdk + 1.9.5-SNAPSHOT + + 4.0.0 + + operator-framework-junit-5 + Operator SDK - Framework - Junit5 + + + 11 + 11 + + + + + io.javaoperatorsdk + operator-framework-core + ${project.version} + + + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + + + org.assertj + assertj-core + 3.20.2 + + + org.awaitility + awaitility + 4.1.0 + + + + \ No newline at end of file diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/HasKubernetesClient.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/HasKubernetesClient.java new file mode 100644 index 0000000000..d93032333f --- /dev/null +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/HasKubernetesClient.java @@ -0,0 +1,7 @@ +package io.javaoperatorsdk.operator.junit; + +import io.fabric8.kubernetes.client.KubernetesClient; + +public interface HasKubernetesClient { + KubernetesClient getKubernetesClient(); +} diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java new file mode 100644 index 0000000000..8a1a702074 --- /dev/null +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java @@ -0,0 +1,7 @@ +package io.javaoperatorsdk.operator.junit; + +import io.fabric8.kubernetes.client.KubernetesClient; + +public interface KubernetesClientAware extends HasKubernetesClient { + void setKubernetesClient(KubernetesClient kubernetesClient); +} diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/OperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/OperatorExtension.java new file mode 100644 index 0000000000..a92f1e582a --- /dev/null +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/OperatorExtension.java @@ -0,0 +1,220 @@ +package io.javaoperatorsdk.operator.junit; + +import static io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider.override; + +import io.fabric8.kubernetes.api.model.KubernetesResourceList; +import io.fabric8.kubernetes.api.model.NamespaceBuilder; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.client.DefaultKubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.javaoperatorsdk.operator.Operator; +import io.javaoperatorsdk.operator.api.ResourceController; +import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; +import io.javaoperatorsdk.operator.api.config.ConfigurationService; +import io.javaoperatorsdk.operator.api.config.Version; +import io.javaoperatorsdk.operator.processing.retry.Retry; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OperatorExtension + implements HasKubernetesClient, + BeforeAllCallback, + BeforeEachCallback, + AfterAllCallback, + AfterEachCallback { + + private static final Logger LOGGER = LoggerFactory.getLogger(OperatorExtension.class); + + private final KubernetesClient kubernetesClient; + private final ConfigurationService configurationService; + private final String namespace; + private final Operator operator; + private final boolean preserveNamespaceOnError; + + private OperatorExtension( + ConfigurationService configurationService, boolean preserveNamespaceOnError) { + this.kubernetesClient = new DefaultKubernetesClient(); + this.namespace = UUID.randomUUID().toString(); + this.configurationService = configurationService; + this.operator = new Operator(this.kubernetesClient, this.configurationService); + this.preserveNamespaceOnError = preserveNamespaceOnError; + } + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + before(context); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + before(context); + } + + @Override + public void afterAll(ExtensionContext context) throws Exception { + after(context); + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + after(context); + } + + @Override + public KubernetesClient getKubernetesClient() { + return kubernetesClient; + } + + public String getNamespace() { + return namespace; + } + + @SuppressWarnings({"rawtypes"}) + public List controllers() { + return operator.getControllers().stream() + .map(Operator.ControllerRef::getController) + .collect(Collectors.toUnmodifiableList()); + } + + @SuppressWarnings({"rawtypes"}) + public + NonNamespaceOperation, Resource> getResourceClient( + Class type) { + return kubernetesClient.resources(type).inNamespace(namespace); + } + + @SuppressWarnings({"rawtypes"}) + public T getCustomResource(Class type, String name) { + return kubernetesClient.resources(type).inNamespace(namespace).withName(name).get(); + } + + public void register(ResourceController> controller) { + register(controller, null); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public void register(ResourceController controller, Retry retry) { + final var config = configurationService.getConfigurationFor(controller); + final var oconfig = override(config).settingNamespace(namespace); + final var path = "/META-INF/fabric8/" + config.getCRDName() + "-v1.yml"; + + if (retry != null) { + oconfig.withRetry(retry); + } + + try (InputStream is = getClass().getResourceAsStream(path)) { + kubernetesClient.load(is).createOrReplace(); + } catch (IOException ex) { + throw new IllegalStateException("Cannot find yaml on classpath: " + path); + } + + if (controller instanceof KubernetesClientAware) { + ((KubernetesClientAware) controller).setKubernetesClient(kubernetesClient); + } + + this.operator.register(controller, oconfig.build()); + + LOGGER.info("Controller {} is registered", controller.getClass().getCanonicalName()); + } + + protected void before(ExtensionContext context) { + LOGGER.info("Initializing integration test in namespace {}", namespace); + + kubernetesClient + .namespaces() + .create(new NamespaceBuilder().withNewMetadata().withName(namespace).endMetadata().build()); + + this.operator.start(); + } + + protected void after(ExtensionContext context) { + if (preserveNamespaceOnError && context.getExecutionException().isPresent()) { + LOGGER.info("Preserving namespace {}", namespace); + } else { + LOGGER.info("Deleting namespace {} and stopping operator", namespace); + kubernetesClient.namespaces().withName(namespace).delete(); + Awaitility.await("namespace deleted") + .atMost(45, TimeUnit.SECONDS) + .until(() -> kubernetesClient.namespaces().withName(namespace).get() == null); + } + + try { + this.operator.close(); + } catch (Exception e) { + // ignored + } + try { + this.kubernetesClient.close(); + } catch (Exception e) { + // ignored + } + } + + public static Builder builder() { + return new Builder(); + } + + @SuppressWarnings("rawtypes") + public static class Builder { + private final List controllers; + private ConfigurationService configurationService; + private boolean preserveNamespaceOnError = false; + + protected Builder() { + this.configurationService = new BaseConfigurationService(Version.UNKNOWN); + this.controllers = new ArrayList<>(); + } + + public Builder preserveNamespaceOnError(boolean value) { + this.preserveNamespaceOnError = value; + return this; + } + + public Builder withConfigurationService(ConfigurationService value) { + configurationService = value; + return this; + } + + @SuppressWarnings("rawtypes") + public Builder withController(ResourceController value) { + controllers.add(value); + return this; + } + + @SuppressWarnings("rawtypes") + public Builder withController(Class value) { + try { + controllers.add(value.getConstructor().newInstance()); + } catch (Exception e) { + throw new RuntimeException(e); + } + return this; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public OperatorExtension build() { + OperatorExtension answer = + new OperatorExtension(configurationService, preserveNamespaceOnError); + for (ResourceController controller : controllers) { + answer.register(controller); + } + + return answer; + } + } +} diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 15828be709..d67adcd7e0 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -79,12 +79,20 @@ 0.19 test + + io.javaoperatorsdk + operator-framework-junit-5 + ${project.version} + test + + io.fabric8 crd-generator-apt diff --git a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java index 013f52855a..a0aeefd887 100644 --- a/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java +++ b/operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationService.java @@ -2,11 +2,11 @@ import io.fabric8.kubernetes.client.CustomResource; import io.javaoperatorsdk.operator.api.ResourceController; -import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; +import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.Utils; -public class DefaultConfigurationService extends AbstractConfigurationService { +public class DefaultConfigurationService extends BaseConfigurationService { private static final DefaultConfigurationService instance = new DefaultConfigurationService(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java index 05a4a3df8f..486c20236a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java @@ -1,52 +1,46 @@ package io.javaoperatorsdk.operator; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService; +import io.javaoperatorsdk.operator.junit.OperatorExtension; import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResource; import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceController; import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceSpec; -import org.junit.jupiter.api.BeforeEach; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.jupiter.api.extension.RegisterExtension; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class EventSourceIT { - - private static final Logger log = LoggerFactory.getLogger(EventSourceIT.class); - - public static final int EXPECTED_TIMER_EVENT_COUNT = 3; - private final IntegrationTestSupport integrationTestSupport = new IntegrationTestSupport(); - - @BeforeEach - public void initAndCleanup() { - KubernetesClient k8sClient = new DefaultKubernetesClient(); - integrationTestSupport.initialize(k8sClient, new EventSourceTestCustomResourceController()); - integrationTestSupport.cleanup(); - } + @RegisterExtension + OperatorExtension operator = + OperatorExtension.builder() + .withConfigurationService(DefaultConfigurationService.instance()) + .withController(EventSourceTestCustomResourceController.class) + .preserveNamespaceOnError(false) + .build(); @Test public void receivingPeriodicEvents() { - integrationTestSupport.teardownIfSuccess( - () -> { - EventSourceTestCustomResource resource = createTestCustomResource("1"); - integrationTestSupport - .getCrOperations() - .inNamespace(IntegrationTestSupport.TEST_NAMESPACE) - .create(resource); - - Thread.sleep( - EventSourceTestCustomResourceController.TIMER_DELAY - + EXPECTED_TIMER_EVENT_COUNT - * EventSourceTestCustomResourceController.TIMER_PERIOD); - - assertThat(integrationTestSupport.numberOfControllerExecutions()) - .isGreaterThanOrEqualTo(EXPECTED_TIMER_EVENT_COUNT + 1); - }); + EventSourceTestCustomResource resource = createTestCustomResource("1"); + + operator.getResourceClient(EventSourceTestCustomResource.class).create(resource); + + await() + .atMost(5, TimeUnit.SECONDS) + .pollInterval( + EventSourceTestCustomResourceController.TIMER_PERIOD / 2, TimeUnit.MILLISECONDS) + .untilAsserted( + () -> { + for (var controller : operator.controllers()) { + if (controller instanceof TestExecutionInfoProvider) { + assertThat(((TestExecutionInfoProvider) controller).getNumberOfExecutions()) + .isGreaterThanOrEqualTo(4); + } + } + }); } public EventSourceTestCustomResource createTestCustomResource(String id) { @@ -54,7 +48,7 @@ public EventSourceTestCustomResource createTestCustomResource(String id) { resource.setMetadata( new ObjectMetaBuilder() .withName("eventsource-" + id) - .withNamespace(IntegrationTestSupport.TEST_NAMESPACE) + .withNamespace(operator.getNamespace()) .withFinalizers(EventSourceTestCustomResourceController.FINALIZER_NAME) .build()); resource.setKind("Eventsourcesample"); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java index d590bdd951..81fa3452eb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/UpdatingResAndSubResIT.java @@ -1,57 +1,53 @@ package io.javaoperatorsdk.operator; -import static io.javaoperatorsdk.operator.IntegrationTestSupport.TEST_NAMESPACE; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService; +import io.javaoperatorsdk.operator.junit.OperatorExtension; import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResource; import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResourceController; import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResourceSpec; import io.javaoperatorsdk.operator.sample.doubleupdate.DoubleUpdateTestCustomResourceStatus; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.RegisterExtension; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class UpdatingResAndSubResIT { - - private IntegrationTestSupport integrationTestSupport = new IntegrationTestSupport(); - - @BeforeEach - public void initAndCleanup() { - KubernetesClient k8sClient = new DefaultKubernetesClient(); - integrationTestSupport.initialize(k8sClient, new DoubleUpdateTestCustomResourceController()); - integrationTestSupport.cleanup(); - } + @RegisterExtension + OperatorExtension operator = + OperatorExtension.builder() + .withConfigurationService(DefaultConfigurationService.instance()) + .withController(DoubleUpdateTestCustomResourceController.class) + .preserveNamespaceOnError(false) + .build(); @Test public void updatesSubResourceStatus() { - integrationTestSupport.teardownIfSuccess( - () -> { - DoubleUpdateTestCustomResource resource = createTestCustomResource("1"); - integrationTestSupport.getCrOperations().inNamespace(TEST_NAMESPACE).create(resource); + DoubleUpdateTestCustomResource resource = createTestCustomResource("1"); + operator.getResourceClient(DoubleUpdateTestCustomResource.class).create(resource); + + awaitStatusUpdated(resource.getMetadata().getName()); + // wait for sure, there are no more events + TestUtils.waitXms(300); - awaitStatusUpdated(resource.getMetadata().getName()); - // wait for sure, there are no more events - TestUtils.waitXms(300); + DoubleUpdateTestCustomResource customResource = + operator + .getResourceClient(DoubleUpdateTestCustomResource.class) + .withName(resource.getMetadata().getName()) + .get(); - DoubleUpdateTestCustomResource customResource = - (DoubleUpdateTestCustomResource) - integrationTestSupport.getCustomResource(resource.getMetadata().getName()); - assertThat(integrationTestSupport.numberOfControllerExecutions()).isEqualTo(1); - assertThat(customResource.getStatus().getState()) - .isEqualTo(DoubleUpdateTestCustomResourceStatus.State.SUCCESS); - assertThat( - customResource - .getMetadata() - .getAnnotations() - .get(DoubleUpdateTestCustomResourceController.TEST_ANNOTATION)) - .isNotNull(); - }); + assertThat(((TestExecutionInfoProvider) operator.controllers().get(0)).getNumberOfExecutions()) + .isEqualTo(1); + assertThat(customResource.getStatus().getState()) + .isEqualTo(DoubleUpdateTestCustomResourceStatus.State.SUCCESS); + assertThat( + customResource + .getMetadata() + .getAnnotations() + .get(DoubleUpdateTestCustomResourceController.TEST_ANNOTATION)) + .isNotNull(); } void awaitStatusUpdated(String name) { @@ -60,12 +56,10 @@ void awaitStatusUpdated(String name) { .untilAsserted( () -> { DoubleUpdateTestCustomResource cr = - (DoubleUpdateTestCustomResource) - integrationTestSupport - .getCrOperations() - .inNamespace(TEST_NAMESPACE) - .withName(name) - .get(); + operator + .getResourceClient(DoubleUpdateTestCustomResource.class) + .withName(name) + .get(); assertThat(cr.getMetadata().getFinalizers()).hasSize(1); assertThat(cr).isNotNull(); assertThat(cr.getStatus()).isNotNull(); @@ -76,11 +70,7 @@ void awaitStatusUpdated(String name) { public DoubleUpdateTestCustomResource createTestCustomResource(String id) { DoubleUpdateTestCustomResource resource = new DoubleUpdateTestCustomResource(); - resource.setMetadata( - new ObjectMetaBuilder() - .withName("doubleupdateresource-" + id) - .withNamespace(TEST_NAMESPACE) - .build()); + resource.setMetadata(new ObjectMetaBuilder().withName("doubleupdateresource-" + id).build()); resource.setKind("DoubleUpdateSample"); resource.setSpec(new DoubleUpdateTestCustomResourceSpec()); resource.getSpec().setValue(id); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationServiceTest.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/BaseConfigurationServiceTest.java similarity index 86% rename from operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationServiceTest.java rename to operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/BaseConfigurationServiceTest.java index 78c7692485..1818ac12cb 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationServiceTest.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/BaseConfigurationServiceTest.java @@ -17,23 +17,23 @@ import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.UpdateControl; -import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; +import io.javaoperatorsdk.operator.api.config.BaseConfigurationService; import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; -public class DefaultConfigurationServiceTest { +public class BaseConfigurationServiceTest { public static final String CUSTOM_FINALIZER_NAME = "a.custom/finalizer"; @Test void attemptingToRetrieveAnUnknownControllerShouldLogWarning() { - final var logger = (Logger) LoggerFactory.getLogger(AbstractConfigurationService.LOGGER_NAME); + final var logger = (Logger) LoggerFactory.getLogger(BaseConfigurationService.LOGGER_NAME); final var appender = new ListAppender(); logger.addAppender(appender); appender.start(); try { final var config = - DefaultConfigurationService.instance() + io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService.instance() .getConfigurationFor(new NotAutomaticallyCreated(), false); assertNull(config); assertEquals(1, appender.list.size()); @@ -54,7 +54,8 @@ void attemptingToRetrieveAnUnknownControllerShouldLogWarning() { public void returnsValuesFromControllerAnnotationFinalizer() { final var controller = new TestCustomResourceController(); final var configuration = - DefaultConfigurationService.instance().getConfigurationFor(controller); + io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService.instance() + .getConfigurationFor(controller); assertEquals(CustomResource.getCRDName(TestCustomResource.class), configuration.getCRDName()); assertEquals( ControllerUtils.getDefaultFinalizerName(configuration.getCRDName()), @@ -67,7 +68,8 @@ public void returnsValuesFromControllerAnnotationFinalizer() { public void returnCustomerFinalizerNameIfSet() { final var controller = new TestCustomFinalizerController(); final var configuration = - DefaultConfigurationService.instance().getConfigurationFor(controller); + io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService.instance() + .getConfigurationFor(controller); assertEquals(CUSTOM_FINALIZER_NAME, configuration.getFinalizer()); } @@ -76,7 +78,7 @@ public void supportsInnerClassCustomResources() { final var controller = new TestCustomFinalizerController(); assertDoesNotThrow( () -> { - DefaultConfigurationService.instance() + io.javaoperatorsdk.operator.config.runtime.DefaultConfigurationService.instance() .getConfigurationFor(controller) .getAssociatedControllerClassName(); }); diff --git a/pom.xml b/pom.xml index 62e3539cfe..083ff7675c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ operator-framework-core + operator-framework-junit5 operator-framework samples @@ -67,25 +68,21 @@ org.junit.jupiter junit-jupiter-api ${junit.version} - test org.junit.jupiter junit-jupiter-engine ${junit.version} - test org.junit.jupiter junit-jupiter-params ${junit.version} - test org.junit.platform junit-platform-commons 1.7.2 - test org.apache.logging.log4j