From 0b82696aa6ab0133ed0c5551653f221b11e3cc89 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 03:22:10 +0000 Subject: [PATCH 1/3] chore(deps): bump formatter-maven-plugin from 2.17.1 to 2.18.0 Bumps [formatter-maven-plugin](https://github.com/revelc/formatter-maven-plugin) from 2.17.1 to 2.18.0. - [Release notes](https://github.com/revelc/formatter-maven-plugin/releases) - [Changelog](https://github.com/revelc/formatter-maven-plugin/blob/main/CHANGELOG.md) - [Commits](https://github.com/revelc/formatter-maven-plugin/compare/formatter-maven-plugin-2.17.1...formatter-maven-plugin-2.18.0) --- updated-dependencies: - dependency-name: net.revelc.code.formatter:formatter-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dfca9ec391..5412cfac2a 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 2.8.2 2.5.2 5.0.0 - 2.17.1 + 2.18.0 1.0 1.6.2 From 7bc49ebdb5921a6982250fb354756255460b401b Mon Sep 17 00:00:00 2001 From: csviri Date: Thu, 3 Mar 2022 09:39:12 +0100 Subject: [PATCH 2/3] fix: fomatted --- .../api/config/ConfigurationService.java | 2 +- .../api/reconciler/EventSourceContext.java | 4 +- .../source/informer/InformerEventSource.java | 131 ++++++++++-------- .../source/polling/PollingEventSource.java | 45 +++--- 4 files changed, 99 insertions(+), 83 deletions(-) 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 2e4679efd3..49ccc1da07 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 @@ -92,7 +92,7 @@ default int concurrentReconciliationThreads() { /** * Used to clone custom resources. - * + * * @return the ObjectMapper to use */ default Cloner getResourceCloner() { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java index 0a93d33d40..ba32f493ec 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java @@ -39,7 +39,7 @@ public ResourceCache

getPrimaryCache() { * {@link io.javaoperatorsdk.operator.api.monitoring.Metrics} or * {@link io.javaoperatorsdk.operator.api.config.Cloner} implementations, which could be useful to * event sources. - * + * * @return the {@link ConfigurationService} associated with the operator */ public ConfigurationService getConfigurationService() { @@ -49,7 +49,7 @@ public ConfigurationService getConfigurationService() { /** * Provides access to the {@link KubernetesClient} used by the current * {@link io.javaoperatorsdk.operator.Operator} instance. - * + * * @return the {@link KubernetesClient} used by the current * {@link io.javaoperatorsdk.operator.Operator} instance. */ diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java index eada096713..95ed3b6ef0 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java @@ -22,8 +22,7 @@ import io.javaoperatorsdk.operator.processing.event.source.ResourceCache; public class InformerEventSource - extends AbstractResourceEventSource - implements ResourceCache { + extends AbstractResourceEventSource implements ResourceCache { private static final Logger log = LoggerFactory.getLogger(InformerEventSource.class); @@ -32,33 +31,46 @@ public class InformerEventSource private final AssociatedSecondaryResourceIdentifier

associatedWith; private final boolean skipUpdateEventPropagationIfNoChange; - public InformerEventSource(SharedInformer sharedInformer, + public InformerEventSource( + SharedInformer sharedInformer, PrimaryResourcesRetriever resourceToTargetResourceIDSet) { this(sharedInformer, resourceToTargetResourceIDSet, null, true); } - public InformerEventSource(KubernetesClient client, Class type, + public InformerEventSource( + KubernetesClient client, + Class type, PrimaryResourcesRetriever resourceToTargetResourceIDSet) { this(client, type, resourceToTargetResourceIDSet, false); } - public InformerEventSource(KubernetesClient client, Class type, + public InformerEventSource( + KubernetesClient client, + Class type, PrimaryResourcesRetriever resourceToTargetResourceIDSet, AssociatedSecondaryResourceIdentifier

associatedWith, boolean skipUpdateEventPropagationIfNoChange) { - this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet, + this( + client.informers().sharedIndexInformerFor(type, 0), + resourceToTargetResourceIDSet, associatedWith, skipUpdateEventPropagationIfNoChange); } - InformerEventSource(KubernetesClient client, Class type, + InformerEventSource( + KubernetesClient client, + Class type, PrimaryResourcesRetriever resourceToTargetResourceIDSet, boolean skipUpdateEventPropagationIfNoChange) { - this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet, null, + this( + client.informers().sharedIndexInformerFor(type, 0), + resourceToTargetResourceIDSet, + null, skipUpdateEventPropagationIfNoChange); } - public InformerEventSource(SharedInformer sharedInformer, + public InformerEventSource( + SharedInformer sharedInformer, PrimaryResourcesRetriever resourceToTargetResourceIDSet, AssociatedSecondaryResourceIdentifier

associatedWith, boolean skipUpdateEventPropagationIfNoChange) { @@ -68,41 +80,44 @@ public InformerEventSource(SharedInformer sharedInformer, this.skipUpdateEventPropagationIfNoChange = skipUpdateEventPropagationIfNoChange; if (sharedInformer.isRunning()) { log.warn( - "Informer is already running on event source creation, this is not desirable and may " + - "lead to non deterministic behavior."); + "Informer is already running on event source creation, this is not desirable and may " + + "lead to non deterministic behavior."); } this.associatedWith = Objects.requireNonNullElseGet(associatedWith, () -> ResourceID::fromResource); - sharedInformer.addEventHandler(new ResourceEventHandler<>() { - @Override - public void onAdd(T t) { - propagateEvent(t); - } - - @Override - public void onUpdate(T oldObject, T newObject) { - if (newObject == null) { - // this is a fix for this potential issue with informer: - // https://github.com/java-operator-sdk/java-operator-sdk/issues/830 - propagateEvent(oldObject); - return; - } - - if (InformerEventSource.this.skipUpdateEventPropagationIfNoChange && - oldObject.getMetadata().getResourceVersion() - .equals(newObject.getMetadata().getResourceVersion())) { - return; - } - propagateEvent(newObject); - } - - @Override - public void onDelete(T t, boolean b) { - propagateEvent(t); - } - }); + sharedInformer.addEventHandler( + new ResourceEventHandler<>() { + @Override + public void onAdd(T t) { + propagateEvent(t); + } + + @Override + public void onUpdate(T oldObject, T newObject) { + if (newObject == null) { + // this is a fix for this potential issue with informer: + // https://github.com/java-operator-sdk/java-operator-sdk/issues/830 + propagateEvent(oldObject); + return; + } + + if (InformerEventSource.this.skipUpdateEventPropagationIfNoChange + && oldObject + .getMetadata() + .getResourceVersion() + .equals(newObject.getMetadata().getResourceVersion())) { + return; + } + propagateEvent(newObject); + } + + @Override + public void onDelete(T t, boolean b) { + propagateEvent(t); + } + }); } private void propagateEvent(T object) { @@ -110,18 +125,19 @@ private void propagateEvent(T object) { if (primaryResourceIdSet.isEmpty()) { return; } - primaryResourceIdSet.forEach(resourceId -> { - Event event = new Event(resourceId); - /* - * In fabric8 client for certain cases informers can be created on in a way that they are - * automatically started, what would cause a NullPointerException here, since an event might - * be received between creation and registration. - */ - final EventHandler eventHandler = getEventHandler(); - if (eventHandler != null) { - eventHandler.handleEvent(event); - } - }); + primaryResourceIdSet.forEach( + resourceId -> { + Event event = new Event(resourceId); + /* + * In fabric8 client for certain cases informers can be created on in a way that they are + * automatically started, what would cause a NullPointerException here, since an event + * might be received between creation and registration. + */ + final EventHandler eventHandler = getEventHandler(); + if (eventHandler != null) { + eventHandler.handleEvent(event); + } + }); } @Override @@ -141,7 +157,7 @@ private Store getStore() { /** * Retrieves the informed resource associated with the specified primary resource as defined by * the function provided when this InformerEventSource was created - * + * * @param resource the primary resource we want to retrieve the associated resource for * @return the informed resource associated with the specified primary resource */ @@ -150,17 +166,18 @@ public Optional getAssociated(P resource) { return get(id); } - public SharedInformer getSharedInformer() { return sharedInformer; } @Override public Optional get(ResourceID resourceID) { - return Optional.ofNullable(sharedInformer.getStore() - .getByKey(io.fabric8.kubernetes.client.informers.cache.Cache.namespaceKeyFunc( - resourceID.getNamespace().orElse(null), - resourceID.getName()))); + return Optional.ofNullable( + sharedInformer + .getStore() + .getByKey( + io.fabric8.kubernetes.client.informers.cache.Cache.namespaceKeyFunc( + resourceID.getNamespace().orElse(null), resourceID.getName()))); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java index 4702bd8c38..f9a4265c04 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java @@ -12,29 +12,26 @@ import io.javaoperatorsdk.operator.processing.event.source.CachingEventSource; /** - *

* Polls resource (on contrary to {@link PerResourcePollingEventSource}) not per resource bases but * instead to calls supplier periodically and independently of the number of state of custom * resources managed by the operator. It is called on start (synced). This means that when the * reconciler first time executed on startup a poll already happened before. So if the cache does * not contain the target resource it means it is not created yet or was deleted while an operator * was not running. - *

+ * *

* Another caveat with this is if the cached object is checked in the reconciler and created since * not in the cache it should be manually added to the cache, since it can happen that the * reconciler is triggered before the cache is propagated with the new resource from a scheduled - * execution. See {@link #put(ResourceID, Object)} method. - *

- * So the generic workflow in reconciler should be: + * execution. See {@link #put(ResourceID, Object)} method. So the generic workflow in reconciler + * should be: * * * * @param type of the polled resource @@ -48,8 +45,8 @@ public class PollingEventSource extends CachingEventSo private final Supplier> supplierToPoll; private final long period; - public PollingEventSource(Supplier> supplier, - long period, Class resourceClass) { + public PollingEventSource( + Supplier> supplier, long period, Class resourceClass) { super(resourceClass); this.supplierToPoll = supplier; this.period = period; @@ -59,16 +56,19 @@ public PollingEventSource(Supplier> supplier, public void start() throws OperatorException { super.start(); getStateAndFillCache(); - timer.schedule(new TimerTask() { - @Override - public void run() { - if (!isRunning()) { - log.debug("Event source not yet started. Will not run."); - return; - } - getStateAndFillCache(); - } - }, period, period); + timer.schedule( + new TimerTask() { + @Override + public void run() { + if (!isRunning()) { + log.debug("Event source not yet started. Will not run."); + return; + } + getStateAndFillCache(); + } + }, + period, + period); } protected void getStateAndFillCache() { @@ -89,7 +89,7 @@ public void stop() throws OperatorException { /** * See {@link PerResourcePollingEventSource} for more info. - * + * * @param primary custom resource * @return related resource */ @@ -97,5 +97,4 @@ public void stop() throws OperatorException { public Optional getAssociated(P primary) { return getCachedValue(ResourceID.fromResource(primary)); } - } From 6d854544b58d94adb26d43d874272e6f86825196 Mon Sep 17 00:00:00 2001 From: csviri Date: Thu, 3 Mar 2022 09:43:27 +0100 Subject: [PATCH 3/3] fix: additional formatting --- .../javaoperatorsdk/operator/api/ObservedGenerationAware.java | 2 +- .../operator/api/reconciler/EventSourceInitializer.java | 4 ++-- .../operator/processing/event/source/EventSource.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java index 43927b8136..069953a32d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java @@ -15,7 +15,7 @@ * {@link UpdateControl#updateResource(HasMetadata)} is called. Although those results call normally * does not result in a status update, there will be a subsequent status update Kubernetes API call * in this case. - * + * * @see ObservedGenerationAwareStatus */ public interface ObservedGenerationAware { diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java index 79b15380a5..562ddc3b8f 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java @@ -8,14 +8,14 @@ /** * An interface that a {@link Reconciler} can implement to have the SDK register the provided * {@link EventSource} - * + * * @param

the primary resource type handled by the associated {@link Reconciler} */ public interface EventSourceInitializer

{ /** * Prepares a list of {@link EventSource} implementations to be registered by the SDK. - * + * * @param context a {@link EventSourceContext} providing access to information useful to event * sources * @return list of event sources to register diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java index 04e19f7ceb..10a690c0e8 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java @@ -15,7 +15,7 @@ public interface EventSource extends LifecycleAware { /** * An optional name for your EventSource. This is only required if you need to register multiple * EventSources for the same resource type (e.g. {@code Deployment}). - * + * * @return the name associated with this EventSource */ default String name() { @@ -25,7 +25,7 @@ default String name() { /** * Sets the {@link EventHandler} that is linked to your reconciler when this EventSource is * registered. - * + * * @param handler the {@link EventHandler} associated with your reconciler */ void setEventHandler(EventHandler handler);