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/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/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);
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:
*
*
- * - Check if the cache contains the resource.
+ * - Check if the cache contains the resource.
*
- If cache contains the resource reconcile it - compare with target state, update if necessary
- *
- * - if cache not contains the resource create it.
+ * - if cache not contains the resource create it.
*
- If the resource was created or updated, put the new version of the resource manually to the
- * cache.
+ * cache.
*
*
* @param type of the polled resource
@@ -48,8 +45,8 @@ public class PollingEventSource extends CachingEventSo
private final Supplier