From e77f2dd72d1bccaf50957c00a7719e43f8fec016 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 13:21:36 +0100 Subject: [PATCH 01/18] fix: use controller name instead of controller class name --- .../java/io/javaoperatorsdk/operator/Operator.java | 14 ++++++-------- .../operator/processing/DefaultEventHandler.java | 9 +-------- 2 files changed, 7 insertions(+), 16 deletions(-) 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 b1e8f25af5..c7a4e4f0c6 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 @@ -50,7 +50,7 @@ public void register( configuration = existing; } final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration()); - final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {}); + final var targetNamespaces = configuration.getNamespaces().toArray(new String[]{}); registerController(controller, configuration.watchAllNamespaces(), retry, targetNamespaces); } } @@ -66,18 +66,16 @@ private void registerController( Class resClass = configuration.getCustomResourceClass(); String finalizer = configuration.getFinalizer(); MixedOperation client = k8sClient.customResources(resClass); - EventDispatcher eventDispatcher = - new EventDispatcher( - controller, finalizer, new EventDispatcher.CustomResourceFacade(client)); + EventDispatcher dispatcher = new EventDispatcher(controller, finalizer, + new EventDispatcher.CustomResourceFacade(client)); CustomResourceCache customResourceCache = new CustomResourceCache(); DefaultEventHandler defaultEventHandler = - new DefaultEventHandler( - customResourceCache, eventDispatcher, controller.getClass().getName(), retry); + new DefaultEventHandler(customResourceCache, dispatcher, configuration.getName(), retry); DefaultEventSourceManager eventSourceManager = new DefaultEventSourceManager(defaultEventHandler, retry != null); defaultEventHandler.setEventSourceManager(eventSourceManager); - eventDispatcher.setEventSourceManager(eventSourceManager); + dispatcher.setEventSourceManager(eventSourceManager); controller.init(eventSourceManager); CustomResourceEventSource customResourceEventSource = @@ -111,7 +109,7 @@ private CustomResourceEventSource createCustomResourceEventSource( CustomResourceEventSource customResourceEventSource = watchAllNamespaces ? CustomResourceEventSource.customResourceEventSourceForAllNamespaces( - customResourceCache, client, generationAware, finalizer) + customResourceCache, client, generationAware, finalizer) : CustomResourceEventSource.customResourceEventSourceForTargetNamespaces( customResourceCache, client, targetNamespaces, generationAware, finalizer); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java index 5b9fa023e6..92fa88a375 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java @@ -17,7 +17,6 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.locks.ReentrantLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,13 +51,7 @@ public DefaultEventHandler( eventBuffer = new EventBuffer(); executor = new ScheduledThreadPoolExecutor( - 5, - new ThreadFactory() { - @Override - public Thread newThread(Runnable runnable) { - return new Thread(runnable, "EventHandler-" + relatedControllerName); - } - }); + 5, runnable -> new Thread(runnable, "EventHandler-" + relatedControllerName)); } public void setEventSourceManager(DefaultEventSourceManager eventSourceManager) { From 4277b3dcd142cccff176a4c85516c0bc59186a40 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 13:33:36 +0100 Subject: [PATCH 02/18] refactor: merge register and registerController methods --- .../io/javaoperatorsdk/operator/Operator.java | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) 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 c7a4e4f0c6..159de239e0 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 @@ -12,7 +12,6 @@ import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager; import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventSource; import io.javaoperatorsdk.operator.processing.retry.GenericRetry; -import io.javaoperatorsdk.operator.processing.retry.Retry; import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,53 +48,43 @@ public void register( if (configuration == null) { configuration = existing; } - final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration()); - final var targetNamespaces = configuration.getNamespaces().toArray(new String[]{}); - registerController(controller, configuration.watchAllNamespaces(), retry, targetNamespaces); - } - } - @SuppressWarnings("rawtypes") - private void registerController( - ResourceController controller, - boolean watchAllNamespaces, - Retry retry, - String... targetNamespaces) - throws OperatorException { - final var configuration = configurationService.getConfigurationFor(controller); - Class resClass = configuration.getCustomResourceClass(); - String finalizer = configuration.getFinalizer(); - MixedOperation client = k8sClient.customResources(resClass); - EventDispatcher dispatcher = new EventDispatcher(controller, finalizer, - new EventDispatcher.CustomResourceFacade(client)); + final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration()); + final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {}); + Class resClass = configuration.getCustomResourceClass(); + String finalizer = configuration.getFinalizer(); + MixedOperation client = k8sClient.customResources(resClass); + EventDispatcher dispatcher = + new EventDispatcher( + controller, finalizer, new EventDispatcher.CustomResourceFacade(client)); - CustomResourceCache customResourceCache = new CustomResourceCache(); - DefaultEventHandler defaultEventHandler = - new DefaultEventHandler(customResourceCache, dispatcher, configuration.getName(), retry); - DefaultEventSourceManager eventSourceManager = - new DefaultEventSourceManager(defaultEventHandler, retry != null); - defaultEventHandler.setEventSourceManager(eventSourceManager); - dispatcher.setEventSourceManager(eventSourceManager); + CustomResourceCache customResourceCache = new CustomResourceCache(); + DefaultEventHandler defaultEventHandler = + new DefaultEventHandler(customResourceCache, dispatcher, configuration.getName(), retry); + DefaultEventSourceManager eventSourceManager = + new DefaultEventSourceManager(defaultEventHandler, retry != null); + defaultEventHandler.setEventSourceManager(eventSourceManager); + dispatcher.setEventSourceManager(eventSourceManager); - controller.init(eventSourceManager); - CustomResourceEventSource customResourceEventSource = - createCustomResourceEventSource( - client, - customResourceCache, - watchAllNamespaces, - targetNamespaces, - defaultEventHandler, - configuration.isGenerationAware(), - finalizer); - eventSourceManager.registerCustomResourceEventSource(customResourceEventSource); + controller.init(eventSourceManager); + final boolean watchAllNamespaces = configuration.watchAllNamespaces(); + CustomResourceEventSource customResourceEventSource = + createCustomResourceEventSource( + client, + customResourceCache, + watchAllNamespaces, + targetNamespaces, + defaultEventHandler, + configuration.isGenerationAware(), + finalizer); + eventSourceManager.registerCustomResourceEventSource(customResourceEventSource); - log.info( - "Registered Controller: '{}' for CRD: '{}' for namespaces: {}", - controller.getClass().getSimpleName(), - resClass, - targetNamespaces.length == 0 - ? "[all/client namespace]" - : Arrays.toString(targetNamespaces)); + log.info( + "Registered Controller: '{}' for CRD: '{}' for namespaces: {}", + controller.getClass().getSimpleName(), + resClass, + watchAllNamespaces ? "[all namespaces]" : Arrays.toString(targetNamespaces)); + } } private CustomResourceEventSource createCustomResourceEventSource( @@ -109,7 +98,7 @@ private CustomResourceEventSource createCustomResourceEventSource( CustomResourceEventSource customResourceEventSource = watchAllNamespaces ? CustomResourceEventSource.customResourceEventSourceForAllNamespaces( - customResourceCache, client, generationAware, finalizer) + customResourceCache, client, generationAware, finalizer) : CustomResourceEventSource.customResourceEventSourceForTargetNamespaces( customResourceCache, client, targetNamespaces, generationAware, finalizer); From 174097fa7c219505f4ded220ae54302ce25af6a2 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 16:41:57 +0100 Subject: [PATCH 03/18] refactor: generify CustomResourceFacade --- .../java/io/javaoperatorsdk/operator/Operator.java | 2 +- .../operator/processing/EventDispatcher.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) 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 159de239e0..7501c29bc5 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 @@ -53,7 +53,7 @@ public void register( final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {}); Class resClass = configuration.getCustomResourceClass(); String finalizer = configuration.getFinalizer(); - MixedOperation client = k8sClient.customResources(resClass); + final var client = k8sClient.customResources(resClass); EventDispatcher dispatcher = new EventDispatcher( controller, finalizer, new EventDispatcher.CustomResourceFacade(client)); 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 9e951e26c2..a440a841e2 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 @@ -5,6 +5,7 @@ import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.markedForDeletion; +import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; @@ -189,15 +190,16 @@ private void addFinalizerIfNotPresent(CustomResource resource) { } // created to support unit testing - public static class CustomResourceFacade { + public static class CustomResourceFacade { - private final MixedOperation> resourceOperation; + private final MixedOperation, Resource> resourceOperation; - public CustomResourceFacade(MixedOperation> resourceOperation) { + public CustomResourceFacade( + MixedOperation, Resource> resourceOperation) { this.resourceOperation = resourceOperation; } - public CustomResource updateStatus(CustomResource resource) { + public R updateStatus(R resource) { log.trace("Updating status for resource: {}", resource); return resourceOperation .inNamespace(resource.getMetadata().getNamespace()) @@ -205,7 +207,7 @@ public CustomResource updateStatus(CustomResource resource) { .updateStatus(resource); } - public CustomResource replaceWithLock(CustomResource resource) { + public R replaceWithLock(R resource) { return resourceOperation .inNamespace(resource.getMetadata().getNamespace()) .withName(resource.getMetadata().getName()) From 8fa839e5098402318530aadd076bdd6f296fd711 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 21:55:17 +0100 Subject: [PATCH 04/18] feat: add version information to configuration --- operator-framework-core/pom.xml | 148 ++++++++++-------- .../config/AbstractConfigurationService.java | 10 ++ .../api/config/ConfigurationService.java | 2 + .../operator/api/config/Utils.java | 33 ++++ .../operator/api/config/Version.java | 27 ++++ .../deployment/QuarkusExtensionProcessor.java | 9 +- .../ConfigurationServiceRecorder.java | 5 +- .../QuarkusConfigurationService.java | 4 +- .../quarkus/extension/Version.java | 13 ++ .../starter/OperatorAutoConfiguration.java | 5 + .../runtime/DefaultConfigurationService.java | 5 + 11 files changed, 195 insertions(+), 66 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java create mode 100644 operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index e46f893d8d..a08f6227ec 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -2,72 +2,96 @@ - 4.0.0 - - io.javaoperatorsdk - java-operator-sdk - 1.7.1-SNAPSHOT - ../pom.xml - + 4.0.0 + + io.javaoperatorsdk + java-operator-sdk + 1.7.1-SNAPSHOT + ../pom.xml + - operator-framework-core - Operator SDK - Framework - Core - Core framework for implementing Kubernetes operators - jar + operator-framework-core + Operator SDK - Framework - Core + Core framework for implementing Kubernetes operators + jar - - 11 - 11 - 11 - + + 11 + 11 + 11 + - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - - + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + pl.project13.maven + git-commit-id-plugin + 4.0.3 + + + get-the-git-infos + + revision + + initialize + + + + true + ${project.build.outputDirectory}/version.properties + + + ^git.build.(time|version)$ + ^git.commit.id.(abbrev|full)$ + + full + + + + - - - io.fabric8 - openshift-client - - - org.slf4j - slf4j-api - + + + io.fabric8 + openshift-client + + + org.slf4j + slf4j-api + - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.mockito - mockito-core - test - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.13.3 - test - - - org.assertj - assertj-core - 3.18.0 - test - - + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-core + test + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + test + + + org.assertj + assertj-core + 3.18.0 + test + + 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/AbstractConfigurationService.java index 8d0ccb34e4..6d4e36f067 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/AbstractConfigurationService.java @@ -10,6 +10,11 @@ public abstract class AbstractConfigurationService implements ConfigurationService { private final Map configurations = new ConcurrentHashMap<>(); + private final Version version; + + public AbstractConfigurationService(Version version) { + this.version = version; + } protected void register(ControllerConfiguration config) { final var name = config.getName(); @@ -41,4 +46,9 @@ public ControllerConfiguration getConfigurationFor public Set getKnownControllerNames() { return configurations.keySet(); } + + @Override + public Version getVersion() { + return version; + } } 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 952b1c1838..51d0c853c2 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 @@ -15,4 +15,6 @@ default Config getClientConfiguration() { } Set getKnownControllerNames(); + + Version getVersion(); } 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 new file mode 100644 index 0000000000..8e82a53fd7 --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -0,0 +1,33 @@ +package io.javaoperatorsdk.operator.api.config; + +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.time.Instant; +import java.util.Date; +import java.util.Properties; + +public class Utils { + + public static Version loadFromProperties() { + final var is = + Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); + final var properties = new Properties(); + try { + properties.load(is); + } catch (IOException e) { + e.printStackTrace(); + } + + Date builtTime; + try { + builtTime = DateFormat.getDateTimeInstance().parse(properties.getProperty("git.build.time")); + } catch (ParseException e) { + builtTime = Date.from(Instant.EPOCH); + } + return new Version( + properties.getProperty("git.build.version", "unknown"), + properties.getProperty("git.commit.id.abbrev", "unknown"), + builtTime); + } +} 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 new file mode 100644 index 0000000000..9d7d0f8c7d --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Version.java @@ -0,0 +1,27 @@ +package io.javaoperatorsdk.operator.api.config; + +import java.util.Date; + +public class Version { + private final String project; + private final String commit; + private final Date builtTime; + + public Version(String project, String commit, Date builtTime) { + this.project = project; + this.commit = commit; + this.builtTime = builtTime; + } + + public String getProject() { + return project; + } + + public String getCommit() { + return commit; + } + + public Date getBuiltTime() { + return builtTime; + } +} diff --git a/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java b/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java index 446519417b..2b9022521d 100644 --- a/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java +++ b/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java @@ -7,12 +7,14 @@ import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import io.javaoperatorsdk.operator.api.config.RetryConfiguration; +import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.quarkus.extension.ConfigurationServiceRecorder; import io.javaoperatorsdk.quarkus.extension.ExternalConfiguration; import io.javaoperatorsdk.quarkus.extension.ExternalControllerConfiguration; import io.javaoperatorsdk.quarkus.extension.OperatorProducer; import io.javaoperatorsdk.quarkus.extension.QuarkusConfigurationService; import io.javaoperatorsdk.quarkus.extension.QuarkusControllerConfiguration; +import io.javaoperatorsdk.quarkus.extension.Version; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.deployment.annotations.BuildProducer; @@ -79,7 +81,12 @@ void createConfigurationServiceAndOperator( .map(ci -> createControllerConfiguration(ci, additionalBeans, reflectionClasses)) .collect(Collectors.toList()); - final var supplier = recorder.configurationServiceSupplier(controllerConfigs); + final var version = Utils.loadFromProperties(); + + final var supplier = + recorder.configurationServiceSupplier( + new Version(version.getProject(), version.getCommit(), version.getBuiltTime()), + controllerConfigs); syntheticBeanBuildItemBuildProducer.produce( SyntheticBeanBuildItem.configure(QuarkusConfigurationService.class) .scope(Singleton.class) diff --git a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/ConfigurationServiceRecorder.java b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/ConfigurationServiceRecorder.java index 8627448bab..d0d6d3dca9 100644 --- a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/ConfigurationServiceRecorder.java +++ b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/ConfigurationServiceRecorder.java @@ -3,6 +3,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.Version; import io.quarkus.arc.Arc; import io.quarkus.runtime.annotations.Recorder; import java.util.List; @@ -12,9 +13,9 @@ public class ConfigurationServiceRecorder { public Supplier configurationServiceSupplier( - List controllerConfigs) { + Version version, List controllerConfigs) { return () -> new QuarkusConfigurationService( - controllerConfigs, Arc.container().instance(KubernetesClient.class).get()); + version, controllerConfigs, Arc.container().instance(KubernetesClient.class).get()); } } diff --git a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/QuarkusConfigurationService.java b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/QuarkusConfigurationService.java index 07cfc30fa1..d18a271cec 100644 --- a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/QuarkusConfigurationService.java +++ b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/QuarkusConfigurationService.java @@ -6,6 +6,7 @@ import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.Version; import io.quarkus.arc.runtime.ClientProxyUnwrapper; import java.util.List; @@ -14,7 +15,8 @@ public class QuarkusConfigurationService extends AbstractConfigurationService { private final KubernetesClient client; public QuarkusConfigurationService( - List configurations, KubernetesClient client) { + Version version, List configurations, KubernetesClient client) { + super(version); this.client = client; if (configurations != null && !configurations.isEmpty()) { configurations.forEach(this::register); diff --git a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java new file mode 100644 index 0000000000..77acba70a7 --- /dev/null +++ b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java @@ -0,0 +1,13 @@ +package io.javaoperatorsdk.quarkus.extension; + +import io.quarkus.runtime.annotations.RecordableConstructor; +import java.util.Date; + +/** Re-publish with a recordable constructor so that quarkus can do its thing with it! */ +public class Version extends io.javaoperatorsdk.operator.api.config.Version { + + @RecordableConstructor + public Version(String project, String commit, Date builtTime) { + super(project, commit, builtTime); + } +} diff --git a/operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java b/operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java index 4a8455b69a..ad6f118aa5 100644 --- a/operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java +++ b/operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java @@ -11,6 +11,7 @@ import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; import io.javaoperatorsdk.operator.api.config.RetryConfiguration; +import io.javaoperatorsdk.operator.api.config.Utils; import io.javaoperatorsdk.operator.config.runtime.AnnotationConfiguration; import java.util.List; import java.util.Optional; @@ -26,6 +27,10 @@ public class OperatorAutoConfiguration extends AbstractConfigurationService { @Autowired private OperatorConfigurationProperties configuration; + public OperatorAutoConfiguration() { + super(Utils.loadFromProperties()); + } + @Bean @ConditionalOnMissingBean public KubernetesClient kubernetesClient() { 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 cadc69b701..73a232c45d 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 @@ -5,11 +5,16 @@ import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.config.Utils; public class DefaultConfigurationService extends AbstractConfigurationService { private static final ConfigurationService instance = new DefaultConfigurationService(); + private DefaultConfigurationService() { + super(Utils.loadFromProperties()); + } + public static ConfigurationService instance() { return instance; } From 4eb057b279a3911f0b131c13824a366d77a200be Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 21:57:37 +0100 Subject: [PATCH 05/18] feat: add start method as entrypoint and output version information Fixes #313 Fixes #314 --- .../main/java/io/javaoperatorsdk/operator/Operator.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 7501c29bc5..28e2dff96c 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 @@ -28,6 +28,15 @@ public Operator(KubernetesClient k8sClient, ConfigurationService configurationSe this.configurationService = configurationService; } + public void start() { + final var version = configurationService.getVersion(); + log.info( + "Operator {} (commit: {}) built on {} starting…", + version.getProject(), + version.getCommit(), + version.getBuiltTime()); + } + public void register(ResourceController controller) throws OperatorException { register(controller, null); From f278c8ffb3704db5ade495ff90feb817b134bc25 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 21:59:39 +0100 Subject: [PATCH 06/18] feat: skip controller registration if CRD is not present on cluster Fixes #315 --- .../io/javaoperatorsdk/operator/Operator.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 28e2dff96c..735f74fcc6 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 @@ -67,9 +67,23 @@ public void register( new EventDispatcher( controller, finalizer, new EventDispatcher.CustomResourceFacade(client)); + // check that the custom resource is known by the cluster + final var crdName = configuration.getCRDName(); + final var crd = + k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get(); + final var controllerName = configuration.getName(); + if (crd == null) { + log.warn( + "'{}' CRD was not found on the {} cluster, skipping '{}' controller registration", + crdName, + configurationService.getClientConfiguration().getMasterUrl(), + controllerName); + return; + } + CustomResourceCache customResourceCache = new CustomResourceCache(); DefaultEventHandler defaultEventHandler = - new DefaultEventHandler(customResourceCache, dispatcher, configuration.getName(), retry); + new DefaultEventHandler(customResourceCache, dispatcher, controllerName, retry); DefaultEventSourceManager eventSourceManager = new DefaultEventSourceManager(defaultEventHandler, retry != null); defaultEventHandler.setEventSourceManager(eventSourceManager); From 2db6b5fd9ffa7c66dcc8e94f2f7bcc0af1d237e9 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 22 Jan 2021 22:22:55 +0100 Subject: [PATCH 07/18] fix: date format parser --- operator-framework-core/pom.xml | 1 + .../java/io/javaoperatorsdk/operator/api/config/Utils.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index a08f6227ec..43d3f95758 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -29,6 +29,7 @@ ${surefire.version} + pl.project13.maven git-commit-id-plugin 4.0.3 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 8e82a53fd7..f36fddb21c 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 @@ -1,8 +1,8 @@ package io.javaoperatorsdk.operator.api.config; import java.io.IOException; -import java.text.DateFormat; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.Instant; import java.util.Date; import java.util.Properties; @@ -21,7 +21,10 @@ public static Version loadFromProperties() { Date builtTime; try { - builtTime = DateFormat.getDateTimeInstance().parse(properties.getProperty("git.build.time")); + 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")); } catch (ParseException e) { builtTime = Date.from(Instant.EPOCH); } From 042d1e4422ddf496e21d80fc6fd334a3ede0f9ce Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Sat, 23 Jan 2021 00:34:21 +0100 Subject: [PATCH 08/18] fix: use finalizer and deletion marker methods from HasMetadata Fixes #317 --- .../operator/ControllerUtils.java | 6 ---- .../operator/processing/EventDispatcher.java | 28 ++++--------------- .../processing/KubernetesResourceUtils.java | 6 ---- .../internal/CustomResourceEventSource.java | 6 ++-- .../operator/EventDispatcherTest.java | 2 +- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java index 287312d0e6..55cbe9d6f6 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java @@ -1,6 +1,5 @@ package io.javaoperatorsdk.operator; -import io.fabric8.kubernetes.client.CustomResource; import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.ResourceController; import java.util.Locale; @@ -13,11 +12,6 @@ public static String getDefaultFinalizerName(String crdName) { return crdName + FINALIZER_NAME_SUFFIX; } - public static boolean hasGivenFinalizer(CustomResource resource, String finalizer) { - return resource.getMetadata().getFinalizers() != null - && resource.getMetadata().getFinalizers().contains(finalizer); - } - public static String getNameFor(Class controllerClass) { // if the controller annotation has a name attribute, use it final var annotation = controllerClass.getAnnotation(Controller.class); 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 a440a841e2..d79f8677f5 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 @@ -3,13 +3,11 @@ import static io.javaoperatorsdk.operator.EventListUtils.containsCustomResourceDeletedEvent; import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID; import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.markedForDeletion; import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.javaoperatorsdk.operator.ControllerUtils; import io.javaoperatorsdk.operator.api.Context; import io.javaoperatorsdk.operator.api.DefaultContext; import io.javaoperatorsdk.operator.api.DeleteControl; @@ -17,7 +15,6 @@ import io.javaoperatorsdk.operator.api.UpdateControl; import io.javaoperatorsdk.operator.processing.event.EventList; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; -import java.util.ArrayList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,8 +62,7 @@ private PostExecutionControl handleDispatch(ExecutionScope executionScope) { getVersion(resource)); return PostExecutionControl.defaultDispatch(); } - if ((markedForDeletion(resource) - && !ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer))) { + if ((resource.isMarkedForDeletion() && !resource.hasFinalizer(resourceFinalizer))) { log.debug( "Skipping event dispatching since its marked for deletion but has no finalizer: {}", executionScope); @@ -77,7 +73,7 @@ private PostExecutionControl handleDispatch(ExecutionScope executionScope) { eventSourceManager, new EventList(executionScope.getEvents()), executionScope.getRetryInfo()); - if (markedForDeletion(resource)) { + if (resource.isMarkedForDeletion()) { return handleDelete(resource, context); } else { return handleCreateOrUpdate(executionScope, resource, context); @@ -86,8 +82,7 @@ private PostExecutionControl handleDispatch(ExecutionScope executionScope) { private PostExecutionControl handleCreateOrUpdate( ExecutionScope executionScope, CustomResource resource, Context context) { - if (!ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer) - && !markedForDeletion(resource)) { + if (!resource.hasFinalizer(resourceFinalizer) && !resource.isMarkedForDeletion()) { /* We always add the finalizer if missing and not marked for deletion. We execute the controller processing only for processing the event sent as a results of the finalizer add. This will make sure that the resources are not created before @@ -133,7 +128,7 @@ private PostExecutionControl handleDelete(CustomResource resource, Context conte getUID(resource), getVersion(resource)); DeleteControl deleteControl = controller.deleteResource(resource, context); - boolean hasFinalizer = ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer); + boolean hasFinalizer = resource.hasFinalizer(resourceFinalizer); if (deleteControl == DeleteControl.DEFAULT_DELETE && hasFinalizer) { CustomResource customResource = removeFinalizer(resource); return PostExecutionControl.customResourceUpdated(customResource); @@ -151,7 +146,7 @@ private PostExecutionControl handleDelete(CustomResource resource, Context conte private void updateCustomResourceWithFinalizer(CustomResource resource) { log.debug( "Adding finalizer for resource: {} version: {}", getUID(resource), getVersion(resource)); - addFinalizerIfNotPresent(resource); + resource.addFinalizer(resourceFinalizer); replace(resource); } @@ -166,7 +161,7 @@ private CustomResource removeFinalizer(CustomResource resource) { "Removing finalizer on resource: {} with version: {}", getUID(resource), getVersion(resource)); - resource.getMetadata().getFinalizers().remove(resourceFinalizer); + resource.removeFinalizer(resourceFinalizer); return customResourceFacade.replaceWithLock(resource); } @@ -178,17 +173,6 @@ private CustomResource replace(CustomResource resource) { return customResourceFacade.replaceWithLock(resource); } - private void addFinalizerIfNotPresent(CustomResource resource) { - if (!ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer) - && !markedForDeletion(resource)) { - log.info("Adding finalizer to {}", resource.getMetadata()); - if (resource.getMetadata().getFinalizers() == null) { - resource.getMetadata().setFinalizers(new ArrayList<>(1)); - } - resource.getMetadata().getFinalizers().add(resourceFinalizer); - } - } - // created to support unit testing public static class CustomResourceFacade { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/KubernetesResourceUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/KubernetesResourceUtils.java index 2fd434ce5f..7f617e9705 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/KubernetesResourceUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/KubernetesResourceUtils.java @@ -1,7 +1,6 @@ package io.javaoperatorsdk.operator.processing; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.CustomResource; public class KubernetesResourceUtils { @@ -12,9 +11,4 @@ public static String getUID(HasMetadata customResource) { public static String getVersion(HasMetadata customResource) { return customResource.getMetadata().getResourceVersion(); } - - public static boolean markedForDeletion(CustomResource resource) { - return resource.getMetadata().getDeletionTimestamp() != null - && !resource.getMetadata().getDeletionTimestamp().isEmpty(); - } } 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 c8d13a4d4b..55ed716c45 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 @@ -2,14 +2,12 @@ import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID; import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; -import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.markedForDeletion; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.WatcherException; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl; -import io.javaoperatorsdk.operator.ControllerUtils; import io.javaoperatorsdk.operator.processing.CustomResourceCache; import io.javaoperatorsdk.operator.processing.KubernetesResourceUtils; import io.javaoperatorsdk.operator.processing.event.AbstractEventSource; @@ -115,7 +113,7 @@ public void eventReceived(Watcher.Action action, CustomResource customResource) } private void markLastGenerationProcessed(CustomResource resource) { - if (generationAware && ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer)) { + if (generationAware && resource.hasFinalizer(resourceFinalizer)) { lastGenerationProcessedSuccessfully.put( KubernetesResourceUtils.getUID(resource), resource.getMetadata().getGeneration()); } @@ -126,7 +124,7 @@ private boolean skipBecauseOfGenerations(CustomResource customResource) { return false; } // if CR being deleted generation is naturally not changing, so we process all the events - if (markedForDeletion(customResource)) { + if (customResource.isMarkedForDeletion()) { return false; } if (!largerGenerationThenProcessedBefore(customResource)) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/EventDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/EventDispatcherTest.java index 2a8bd942ea..643bb5bab3 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/EventDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/EventDispatcherTest.java @@ -33,7 +33,7 @@ class EventDispatcherTest { - private static final String DEFAULT_FINALIZER = "finalizer"; + private static final String DEFAULT_FINALIZER = "javaoperatorsdk.io/finalizer"; private CustomResource testCustomResource; private EventDispatcher eventDispatcher; private ResourceController controller = mock(ResourceController.class); From b791c4e4122193a617d9986b102aa188397ec8c3 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 15:52:29 +0100 Subject: [PATCH 09/18] fix: Controller annotation is not mandatory for default configuration --- .../config/runtime/AnnotationConfiguration.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 cce8ac1622..0f075dd266 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 @@ -5,17 +5,18 @@ import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; +import java.util.Optional; import java.util.Set; public class AnnotationConfiguration implements ControllerConfiguration { private final ResourceController controller; - private final Controller annotation; + private final Optional annotation; public AnnotationConfiguration(ResourceController controller) { this.controller = controller; - this.annotation = controller.getClass().getAnnotation(Controller.class); + this.annotation = Optional.ofNullable(controller.getClass().getAnnotation(Controller.class)); } @Override @@ -30,16 +31,13 @@ public String getCRDName() { @Override public String getFinalizer() { - final String annotationFinalizerName = annotation.finalizerName(); - if (!Controller.NULL.equals(annotationFinalizerName)) { - return annotationFinalizerName; - } - return ControllerUtils.getDefaultFinalizerName(getCRDName()); + return annotation.map(Controller::finalizerName).filter(String::isBlank) + .orElse(ControllerUtils.getDefaultFinalizerName(getCRDName())); } @Override public boolean isGenerationAware() { - return annotation.generationAwareEventProcessing(); + return annotation.map(Controller::generationAwareEventProcessing).orElse(true); } @Override @@ -49,7 +47,7 @@ public Class getCustomResourceClass() { @Override public Set getNamespaces() { - return Set.of(annotation.namespaces()); + return Set.of(annotation.map(Controller::namespaces).orElse(new String[]{})); } @Override From 9edcde971db4e4af536003e512bdc2f519e2d39f Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 15:56:17 +0100 Subject: [PATCH 10/18] feat: use Operator.start() --- .../operator/sample/QuarkusOperator.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/samples/quarkus/src/main/java/io/javaoperatorsdk/operator/sample/QuarkusOperator.java b/samples/quarkus/src/main/java/io/javaoperatorsdk/operator/sample/QuarkusOperator.java index 1c0f01953b..9d56fd27ef 100644 --- a/samples/quarkus/src/main/java/io/javaoperatorsdk/operator/sample/QuarkusOperator.java +++ b/samples/quarkus/src/main/java/io/javaoperatorsdk/operator/sample/QuarkusOperator.java @@ -1,8 +1,6 @@ package io.javaoperatorsdk.operator.sample; -import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.Operator; -import io.javaoperatorsdk.operator.api.config.ConfigurationService; import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.QuarkusApplication; import io.quarkus.runtime.annotations.QuarkusMain; @@ -11,22 +9,15 @@ @QuarkusMain public class QuarkusOperator implements QuarkusApplication { - @Inject KubernetesClient client; - @Inject Operator operator; - @Inject ConfigurationService configuration; - - @Inject CustomServiceController controller; - public static void main(String... args) { Quarkus.run(QuarkusOperator.class, args); } @Override public int run(String... args) throws Exception { - final var config = configuration.getConfigurationFor(controller); - System.out.println("CR class: " + config.getCustomResourceClass()); + operator.start(); Quarkus.waitForExit(); return 0; } From 538e46834d51b9430fe33dad8297a32f77d579b2 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 16:26:16 +0100 Subject: [PATCH 11/18] fix: log warning if version.properties cannot be found --- .../operator/api/config/Utils.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 f36fddb21c..4cac15b099 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 @@ -6,17 +6,26 @@ import java.time.Instant; import java.util.Date; import java.util.Properties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Utils { + private static final Logger log = LoggerFactory.getLogger(Utils.class); + public static Version loadFromProperties() { final var is = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); + final var properties = new Properties(); - try { - properties.load(is); - } catch (IOException e) { - e.printStackTrace(); + if(is != null) { + try { + properties.load(is); + } catch (IOException e) { + log.warn("Couldn't load version information: {}", e.getMessage()); + } + } else { + log.warn("Couldn't find version.properties file. Default version information will be used."); } Date builtTime; From 9c0ccbde516cad62b3aadbccfc195840693d7c39 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 16:53:36 +0100 Subject: [PATCH 12/18] docs: add some javadocs --- .../io/javaoperatorsdk/operator/Operator.java | 24 ++++++++++++++++++ .../api/config/ConfigurationService.java | 25 +++++++++++++++++++ .../operator/api/config/Utils.java | 8 +++++- .../operator/api/config/Version.java | 18 +++++++++++++ .../runtime/AnnotationConfiguration.java | 6 +++-- 5 files changed, 78 insertions(+), 3 deletions(-) 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 735f74fcc6..1139e78a51 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 @@ -28,6 +28,11 @@ public Operator(KubernetesClient k8sClient, ConfigurationService configurationSe this.configurationService = configurationService; } + /** + * 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 + * and start the cluster monitoring processes. + */ public void start() { final var version = configurationService.getVersion(); log.info( @@ -37,11 +42,30 @@ public void start() { version.getBuiltTime()); } + /** + * Registers the specified controller with this operator. + * + * @param controller the controller to register + * @param the {@code CustomResource} type associated with the controller + * @throws OperatorException if a problem occurred during the registration process + */ public void register(ResourceController controller) throws OperatorException { register(controller, null); } + /** + * Registers the specified controller with this operator, overriding its default configuration by + * the specified one (usually created via {@link + * io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)}, + * passing it the controller's original configuration. + * + * @param controller the controller to register + * @param configuration the configuration with which we want to register the controller, if {@code + * null}, the controller's orginal configuration is used + * @param the {@code CustomResource} type associated with the controller + * @throws OperatorException if a problem occurred during the registration process + */ public void register( ResourceController controller, ControllerConfiguration configuration) throws OperatorException { 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 51d0c853c2..820d1abb28 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 @@ -5,16 +5,41 @@ import io.javaoperatorsdk.operator.api.ResourceController; import java.util.Set; +/** An interface from which to retrieve configuration information. */ public interface ConfigurationService { + /** + * Retrieves the configuration associated with the specified controller + * + * @param controller the controller we want the configuration of + * @param the {@code CustomResource} type associated with the specified controller + * @return the {@link ControllerConfiguration} associated with the specified controller or {@code + * null} if no configuration exists for the controller + */ ControllerConfiguration getConfigurationFor( ResourceController controller); + /** + * Retrieves the Kubernetes client configuration + * + * @return the configuration of the Kubernetes client, defaulting to the provided + * auto-configuration + */ default Config getClientConfiguration() { return Config.autoConfigure(null); } + /** + * Retrieves the set of the names of controllers for which a configuration exists + * + * @return the set of known controller names + */ Set getKnownControllerNames(); + /** + * Retrieves the {@link Version} information associated with this particular instance of the SDK + * + * @return the version information + */ Version getVersion(); } 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 4cac15b099..442b7d47fa 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 @@ -13,12 +13,18 @@ public class Utils { private static final Logger log = LoggerFactory.getLogger(Utils.class); + /** + * Attempts to load version information from a properties file produced at build time, currently + * via the {@code git-commit-id-plugin} maven plugin. + * + * @return a {@link Version} object encapsulating the version information + */ public static Version loadFromProperties() { final var is = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); final var properties = new Properties(); - if(is != null) { + if (is != null) { try { properties.load(is); } catch (IOException e) { 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 9d7d0f8c7d..72e63443b9 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 @@ -2,7 +2,9 @@ import java.util.Date; +/** A class encapsulating the version information associated with this SDK instance. */ public class Version { + private final String project; private final String commit; private final Date builtTime; @@ -13,14 +15,30 @@ public Version(String project, String commit, Date builtTime) { this.builtTime = builtTime; } + /** + * Returns the SDK project version + * + * @return the SDK project version + */ public String getProject() { return project; } + /** + * Returns the git commit id associated with this SDK instance + * + * @return the git commit id + */ public String getCommit() { return commit; } + /** + * Returns the date at which this SDK instance was built + * + * @return the build time at which this SDK instance was built or the date corresponding to {@link + * java.time.Instant#EPOCH} if the built time couldn't be retrieved + */ public Date getBuiltTime() { return builtTime; } 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 0f075dd266..7e04ba4b44 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 @@ -31,7 +31,9 @@ public String getCRDName() { @Override public String getFinalizer() { - return annotation.map(Controller::finalizerName).filter(String::isBlank) + return annotation + .map(Controller::finalizerName) + .filter(String::isBlank) .orElse(ControllerUtils.getDefaultFinalizerName(getCRDName())); } @@ -47,7 +49,7 @@ public Class getCustomResourceClass() { @Override public Set getNamespaces() { - return Set.of(annotation.map(Controller::namespaces).orElse(new String[]{})); + return Set.of(annotation.map(Controller::namespaces).orElse(new String[] {})); } @Override From b9987a74c62c84a59c07f1344cce26771eb1c07b Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 17:49:27 +0100 Subject: [PATCH 13/18] fix: controllers need to be annotated with @Controller The reason for this is that the default configuration service relies on these annotations to be present to do its work. Note: Quarkus applications don't need to be annotated if no changes to the default configuration is needed. --- .../io/javaoperatorsdk/operator/sample/SchemaController.java | 2 ++ .../io/javaoperatorsdk/operator/sample/TomcatController.java | 2 ++ .../io/javaoperatorsdk/operator/sample/WebappController.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/samples/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaController.java b/samples/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaController.java index 26688ff520..4367333ed4 100644 --- a/samples/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaController.java +++ b/samples/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/SchemaController.java @@ -6,6 +6,7 @@ import io.fabric8.kubernetes.api.model.SecretBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.Context; +import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.DeleteControl; import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.UpdateControl; @@ -20,6 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Controller public class SchemaController implements ResourceController { static final String USERNAME_FORMAT = "%s-user"; static final String SECRET_FORMAT = "%s-secret"; diff --git a/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/TomcatController.java b/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/TomcatController.java index c2326e0b53..7fbf54109d 100644 --- a/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/TomcatController.java +++ b/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/TomcatController.java @@ -10,6 +10,7 @@ import io.fabric8.kubernetes.client.dsl.ServiceResource; import io.fabric8.kubernetes.client.utils.Serialization; import io.javaoperatorsdk.operator.api.Context; +import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.DeleteControl; import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.UpdateControl; @@ -23,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Controller public class TomcatController implements ResourceController { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/WebappController.java b/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/WebappController.java index de32c66fca..b2e4330d5b 100644 --- a/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/WebappController.java +++ b/samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/WebappController.java @@ -4,6 +4,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.Context; +import io.javaoperatorsdk.operator.api.Controller; import io.javaoperatorsdk.operator.api.DeleteControl; import io.javaoperatorsdk.operator.api.ResourceController; import io.javaoperatorsdk.operator.api.UpdateControl; @@ -15,6 +16,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Controller public class WebappController implements ResourceController { private KubernetesClient kubernetesClient; From 09ce8892b2236b3235bd2fd31273d056e3fce36a Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 17:59:34 +0100 Subject: [PATCH 14/18] =?UTF-8?q?fix:=20only=20keep=20**not**=20blank=20fi?= =?UTF-8?q?nalizer,=20not=20blank=20ones=E2=80=A6=20:facepalm:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operator/config/runtime/AnnotationConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 7e04ba4b44..bc2c13ace8 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 @@ -7,6 +7,7 @@ import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; import java.util.Optional; import java.util.Set; +import java.util.function.Predicate; public class AnnotationConfiguration implements ControllerConfiguration { @@ -33,7 +34,7 @@ public String getCRDName() { public String getFinalizer() { return annotation .map(Controller::finalizerName) - .filter(String::isBlank) + .filter(Predicate.not(String::isBlank)) .orElse(ControllerUtils.getDefaultFinalizerName(getCRDName())); } From 6cde0bea9add8bafed4818c5558b0db9375bfbe8 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 19:26:33 +0100 Subject: [PATCH 15/18] feat: throw an explicit exception if CRD is not found Fail fast when the CRD is not found instead of letting watchers throw a cryptic exception based on PR discussion. Fixes #315 --- .../io/javaoperatorsdk/operator/Operator.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) 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 1139e78a51..cff5553794 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 @@ -46,7 +46,7 @@ public void start() { * Registers the specified controller with this operator. * * @param controller the controller to register - * @param the {@code CustomResource} type associated with the controller + * @param the {@code CustomResource} type associated with the controller * @throws OperatorException if a problem occurred during the registration process */ public void register(ResourceController controller) @@ -56,14 +56,13 @@ public void register(ResourceController controller /** * Registers the specified controller with this operator, overriding its default configuration by - * the specified one (usually created via {@link - * io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)}, + * the specified one (usually created via {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)}, * passing it the controller's original configuration. * - * @param controller the controller to register + * @param controller the controller to register * @param configuration the configuration with which we want to register the controller, if {@code - * null}, the controller's orginal configuration is used - * @param the {@code CustomResource} type associated with the controller + * null}, the controller's orginal configuration is used + * @param the {@code CustomResource} type associated with the controller * @throws OperatorException if a problem occurred during the registration process */ public void register( @@ -83,7 +82,7 @@ public void register( } final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration()); - final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {}); + final var targetNamespaces = configuration.getNamespaces().toArray(new String[]{}); Class resClass = configuration.getCustomResourceClass(); String finalizer = configuration.getFinalizer(); final var client = k8sClient.customResources(resClass); @@ -97,12 +96,9 @@ public void register( k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get(); final var controllerName = configuration.getName(); if (crd == null) { - log.warn( - "'{}' CRD was not found on the {} cluster, skipping '{}' controller registration", - crdName, - configurationService.getClientConfiguration().getMasterUrl(), - controllerName); - return; + throw new OperatorException( + "'" + crdName + "' CRD was not found on the cluster, controller " + + controllerName + " cannot be registered"); } CustomResourceCache customResourceCache = new CustomResourceCache(); @@ -145,7 +141,7 @@ private CustomResourceEventSource createCustomResourceEventSource( CustomResourceEventSource customResourceEventSource = watchAllNamespaces ? CustomResourceEventSource.customResourceEventSourceForAllNamespaces( - customResourceCache, client, generationAware, finalizer) + customResourceCache, client, generationAware, finalizer) : CustomResourceEventSource.customResourceEventSourceForTargetNamespaces( customResourceCache, client, targetNamespaces, generationAware, finalizer); From ebb453e61b62085fdcf5da5c2b7dbcadce66aa5a Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 25 Jan 2021 20:55:10 +0100 Subject: [PATCH 16/18] fix: format --- .../io/javaoperatorsdk/operator/Operator.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 cff5553794..a215f49ac4 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 @@ -46,7 +46,7 @@ public void start() { * Registers the specified controller with this operator. * * @param controller the controller to register - * @param the {@code CustomResource} type associated with the controller + * @param the {@code CustomResource} type associated with the controller * @throws OperatorException if a problem occurred during the registration process */ public void register(ResourceController controller) @@ -56,13 +56,14 @@ public void register(ResourceController controller /** * Registers the specified controller with this operator, overriding its default configuration by - * the specified one (usually created via {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)}, + * the specified one (usually created via {@link + * io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)}, * passing it the controller's original configuration. * - * @param controller the controller to register + * @param controller the controller to register * @param configuration the configuration with which we want to register the controller, if {@code - * null}, the controller's orginal configuration is used - * @param the {@code CustomResource} type associated with the controller + * null}, the controller's orginal configuration is used + * @param the {@code CustomResource} type associated with the controller * @throws OperatorException if a problem occurred during the registration process */ public void register( @@ -82,7 +83,7 @@ public void register( } final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration()); - final var targetNamespaces = configuration.getNamespaces().toArray(new String[]{}); + final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {}); Class resClass = configuration.getCustomResourceClass(); String finalizer = configuration.getFinalizer(); final var client = k8sClient.customResources(resClass); @@ -97,8 +98,11 @@ public void register( final var controllerName = configuration.getName(); if (crd == null) { throw new OperatorException( - "'" + crdName + "' CRD was not found on the cluster, controller " - + controllerName + " cannot be registered"); + "'" + + crdName + + "' CRD was not found on the cluster, controller " + + controllerName + + " cannot be registered"); } CustomResourceCache customResourceCache = new CustomResourceCache(); @@ -141,7 +145,7 @@ private CustomResourceEventSource createCustomResourceEventSource( CustomResourceEventSource customResourceEventSource = watchAllNamespaces ? CustomResourceEventSource.customResourceEventSourceForAllNamespaces( - customResourceCache, client, generationAware, finalizer) + customResourceCache, client, generationAware, finalizer) : CustomResourceEventSource.customResourceEventSourceForTargetNamespaces( customResourceCache, client, targetNamespaces, generationAware, finalizer); From d4d48cdf7cf0c61dd355ddb98700a8c792cb6375 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 26 Jan 2021 12:52:22 +0100 Subject: [PATCH 17/18] fix: replace ellipsis by ... for greater compatibility --- .../src/main/java/io/javaoperatorsdk/operator/Operator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a215f49ac4..c245ca6bf3 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 @@ -36,7 +36,7 @@ public Operator(KubernetesClient k8sClient, ConfigurationService configurationSe public void start() { final var version = configurationService.getVersion(); log.info( - "Operator {} (commit: {}) built on {} starting…", + "Operator {} (commit: {}) built on {} starting...", version.getProject(), version.getCommit(), version.getBuiltTime()); From 7608163fe1ee3fcc6dbb29b58216ffca81724547 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Tue, 26 Jan 2021 13:10:46 +0100 Subject: [PATCH 18/18] fix: rename getProject to getSdkVersion for greater clarity Note that the rename trickles down to several spots because Quarkus' @RecordableConstructor is sensitive to parameter names: the parameter names used in the constructor must match an existing getter. --- .../java/io/javaoperatorsdk/operator/Operator.java | 2 +- .../javaoperatorsdk/operator/api/config/Version.java | 10 +++++----- .../deployment/QuarkusExtensionProcessor.java | 2 +- .../io/javaoperatorsdk/quarkus/extension/Version.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) 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 c245ca6bf3..5045eeddcf 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 @@ -37,7 +37,7 @@ public void start() { final var version = configurationService.getVersion(); log.info( "Operator {} (commit: {}) built on {} starting...", - version.getProject(), + version.getSdkVersion(), version.getCommit(), version.getBuiltTime()); } 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 72e63443b9..6af60412b4 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 @@ -5,12 +5,12 @@ /** A class encapsulating the version information associated with this SDK instance. */ public class Version { - private final String project; + private final String sdk; private final String commit; private final Date builtTime; - public Version(String project, String commit, Date builtTime) { - this.project = project; + public Version(String sdkVersion, String commit, Date builtTime) { + this.sdk = sdkVersion; this.commit = commit; this.builtTime = builtTime; } @@ -20,8 +20,8 @@ public Version(String project, String commit, Date builtTime) { * * @return the SDK project version */ - public String getProject() { - return project; + public String getSdkVersion() { + return sdk; } /** diff --git a/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java b/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java index 2b9022521d..126ef44446 100644 --- a/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java +++ b/operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java @@ -85,7 +85,7 @@ void createConfigurationServiceAndOperator( final var supplier = recorder.configurationServiceSupplier( - new Version(version.getProject(), version.getCommit(), version.getBuiltTime()), + new Version(version.getSdkVersion(), version.getCommit(), version.getBuiltTime()), controllerConfigs); syntheticBeanBuildItemBuildProducer.produce( SyntheticBeanBuildItem.configure(QuarkusConfigurationService.class) diff --git a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java index 77acba70a7..354d7628cf 100644 --- a/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java +++ b/operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/Version.java @@ -7,7 +7,7 @@ public class Version extends io.javaoperatorsdk.operator.api.config.Version { @RecordableConstructor - public Version(String project, String commit, Date builtTime) { - super(project, commit, builtTime); + public Version(String sdkVersion, String commit, Date builtTime) { + super(sdkVersion, commit, builtTime); } }