Skip to content
Open
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 @@ -44,8 +44,6 @@
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSIONS;

/** An interface from which to retrieve configuration information. */
public interface ConfigurationService {

Expand Down Expand Up @@ -447,19 +445,6 @@ default Set<Class<? extends HasMetadata>> defaultNonSSAResource() {
return defaultNonSSAResources();
}

/**
* If the event logic can compare resourceVersions.
*
* <p>Enabled by default as Kubernetes does support this interpretation of resourceVersions.
* Disable only if your api server provides non comparable resource versions.
*
* @return if resource versions are comparable
* @since 5.3.0
*/
default boolean comparableResourceVersions() {
return DEFAULT_COMPARABLE_RESOURCE_VERSIONS;
}

/**
* {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patch resource or status can
* either use simple patches or SSA. Setting this to {@code true}, controllers will use SSA for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class ConfigurationServiceOverrider {
private Duration reconciliationTerminationTimeout;
private Boolean ssaBasedCreateUpdateMatchForDependentResources;
private Set<Class<? extends HasMetadata>> defaultNonSSAResource;
private Boolean comparableResourceVersions;
private Boolean useSSAToPatchPrimaryResource;
private Boolean cloneSecondaryResourcesWhenGettingFromCache;

Expand Down Expand Up @@ -166,26 +165,6 @@ public ConfigurationServiceOverrider withDefaultNonSSAResource(
return this;
}

/**
* @param value true if internal algorithms can use metadata.resourceVersion as a numeric value.
* @return this
*/
public ConfigurationServiceOverrider withComparableResourceVersions(boolean value) {
this.comparableResourceVersions = value;
return this;
}

/**
* @deprecated use withComparableResourceVersions
* @param value true if internal algorithms can use metadata.resourceVersion as a numeric value.
* @return this
*/
@Deprecated(forRemoval = true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we can remove this method, yet.

public ConfigurationServiceOverrider withParseResourceVersions(boolean value) {
this.comparableResourceVersions = value;
return this;
}

public ConfigurationServiceOverrider withUseSSAToPatchPrimaryResource(boolean value) {
this.useSSAToPatchPrimaryResource = value;
return this;
Expand Down Expand Up @@ -330,12 +309,6 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
cloneSecondaryResourcesWhenGettingFromCache,
ConfigurationService::cloneSecondaryResourcesWhenGettingFromCache);
}

@Override
public boolean comparableResourceVersions() {
return overriddenValueOrDefault(
comparableResourceVersions, ConfigurationService::comparableResourceVersions);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSION;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET;
Expand Down Expand Up @@ -131,4 +132,9 @@

/** Kubernetes field selector for additional resource filtering */
Field[] fieldSelector() default {};

/**
* true if we can consider resource versions as integers, therefore it is valid to compare them
*/
boolean comparableResourceVersion() default DEFAULT_COMPARABLE_RESOURCE_VERSION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc could use an @since tag

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class InformerConfiguration<R extends HasMetadata> {
private ItemStore<R> itemStore;
private Long informerListLimit;
private FieldSelector fieldSelector;
private boolean comparableResourceVersions;

protected InformerConfiguration(
Class<R> resourceClass,
Expand All @@ -66,7 +67,8 @@ protected InformerConfiguration(
GenericFilter<? super R> genericFilter,
ItemStore<R> itemStore,
Long informerListLimit,
FieldSelector fieldSelector) {
FieldSelector fieldSelector,
boolean comparableResourceVersions) {
this(resourceClass);
this.name = name;
this.namespaces = namespaces;
Expand All @@ -79,6 +81,7 @@ protected InformerConfiguration(
this.itemStore = itemStore;
this.informerListLimit = informerListLimit;
this.fieldSelector = fieldSelector;
this.comparableResourceVersions = comparableResourceVersions;
}

private InformerConfiguration(Class<R> resourceClass) {
Expand Down Expand Up @@ -113,7 +116,8 @@ public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder(
original.genericFilter,
original.itemStore,
original.informerListLimit,
original.fieldSelector)
original.fieldSelector,
original.comparableResourceVersions)
.builder;
}

Expand Down Expand Up @@ -288,6 +292,10 @@ public FieldSelector getFieldSelector() {
return fieldSelector;
}

public boolean isComparableResourceVersions() {
return comparableResourceVersions;
}

@SuppressWarnings("UnusedReturnValue")
public class Builder {

Expand Down Expand Up @@ -359,6 +367,7 @@ public InformerConfiguration<R>.Builder initFromAnnotation(
Arrays.stream(informerConfig.fieldSelector())
.map(f -> new FieldSelector.Field(f.path(), f.value(), f.negated()))
.toList()));
withComparableResourceVersions(informerConfig.comparableResourceVersion());
}
return this;
}
Expand Down Expand Up @@ -459,5 +468,10 @@ public Builder withFieldSelector(FieldSelector fieldSelector) {
InformerConfiguration.this.fieldSelector = fieldSelector;
return this;
}

public Builder withComparableResourceVersions(boolean comparableResourceVersions) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method name should match the annotation field (i.e. versions vs version)

InformerConfiguration.this.comparableResourceVersions = comparableResourceVersions;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;
import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSIONS;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSION;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACE_SET;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET;
Expand Down Expand Up @@ -97,21 +97,21 @@ class DefaultInformerEventSourceConfiguration<R extends HasMetadata>
private final GroupVersionKind groupVersionKind;
private final InformerConfiguration<R> informerConfig;
private final KubernetesClient kubernetesClient;
private final boolean comparableResourceVersions;
private final boolean comparableResourceVersion;

protected DefaultInformerEventSourceConfiguration(
GroupVersionKind groupVersionKind,
PrimaryToSecondaryMapper<?> primaryToSecondaryMapper,
SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper,
InformerConfiguration<R> informerConfig,
KubernetesClient kubernetesClient,
boolean comparableResourceVersions) {
boolean comparableResourceVersion) {
this.informerConfig = Objects.requireNonNull(informerConfig);
this.groupVersionKind = groupVersionKind;
this.primaryToSecondaryMapper = primaryToSecondaryMapper;
this.secondaryToPrimaryMapper = secondaryToPrimaryMapper;
this.kubernetesClient = kubernetesClient;
this.comparableResourceVersions = comparableResourceVersions;
this.comparableResourceVersion = comparableResourceVersion;
}

@Override
Expand Down Expand Up @@ -141,8 +141,8 @@ public Optional<KubernetesClient> getKubernetesClient() {
}

@Override
public boolean comparableResourceVersions() {
return this.comparableResourceVersions;
public boolean comparableResourceVersion() {
return this.comparableResourceVersion;
}
}

Expand All @@ -157,7 +157,7 @@ class Builder<R extends HasMetadata> {
private PrimaryToSecondaryMapper<?> primaryToSecondaryMapper;
private SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
private KubernetesClient kubernetesClient;
private boolean comparableResourceVersions = DEFAULT_COMPARABLE_RESOURCE_VERSIONS;
private boolean comparableResourceVersion = DEFAULT_COMPARABLE_RESOURCE_VERSION;

private Builder(Class<R> resourceClass, Class<? extends HasMetadata> primaryResourceClass) {
this(resourceClass, primaryResourceClass, null);
Expand Down Expand Up @@ -295,8 +295,8 @@ public Builder<R> withFieldSelector(FieldSelector fieldSelector) {
return this;
}

public Builder<R> withComparableResourceVersions(boolean comparableResourceVersions) {
this.comparableResourceVersions = comparableResourceVersions;
public Builder<R> withComparableResourceVersion(boolean comparableResourceVersion) {
this.comparableResourceVersion = comparableResourceVersion;
return this;
}

Expand Down Expand Up @@ -340,9 +340,9 @@ public InformerEventSourceConfiguration<R> build() {
false)),
config.build(),
kubernetesClient,
comparableResourceVersions);
comparableResourceVersion);
}
}

boolean comparableResourceVersions();
boolean comparableResourceVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class Constants {
public static final String RESOURCE_GVK_KEY = "josdk.resource.gvk";
public static final String CONTROLLER_NAME = "controller.name";
public static final boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES = true;
public static final boolean DEFAULT_COMPARABLE_RESOURCE_VERSIONS = true;
public static final boolean DEFAULT_COMPARABLE_RESOURCE_VERSION = true;

private Constants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ControllerEventSource(Controller<T> controller) {
NAME,
controller.getCRClient(),
controller.getConfiguration(),
controller.getConfiguration().getConfigurationService().comparableResourceVersions());
controller.getConfiguration().getInformerConfig().isComparableResourceVersions());
this.controller = controller;

final var config = controller.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.PrimaryToSecondaryMapper;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSIONS;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSION;

/**
* Wraps informer(s) so they are connected to the eventing system of the framework. Note that since
Expand Down Expand Up @@ -86,11 +86,11 @@ public InformerEventSource(
this(
configuration,
configuration.getKubernetesClient().orElse(context.getClient()),
configuration.comparableResourceVersions());
configuration.comparableResourceVersion());
}

InformerEventSource(InformerEventSourceConfiguration<R> configuration, KubernetesClient client) {
this(configuration, client, DEFAULT_COMPARABLE_RESOURCE_VERSIONS);
this(configuration, client, DEFAULT_COMPARABLE_RESOURCE_VERSION);
}

@SuppressWarnings({"unchecked", "rawtypes"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class ComparableResourceVersionsDisabledIT {
@RegisterExtension
LocallyRunOperatorExtension operator =
LocallyRunOperatorExtension.builder()
.withReconciler(new CreateUpdateEventFilterTestReconciler())
.withConfigurationService(overrider -> overrider.withComparableResourceVersions(false))
.withReconciler(new CreateUpdateEventFilterTestReconciler(false))
.build();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public class CreateUpdateEventFilterTestReconciler
private final DirectConfigMapDependentResource configMapDR =
new DirectConfigMapDependentResource(ConfigMap.class);

private final boolean comparableResourceVersion;

public CreateUpdateEventFilterTestReconciler(boolean comparableResourceVersion) {
this.comparableResourceVersion = comparableResourceVersion;
}

public CreateUpdateEventFilterTestReconciler() {
this(true);
}

@Override
public UpdateControl<CreateUpdateEventFilterTestCustomResource> reconcile(
CreateUpdateEventFilterTestCustomResource resource,
Expand Down Expand Up @@ -89,6 +99,7 @@ public List<EventSource<?, CreateUpdateEventFilterTestCustomResource>> prepareEv
InformerEventSourceConfiguration.from(
ConfigMap.class, CreateUpdateEventFilterTestCustomResource.class)
.withLabelSelector("integrationtest = " + this.getClass().getSimpleName())
.withComparableResourceVersion(comparableResourceVersion)
.build();

final var informerEventSource = new InformerEventSource<>(informerConfiguration, context);
Expand Down