Skip to content

Commit 7433c8b

Browse files
chore(deps): bump formatter-maven-plugin from 2.17.1 to 2.18.0 (#989)
1 parent def54f5 commit 7433c8b

File tree

8 files changed

+105
-89
lines changed

8 files changed

+105
-89
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* {@link UpdateControl#updateResource(HasMetadata)} is called. Although those results call normally
1616
* does not result in a status update, there will be a subsequent status update Kubernetes API call
1717
* in this case.
18-
*
18+
*
1919
* @see ObservedGenerationAwareStatus
2020
*/
2121
public interface ObservedGenerationAware {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ default int concurrentReconciliationThreads() {
9292

9393
/**
9494
* Used to clone custom resources.
95-
*
95+
*
9696
* @return the ObjectMapper to use
9797
*/
9898
default Cloner getResourceCloner() {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ResourceCache<P> getPrimaryCache() {
3939
* {@link io.javaoperatorsdk.operator.api.monitoring.Metrics} or
4040
* {@link io.javaoperatorsdk.operator.api.config.Cloner} implementations, which could be useful to
4141
* event sources.
42-
*
42+
*
4343
* @return the {@link ConfigurationService} associated with the operator
4444
*/
4545
public ConfigurationService getConfigurationService() {
@@ -49,7 +49,7 @@ public ConfigurationService getConfigurationService() {
4949
/**
5050
* Provides access to the {@link KubernetesClient} used by the current
5151
* {@link io.javaoperatorsdk.operator.Operator} instance.
52-
*
52+
*
5353
* @return the {@link KubernetesClient} used by the current
5454
* {@link io.javaoperatorsdk.operator.Operator} instance.
5555
*/

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
/**
99
* An interface that a {@link Reconciler} can implement to have the SDK register the provided
1010
* {@link EventSource}
11-
*
11+
*
1212
* @param <P> the primary resource type handled by the associated {@link Reconciler}
1313
*/
1414
public interface EventSourceInitializer<P extends HasMetadata> {
1515

1616
/**
1717
* Prepares a list of {@link EventSource} implementations to be registered by the SDK.
18-
*
18+
*
1919
* @param context a {@link EventSourceContext} providing access to information useful to event
2020
* sources
2121
* @return list of event sources to register

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface EventSource extends LifecycleAware {
1515
/**
1616
* An optional name for your EventSource. This is only required if you need to register multiple
1717
* EventSources for the same resource type (e.g. {@code Deployment}).
18-
*
18+
*
1919
* @return the name associated with this EventSource
2020
*/
2121
default String name() {
@@ -25,7 +25,7 @@ default String name() {
2525
/**
2626
* Sets the {@link EventHandler} that is linked to your reconciler when this EventSource is
2727
* registered.
28-
*
28+
*
2929
* @param handler the {@link EventHandler} associated with your reconciler
3030
*/
3131
void setEventHandler(EventHandler handler);

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import io.javaoperatorsdk.operator.processing.event.source.ResourceCache;
2323

2424
public class InformerEventSource<T extends HasMetadata, P extends HasMetadata>
25-
extends AbstractResourceEventSource<P, T>
26-
implements ResourceCache<T> {
25+
extends AbstractResourceEventSource<P, T> implements ResourceCache<T> {
2726

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

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

35-
public InformerEventSource(SharedInformer<T> sharedInformer,
34+
public InformerEventSource(
35+
SharedInformer<T> sharedInformer,
3636
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet) {
3737
this(sharedInformer, resourceToTargetResourceIDSet, null, true);
3838
}
3939

40-
public InformerEventSource(KubernetesClient client, Class<T> type,
40+
public InformerEventSource(
41+
KubernetesClient client,
42+
Class<T> type,
4143
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet) {
4244
this(client, type, resourceToTargetResourceIDSet, false);
4345
}
4446

45-
public InformerEventSource(KubernetesClient client, Class<T> type,
47+
public InformerEventSource(
48+
KubernetesClient client,
49+
Class<T> type,
4650
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
4751
AssociatedSecondaryResourceIdentifier<P> associatedWith,
4852
boolean skipUpdateEventPropagationIfNoChange) {
49-
this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet,
53+
this(
54+
client.informers().sharedIndexInformerFor(type, 0),
55+
resourceToTargetResourceIDSet,
5056
associatedWith,
5157
skipUpdateEventPropagationIfNoChange);
5258
}
5359

54-
InformerEventSource(KubernetesClient client, Class<T> type,
60+
InformerEventSource(
61+
KubernetesClient client,
62+
Class<T> type,
5563
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
5664
boolean skipUpdateEventPropagationIfNoChange) {
57-
this(client.informers().sharedIndexInformerFor(type, 0), resourceToTargetResourceIDSet, null,
65+
this(
66+
client.informers().sharedIndexInformerFor(type, 0),
67+
resourceToTargetResourceIDSet,
68+
null,
5869
skipUpdateEventPropagationIfNoChange);
5970
}
6071

61-
public InformerEventSource(SharedInformer<T> sharedInformer,
72+
public InformerEventSource(
73+
SharedInformer<T> sharedInformer,
6274
PrimaryResourcesRetriever<T> resourceToTargetResourceIDSet,
6375
AssociatedSecondaryResourceIdentifier<P> associatedWith,
6476
boolean skipUpdateEventPropagationIfNoChange) {
@@ -68,60 +80,64 @@ public InformerEventSource(SharedInformer<T> sharedInformer,
6880
this.skipUpdateEventPropagationIfNoChange = skipUpdateEventPropagationIfNoChange;
6981
if (sharedInformer.isRunning()) {
7082
log.warn(
71-
"Informer is already running on event source creation, this is not desirable and may " +
72-
"lead to non deterministic behavior.");
83+
"Informer is already running on event source creation, this is not desirable and may "
84+
+ "lead to non deterministic behavior.");
7385
}
7486

7587
this.associatedWith =
7688
Objects.requireNonNullElseGet(associatedWith, () -> ResourceID::fromResource);
7789

78-
sharedInformer.addEventHandler(new ResourceEventHandler<>() {
79-
@Override
80-
public void onAdd(T t) {
81-
propagateEvent(t);
82-
}
83-
84-
@Override
85-
public void onUpdate(T oldObject, T newObject) {
86-
if (newObject == null) {
87-
// this is a fix for this potential issue with informer:
88-
// https://github.com/java-operator-sdk/java-operator-sdk/issues/830
89-
propagateEvent(oldObject);
90-
return;
91-
}
92-
93-
if (InformerEventSource.this.skipUpdateEventPropagationIfNoChange &&
94-
oldObject.getMetadata().getResourceVersion()
95-
.equals(newObject.getMetadata().getResourceVersion())) {
96-
return;
97-
}
98-
propagateEvent(newObject);
99-
}
100-
101-
@Override
102-
public void onDelete(T t, boolean b) {
103-
propagateEvent(t);
104-
}
105-
});
90+
sharedInformer.addEventHandler(
91+
new ResourceEventHandler<>() {
92+
@Override
93+
public void onAdd(T t) {
94+
propagateEvent(t);
95+
}
96+
97+
@Override
98+
public void onUpdate(T oldObject, T newObject) {
99+
if (newObject == null) {
100+
// this is a fix for this potential issue with informer:
101+
// https://github.com/java-operator-sdk/java-operator-sdk/issues/830
102+
propagateEvent(oldObject);
103+
return;
104+
}
105+
106+
if (InformerEventSource.this.skipUpdateEventPropagationIfNoChange
107+
&& oldObject
108+
.getMetadata()
109+
.getResourceVersion()
110+
.equals(newObject.getMetadata().getResourceVersion())) {
111+
return;
112+
}
113+
propagateEvent(newObject);
114+
}
115+
116+
@Override
117+
public void onDelete(T t, boolean b) {
118+
propagateEvent(t);
119+
}
120+
});
106121
}
107122

108123
private void propagateEvent(T object) {
109124
var primaryResourceIdSet = secondaryToPrimaryResourcesIdSet.associatedPrimaryResources(object);
110125
if (primaryResourceIdSet.isEmpty()) {
111126
return;
112127
}
113-
primaryResourceIdSet.forEach(resourceId -> {
114-
Event event = new Event(resourceId);
115-
/*
116-
* In fabric8 client for certain cases informers can be created on in a way that they are
117-
* automatically started, what would cause a NullPointerException here, since an event might
118-
* be received between creation and registration.
119-
*/
120-
final EventHandler eventHandler = getEventHandler();
121-
if (eventHandler != null) {
122-
eventHandler.handleEvent(event);
123-
}
124-
});
128+
primaryResourceIdSet.forEach(
129+
resourceId -> {
130+
Event event = new Event(resourceId);
131+
/*
132+
* In fabric8 client for certain cases informers can be created on in a way that they are
133+
* automatically started, what would cause a NullPointerException here, since an event
134+
* might be received between creation and registration.
135+
*/
136+
final EventHandler eventHandler = getEventHandler();
137+
if (eventHandler != null) {
138+
eventHandler.handleEvent(event);
139+
}
140+
});
125141
}
126142

127143
@Override
@@ -141,7 +157,7 @@ private Store<T> getStore() {
141157
/**
142158
* Retrieves the informed resource associated with the specified primary resource as defined by
143159
* the function provided when this InformerEventSource was created
144-
*
160+
*
145161
* @param resource the primary resource we want to retrieve the associated resource for
146162
* @return the informed resource associated with the specified primary resource
147163
*/
@@ -150,17 +166,18 @@ public Optional<T> getAssociated(P resource) {
150166
return get(id);
151167
}
152168

153-
154169
public SharedInformer<T> getSharedInformer() {
155170
return sharedInformer;
156171
}
157172

158173
@Override
159174
public Optional<T> get(ResourceID resourceID) {
160-
return Optional.ofNullable(sharedInformer.getStore()
161-
.getByKey(io.fabric8.kubernetes.client.informers.cache.Cache.namespaceKeyFunc(
162-
resourceID.getNamespace().orElse(null),
163-
resourceID.getName())));
175+
return Optional.ofNullable(
176+
sharedInformer
177+
.getStore()
178+
.getByKey(
179+
io.fabric8.kubernetes.client.informers.cache.Cache.namespaceKeyFunc(
180+
resourceID.getNamespace().orElse(null), resourceID.getName())));
164181
}
165182

166183
@Override

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@
1212
import io.javaoperatorsdk.operator.processing.event.source.CachingEventSource;
1313

1414
/**
15-
* <p>
1615
* Polls resource (on contrary to {@link PerResourcePollingEventSource}) not per resource bases but
1716
* instead to calls supplier periodically and independently of the number of state of custom
1817
* resources managed by the operator. It is called on start (synced). This means that when the
1918
* reconciler first time executed on startup a poll already happened before. So if the cache does
2019
* not contain the target resource it means it is not created yet or was deleted while an operator
2120
* was not running.
22-
* </p>
21+
*
2322
* <p>
2423
* Another caveat with this is if the cached object is checked in the reconciler and created since
2524
* not in the cache it should be manually added to the cache, since it can happen that the
2625
* reconciler is triggered before the cache is propagated with the new resource from a scheduled
27-
* execution. See {@link #put(ResourceID, Object)} method.
28-
* </p>
29-
* So the generic workflow in reconciler should be:
26+
* execution. See {@link #put(ResourceID, Object)} method. So the generic workflow in reconciler
27+
* should be:
3028
*
3129
* <ul>
32-
* <li>Check if the cache contains the resource.</li>
30+
* <li>Check if the cache contains the resource.
3331
* <li>If cache contains the resource reconcile it - compare with target state, update if necessary
34-
* </li>
35-
* <li>if cache not contains the resource create it.</li>
32+
* <li>if cache not contains the resource create it.
3633
* <li>If the resource was created or updated, put the new version of the resource manually to the
37-
* cache.</li>
34+
* cache.
3835
* </ul>
3936
*
4037
* @param <T> type of the polled resource
@@ -48,8 +45,8 @@ public class PollingEventSource<T, P extends HasMetadata> extends CachingEventSo
4845
private final Supplier<Map<ResourceID, T>> supplierToPoll;
4946
private final long period;
5047

51-
public PollingEventSource(Supplier<Map<ResourceID, T>> supplier,
52-
long period, Class<T> resourceClass) {
48+
public PollingEventSource(
49+
Supplier<Map<ResourceID, T>> supplier, long period, Class<T> resourceClass) {
5350
super(resourceClass);
5451
this.supplierToPoll = supplier;
5552
this.period = period;
@@ -59,16 +56,19 @@ public PollingEventSource(Supplier<Map<ResourceID, T>> supplier,
5956
public void start() throws OperatorException {
6057
super.start();
6158
getStateAndFillCache();
62-
timer.schedule(new TimerTask() {
63-
@Override
64-
public void run() {
65-
if (!isRunning()) {
66-
log.debug("Event source not yet started. Will not run.");
67-
return;
68-
}
69-
getStateAndFillCache();
70-
}
71-
}, period, period);
59+
timer.schedule(
60+
new TimerTask() {
61+
@Override
62+
public void run() {
63+
if (!isRunning()) {
64+
log.debug("Event source not yet started. Will not run.");
65+
return;
66+
}
67+
getStateAndFillCache();
68+
}
69+
},
70+
period,
71+
period);
7272
}
7373

7474
protected void getStateAndFillCache() {
@@ -89,13 +89,12 @@ public void stop() throws OperatorException {
8989

9090
/**
9191
* See {@link PerResourcePollingEventSource} for more info.
92-
*
92+
*
9393
* @param primary custom resource
9494
* @return related resource
9595
*/
9696
@Override
9797
public Optional<T> getAssociated(P primary) {
9898
return getCachedValue(ResourceID.fromResource(primary));
9999
}
100-
101100
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
7070
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
7171
<git-commit-id-maven-plugin.version>5.0.0</git-commit-id-maven-plugin.version>
72-
<formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version>
72+
<formatter-maven-plugin.version>2.18.0</formatter-maven-plugin.version>
7373
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
7474
<impsort-maven-plugin.version>1.6.2</impsort-maven-plugin.version>
7575
</properties>

0 commit comments

Comments
 (0)