Skip to content

Commit 946e2b3

Browse files
committed
mostly removing the parse resource version term
and more of the previous annotation handling
1 parent 2b755b2 commit 946e2b3

8 files changed

Lines changed: 34 additions & 87 deletions

File tree

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -450,45 +450,15 @@ default Set<Class<? extends HasMetadata>> defaultNonSSAResource() {
450450
}
451451

452452
/**
453-
* For dependent resources, the framework can add an annotation to filter out events resulting
454-
* directly from the framework's operation. There are, however, some resources that do not follow
455-
* the Kubernetes API conventions that changes in metadata should not increase the generation of
456-
* the resource (as recorded in the {@code generation} field of the resource's {@code metadata}).
457-
* For these resources, this convention is not respected and results in a new event for the
458-
* framework to process. If that particular case is not handled correctly in the resource matcher,
459-
* the framework will consider that the resource doesn't match the desired state and therefore
460-
* triggers an update, which in turn, will re-add the annotation, thus starting the loop again,
461-
* infinitely.
462-
*
463-
* <p>As a workaround, we automatically skip adding previous annotation for those well-known
464-
* resources. Note that if you are sure that the matcher works for your use case, and it should in
465-
* most instances, you can remove the resource type from the blocklist.
466-
*
467-
* <p>The consequence of adding a resource type to the set is that the framework will not use
468-
* event filtering to prevent events, initiated by changes made by the framework itself as a
469-
* result of its processing of dependent resources, to trigger the associated reconciler again.
470-
*
471-
* <p>Note that this method only takes effect if annotating dependent resources to prevent
472-
* dependent resources events from triggering the associated reconciler again is activated as
473-
* controlled by {@link #previousAnnotationForDependentResourcesEventFiltering()}
474-
*
475-
* @return a Set of resource classes where the previous version annotation won't be used.
476-
*/
477-
default Set<Class<? extends HasMetadata>> withPreviousAnnotationForDependentResourcesBlocklist() {
478-
return Set.of(Deployment.class, StatefulSet.class);
479-
}
480-
481-
/**
482-
* If the event logic should parse the resourceVersion to determine the ordering of dependent
483-
* resource events.
453+
* If the event logic can compare resourceVersions.
484454
*
485455
* <p>Enabled by default as Kubernetes does support this interpretation of resourceVersions.
486-
* Disable only if your api server provides non comparable resource versions..
456+
* Disable only if your api server provides non comparable resource versions.
487457
*
488-
* @return if resource version should be parsed (as integer)
489-
* @since 4.5.0
458+
* @return if resource versions are comparable
459+
* @since 5.3.0
490460
*/
491-
default boolean parseResourceVersionsForEventFilteringAndCaching() {
461+
default boolean comparableResourceVersions() {
492462
return DEFAULT_COMPARABLE_RESOURCE_VERSIONS;
493463
}
494464

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

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ public class ConfigurationServiceOverrider {
5151
private Duration reconciliationTerminationTimeout;
5252
private Boolean ssaBasedCreateUpdateMatchForDependentResources;
5353
private Set<Class<? extends HasMetadata>> defaultNonSSAResource;
54-
private Boolean previousAnnotationForDependentResources;
55-
private Boolean parseResourceVersions;
54+
private Boolean comparableResourceVersions;
5655
private Boolean useSSAToPatchPrimaryResource;
5756
private Boolean cloneSecondaryResourcesWhenGettingFromCache;
58-
private Set<Class<? extends HasMetadata>> previousAnnotationUsageBlocklist;
5957

6058
@SuppressWarnings("rawtypes")
6159
private DependentResourceFactory dependentResourceFactory;
@@ -167,29 +165,24 @@ public ConfigurationServiceOverrider withDefaultNonSSAResource(
167165
this.defaultNonSSAResource = defaultNonSSAResource;
168166
return this;
169167
}
170-
171-
public ConfigurationServiceOverrider withPreviousAnnotationForDependentResources(boolean value) {
172-
this.previousAnnotationForDependentResources = value;
173-
return this;
174-
}
175-
168+
176169
/**
177170
* @param value true if internal algorithms can use metadata.resourceVersion as a numeric value.
178171
* @return this
179172
*/
180-
public ConfigurationServiceOverrider withParseResourceVersions(boolean value) {
181-
this.parseResourceVersions = value;
173+
public ConfigurationServiceOverrider withComparableResourceVersions(boolean value) {
174+
this.comparableResourceVersions = value;
182175
return this;
183176
}
184177

185178
/**
186-
* @deprecated use withParseResourceVersions
179+
* @deprecated use withComparableResourceVersions
187180
* @param value true if internal algorithms can use metadata.resourceVersion as a numeric value.
188181
* @return this
189182
*/
190183
@Deprecated(forRemoval = true)
191-
public ConfigurationServiceOverrider wihtParseResourceVersions(boolean value) {
192-
this.parseResourceVersions = value;
184+
public ConfigurationServiceOverrider withParseResourceVersions(boolean value) {
185+
this.comparableResourceVersions = value;
193186
return this;
194187
}
195188

@@ -204,12 +197,6 @@ public ConfigurationServiceOverrider withCloneSecondaryResourcesWhenGettingFromC
204197
return this;
205198
}
206199

207-
public ConfigurationServiceOverrider withPreviousAnnotationForDependentResourcesBlocklist(
208-
Set<Class<? extends HasMetadata>> blocklist) {
209-
this.previousAnnotationUsageBlocklist = blocklist;
210-
return this;
211-
}
212-
213200
public ConfigurationService build() {
214201
return new BaseConfigurationService(original.getVersion(), cloner, client) {
215202
@Override
@@ -331,13 +318,6 @@ public Set<Class<? extends HasMetadata>> defaultNonSSAResources() {
331318
defaultNonSSAResource, ConfigurationService::defaultNonSSAResources);
332319
}
333320

334-
@Override
335-
public boolean parseResourceVersionsForEventFilteringAndCaching() {
336-
return overriddenValueOrDefault(
337-
parseResourceVersions,
338-
ConfigurationService::parseResourceVersionsForEventFilteringAndCaching);
339-
}
340-
341321
@Override
342322
public boolean useSSAToPatchPrimaryResource() {
343323
return overriddenValueOrDefault(
@@ -350,13 +330,12 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
350330
cloneSecondaryResourcesWhenGettingFromCache,
351331
ConfigurationService::cloneSecondaryResourcesWhenGettingFromCache);
352332
}
353-
333+
354334
@Override
355-
public Set<Class<? extends HasMetadata>>
356-
withPreviousAnnotationForDependentResourcesBlocklist() {
335+
public boolean comparableResourceVersions() {
357336
return overriddenValueOrDefault(
358-
previousAnnotationUsageBlocklist,
359-
ConfigurationService::withPreviousAnnotationForDependentResourcesBlocklist);
337+
comparableResourceVersions,
338+
ConfigurationService::comparableResourceVersions);
360339
}
361340
};
362341
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ControllerEventSource(Controller<T> controller) {
5454
controller
5555
.getConfiguration()
5656
.getConfigurationService()
57-
.parseResourceVersionsForEventFilteringAndCaching());
57+
.comparableResourceVersions());
5858
this.controller = controller;
5959

6060
final var config = controller.getConfiguration();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public InformerEventSource(
9797
private InformerEventSource(
9898
InformerEventSourceConfiguration<R> configuration,
9999
KubernetesClient client,
100-
boolean parseResourceVersions) {
100+
boolean comparableResourceVersions) {
101101
super(
102102
configuration.name(),
103103
configuration
104104
.getGroupVersionKind()
105105
.map(gvk -> client.genericKubernetesResources(gvk.apiVersion(), gvk.getKind()))
106106
.orElseGet(() -> (MixedOperation) client.resources(configuration.getResourceClass())),
107107
configuration,
108-
parseResourceVersions);
108+
comparableResourceVersions);
109109
// If there is a primary to secondary mapper there is no need for primary to secondary index.
110110
primaryToSecondaryMapper = configuration.getPrimaryToSecondaryMapper();
111111
if (useSecondaryToPrimaryIndex()) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ public abstract class ManagedInformerEventSource<
5656

5757
private static final Logger log = LoggerFactory.getLogger(ManagedInformerEventSource.class);
5858
private InformerManager<R, C> cache;
59-
private final boolean parseResourceVersions;
59+
private final boolean comparableResourceVersions;
6060
private ControllerConfiguration<R> controllerConfiguration;
6161
private final C configuration;
6262
private final Map<String, Function<R, List<String>>> indexers = new HashMap<>();
6363
protected TemporaryResourceCache<R> temporaryResourceCache;
6464
protected MixedOperation client;
6565

6666
protected ManagedInformerEventSource(
67-
String name, MixedOperation client, C configuration, boolean parseResourceVersions) {
67+
String name, MixedOperation client, C configuration, boolean comparableResourceVersions) {
6868
super(configuration.getResourceClass(), name);
69-
this.parseResourceVersions = parseResourceVersions;
69+
this.comparableResourceVersions = comparableResourceVersions;
7070
this.client = client;
7171
this.configuration = configuration;
7272
}
@@ -103,7 +103,7 @@ public synchronized void start() {
103103
if (isRunning()) {
104104
return;
105105
}
106-
temporaryResourceCache = new TemporaryResourceCache<>(parseResourceVersions);
106+
temporaryResourceCache = new TemporaryResourceCache<>(comparableResourceVersions);
107107
this.cache = new InformerManager<>(client, configuration, this);
108108
cache.setControllerConfiguration(controllerConfiguration);
109109
cache.addIndexers(indexers);
@@ -135,7 +135,7 @@ public void handleRecentResourceCreate(ResourceID resourceID, R resource) {
135135
public Optional<R> get(ResourceID resourceID) {
136136
var res = cache.get(resourceID);
137137
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
138-
if (parseResourceVersions
138+
if (comparableResourceVersions
139139
&& resource.isPresent()
140140
&& res.filter(
141141
r ->

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ public class TemporaryResourceCache<T extends HasMetadata> {
5151
private static final Logger log = LoggerFactory.getLogger(TemporaryResourceCache.class);
5252

5353
private final Map<ResourceID, T> cache = new ConcurrentHashMap<>();
54-
private final boolean parseResourceVersions;
54+
private final boolean comparableResourceVersions;
5555
private final Map<ResourceID, ReentrantLock> activelyModifying = new ConcurrentHashMap<>();
5656
private String latestResourceVersion;
5757

58-
public TemporaryResourceCache(boolean parseResourceVersions) {
59-
this.parseResourceVersions = parseResourceVersions;
58+
public TemporaryResourceCache(boolean comparableResourceVersions) {
59+
this.comparableResourceVersions = comparableResourceVersions;
6060
}
6161

6262
public void startModifying(ResourceID id) {
63-
if (!parseResourceVersions) {
63+
if (!comparableResourceVersions) {
6464
return;
6565
}
6666
activelyModifying
@@ -77,7 +77,7 @@ public void startModifying(ResourceID id) {
7777
}
7878

7979
public void doneModifying(ResourceID id) {
80-
if (!parseResourceVersions) {
80+
if (!comparableResourceVersions) {
8181
return;
8282
}
8383
activelyModifying.computeIfPresent(
@@ -134,7 +134,7 @@ private boolean onEvent(T resource, boolean unknownState) {
134134

135135
/** put the item into the cache if it's for a later state than what has already been observed. */
136136
public synchronized void putResource(T newResource) {
137-
if (!parseResourceVersions) {
137+
if (!comparableResourceVersions) {
138138
return;
139139
}
140140

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryPrimaryResourceCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void removesResourceFromCache() {
108108
}
109109

110110
@Test
111-
void resourceNoVersionParsing() {
111+
void nonComparableResourceVersionsDisables() {
112112
this.temporaryResourceCache = new TemporaryResourceCache<>(false);
113113

114114
this.temporaryResourceCache.putResource(testResource());

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/PreviousAnnotationDisabledIT.java renamed to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/createupdateeventfilter/ComparableResourceVersionsDisabledIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515
*/
1616
package io.javaoperatorsdk.operator.baseapi.createupdateeventfilter;
1717

18+
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
1819
import org.junit.jupiter.api.Test;
1920
import org.junit.jupiter.api.extension.RegisterExtension;
2021

21-
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
22-
23-
class PreviousAnnotationDisabledIT {
22+
class ComparableResourceVersionsDisabledIT {
2423

2524
@RegisterExtension
2625
LocallyRunOperatorExtension operator =
2726
LocallyRunOperatorExtension.builder()
2827
.withReconciler(new CreateUpdateEventFilterTestReconciler())
29-
.withConfigurationService(
30-
overrider -> overrider.withPreviousAnnotationForDependentResources(false))
28+
.withConfigurationService(overrider -> overrider.withComparableResourceVersions(false))
3129
.build();
3230

3331
@Test

0 commit comments

Comments
 (0)