Skip to content

chore(deps): bump formatter-maven-plugin from 2.17.1 to 2.18.0 #989

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ default int concurrentReconciliationThreads() {

/**
* Used to clone custom resources.
*
*
* @return the ObjectMapper to use
*/
default Cloner getResourceCloner() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResourceCache<P> 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() {
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* An interface that a {@link Reconciler} can implement to have the SDK register the provided
* {@link EventSource}
*
*
* @param <P> the primary resource type handled by the associated {@link Reconciler}
*/
public interface EventSourceInitializer<P extends HasMetadata> {

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import io.javaoperatorsdk.operator.processing.event.source.ResourceCache;

public class InformerEventSource<T extends HasMetadata, P extends HasMetadata>
extends AbstractResourceEventSource<P, T>
implements ResourceCache<T> {
extends AbstractResourceEventSource<P, T> implements ResourceCache<T> {

private static final Logger log = LoggerFactory.getLogger(InformerEventSource.class);

Expand All @@ -32,33 +31,46 @@ public class InformerEventSource<T extends HasMetadata, P extends HasMetadata>
private final AssociatedSecondaryResourceIdentifier<P> associatedWith;
private final boolean skipUpdateEventPropagationIfNoChange;

public InformerEventSource(SharedInformer<T> sharedInformer,
public InformerEventSource(
SharedInformer<T> sharedInformer,
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet) {
this(sharedInformer, resourceToTargetResourceIDSet, null, true);
}

public InformerEventSource(KubernetesClient client, Class<T> type,
public InformerEventSource(
KubernetesClient client,
Class<T> type,
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet) {
this(client, type, resourceToTargetResourceIDSet, false);
}

public InformerEventSource(KubernetesClient client, Class<T> type,
public InformerEventSource(
KubernetesClient client,
Class<T> type,
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
AssociatedSecondaryResourceIdentifier<P> associatedWith,
boolean skipUpdateEventPropagationIfNoChange) {
this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet,
this(
client.informers().sharedIndexInformerFor(type, 0),
resourceToTargetResourceIDSet,
associatedWith,
skipUpdateEventPropagationIfNoChange);
}

InformerEventSource(KubernetesClient client, Class<T> type,
InformerEventSource(
KubernetesClient client,
Class<T> type,
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
boolean skipUpdateEventPropagationIfNoChange) {
this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet, null,
this(
client.informers().sharedIndexInformerFor(type, 0),
resourceToTargetResourceIDSet,
null,
skipUpdateEventPropagationIfNoChange);
}

public InformerEventSource(SharedInformer<T> sharedInformer,
public InformerEventSource(
SharedInformer<T> sharedInformer,
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
AssociatedSecondaryResourceIdentifier<P> associatedWith,
boolean skipUpdateEventPropagationIfNoChange) {
Expand All @@ -68,60 +80,64 @@ public InformerEventSource(SharedInformer<T> 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) {
var primaryResourceIdSet = secondaryToPrimaryResourcesIdSet.associatedPrimaryResources(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
Expand All @@ -141,7 +157,7 @@ private Store<T> 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
*/
Expand All @@ -150,17 +166,18 @@ public Optional<T> getAssociated(P resource) {
return get(id);
}


public SharedInformer<T> getSharedInformer() {
return sharedInformer;
}

@Override
public Optional<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@
import io.javaoperatorsdk.operator.processing.event.source.CachingEventSource;

/**
* <p>
* 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.
* </p>
*
* <p>
* 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.
* </p>
* So the generic workflow in reconciler should be:
* execution. See {@link #put(ResourceID, Object)} method. So the generic workflow in reconciler
* should be:
*
* <ul>
* <li>Check if the cache contains the resource.</li>
* <li>Check if the cache contains the resource.
* <li>If cache contains the resource reconcile it - compare with target state, update if necessary
* </li>
* <li>if cache not contains the resource create it.</li>
* <li>if cache not contains the resource create it.
* <li>If the resource was created or updated, put the new version of the resource manually to the
* cache.</li>
* cache.
* </ul>
*
* @param <T> type of the polled resource
Expand All @@ -48,8 +45,8 @@ public class PollingEventSource<T, P extends HasMetadata> extends CachingEventSo
private final Supplier<Map<ResourceID, T>> supplierToPoll;
private final long period;

public PollingEventSource(Supplier<Map<ResourceID, T>> supplier,
long period, Class<T> resourceClass) {
public PollingEventSource(
Supplier<Map<ResourceID, T>> supplier, long period, Class<T> resourceClass) {
super(resourceClass);
this.supplierToPoll = supplier;
this.period = period;
Expand All @@ -59,16 +56,19 @@ public PollingEventSource(Supplier<Map<ResourceID, T>> 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() {
Expand All @@ -89,13 +89,12 @@ public void stop() throws OperatorException {

/**
* See {@link PerResourcePollingEventSource} for more info.
*
*
* @param primary custom resource
* @return related resource
*/
@Override
public Optional<T> getAssociated(P primary) {
return getCachedValue(ResourceID.fromResource(primary));
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
<git-commit-id-maven-plugin.version>5.0.0</git-commit-id-maven-plugin.version>
<formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version>
<formatter-maven-plugin.version>2.18.0</formatter-maven-plugin.version>
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
<impsort-maven-plugin.version>1.6.2</impsort-maven-plugin.version>
</properties>
Expand Down