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 @@ -653,7 +653,7 @@ default InformerPool informerPool() {
* the operator creates or updates.
*
* @return the list of aspects to apply to computed desired states, empty by default
* @since 5.6.0
* @since 5.7.0
*/
default List<DesiredStateAspect> desiredStateAspects() {
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public ConfigurationServiceOverrider withInformerPool(InformerPool informerPool)
*
* @param desiredStateAspects the aspects to apply, in the order in which they should be applied
* @return this {@link ConfigurationServiceOverrider} for chained customization
* @since 5.6.0
* @since 5.7.0
*/
public ConfigurationServiceOverrider withDesiredStateAspects(
List<DesiredStateAspect> desiredStateAspects) {
Expand All @@ -312,7 +312,7 @@ public ConfigurationServiceOverrider withDesiredStateAspects(
*
* @param desiredStateAspects the aspects to append, in the order in which they should be applied
* @return this {@link ConfigurationServiceOverrider} for chained customization
* @since 5.6.0
* @since 5.7.0
*/
public ConfigurationServiceOverrider addDesiredStateAspects(
DesiredStateAspect... desiredStateAspects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public R update(R actual, R desired, P primary, Context<P> context) {

@Override
public Result<R> match(R resource, P primary, Context<P> context) {
// retrieve the desired state via the context so that it is processed the same way as for
// non-bulk dependents, in particular so that configured DesiredStateAspects are applied
// before matching
return bulkDependentResource.match(resource, getOrComputeDesired(context), primary, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ protected SharedIndexInformer createInformer(InformerClassifier<?> classifier) {
Optional.ofNullable(classifier.itemStore()).ifPresent(informer::itemStore);

if (classifier.withoutNamespaceIndex()) {
// the framework only reads the indexes registered through the resource cache, never this one
informer.removeNamespaceIndex();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.Cache;
Expand Down Expand Up @@ -80,25 +78,11 @@ public PerResourcePollingEventSource(
this.resourceFetcher = config.resourceFetcher();
this.registerPredicate = config.registerPredicate();
this.configuredExecutorService = config.executorService();
var configurationService = configurationServiceOf(context);
this.useVirtualThreads =
configurationService != null && configurationService.useVirtualThreads();
this.useVirtualThreads = PollingExecutors.useVirtualThreads(context);
this.ownsExecutorService = configuredExecutorService == null;
this.period = config.defaultPollingPeriod();
}

/**
* The configuration of the operator the event source belongs to, or {@code null} if it doesn't
* belong to one, which only happens when the event source is used standalone, outside an
* operator.
*/
private static ConfigurationService configurationServiceOf(EventSourceContext<?> context) {
final var controllerConfiguration = context.getControllerConfiguration();
return controllerConfiguration == null
? null
: controllerConfiguration.getConfigurationService();
}

@Override
public void start() throws OperatorException {
if (isRunning()) {
Expand All @@ -119,8 +103,7 @@ private ScheduledExecutorService resolveExecutorService() {
if (configuredExecutorService != null) {
return configuredExecutorService;
}
return ExecutorServiceManager.newScheduledExecutorService(
1, useVirtualThreads, "josdk-polling-" + name());
return PollingExecutors.newExecutor(name(), useVirtualThreads);
}

private Set<R> getAndCacheResource(P primary, boolean fromGetter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.health.Status;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
Expand Down Expand Up @@ -89,7 +88,7 @@ public class PollingEventSource<R, P extends HasMetadata, ID>
*/
public PollingEventSource(
Class<R> resourceClass, EventSourceContext<P> context, PollingConfiguration<R, ID> config) {
this(resourceClass, config, configurationServiceOf(context));
this(resourceClass, config, PollingExecutors.useVirtualThreads(context));
}

/**
Expand All @@ -100,34 +99,19 @@ public PollingEventSource(
*/
@Deprecated(since = "5.7.0")
public PollingEventSource(Class<R> resourceClass, PollingConfiguration<R, ID> config) {
this(resourceClass, config, null);
this(resourceClass, config, false);
}

private PollingEventSource(
Class<R> resourceClass,
PollingConfiguration<R, ID> config,
ConfigurationService configurationService) {
Class<R> resourceClass, PollingConfiguration<R, ID> config, boolean useVirtualThreads) {
super(config.name(), resourceClass, config.resourceIDMapper());
this.genericResourceFetcher = config.genericResourceFetcher();
this.period = config.period();
this.configuredExecutorService = config.executorService();
this.useVirtualThreads =
configurationService != null && configurationService.useVirtualThreads();
this.useVirtualThreads = useVirtualThreads;
this.ownsExecutorService = configuredExecutorService == null;
}

/**
* The configuration of the operator the event source belongs to, or {@code null} if it doesn't
* belong to one, which only happens when the event source is used standalone, outside an
* operator.
*/
private static ConfigurationService configurationServiceOf(EventSourceContext<?> context) {
final var controllerConfiguration = context.getControllerConfiguration();
return controllerConfiguration == null
? null
: controllerConfiguration.getConfigurationService();
}

@Override
public void start() throws OperatorException {
if (pollingTask != null) {
Expand Down Expand Up @@ -187,8 +171,7 @@ private ScheduledExecutorService resolveExecutorService() {
if (configuredExecutorService != null) {
return configuredExecutorService;
}
return ExecutorServiceManager.newScheduledExecutorService(
1, useVirtualThreads, "josdk-polling-" + name());
return PollingExecutors.newExecutor(name(), useVirtualThreads);
}

protected synchronized void getStateAndFillCache() {
Expand All @@ -204,7 +187,6 @@ public interface GenericResourceFetcher<R> {
public void stop() throws OperatorException {
super.stop();
if (pollingTask != null) {
// as with the java.util.Timer this replaces, an ongoing poll is left to finish
pollingTask.cancel(false);
pollingTask = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Java Operator SDK Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.javaoperatorsdk.operator.processing.event.source.polling;

import java.util.concurrent.ScheduledExecutorService;

import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;

final class PollingExecutors {

private PollingExecutors() {}

/**
* Whether the operator the event source belongs to is configured to use virtual threads. The
* controller configuration is {@code null} when the event source is used standalone, outside an
* operator.
*/
static boolean useVirtualThreads(EventSourceContext<?> context) {
final var controllerConfiguration = context.getControllerConfiguration();
if (controllerConfiguration == null) {
return false;
}
final var configurationService = controllerConfiguration.getConfigurationService();
return configurationService != null && configurationService.useVirtualThreads();
}

static ScheduledExecutorService newExecutor(String eventSourceName, boolean useVirtualThreads) {
return ExecutorServiceManager.newScheduledExecutorService(
1, useVirtualThreads, "josdk-polling-" + eventSourceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public TimerEventSource() {
this.ownsExecutorService = true;
}

/**
* @deprecated use {@link #TimerEventSource(String, boolean, Supplier)} instead, passing {@code
* null} as the supplier to keep the previous behavior.
*/
@Deprecated(since = "5.7.0")
public TimerEventSource(String name, boolean triggerReconcilerOnAllEvents) {
this(name, triggerReconcilerOnAllEvents, null);
}
Expand Down Expand Up @@ -134,8 +139,6 @@ public void onResourceDeleted(R resource) {
public void cancelOnceSchedule(ResourceID customResourceUid) {
var scheduled = onceTasks.remove(customResourceUid);
if (scheduled != null) {
// as with the java.util.TimerTask this replaces, a task that is already running is left to
// finish
scheduled.cancel(false);
}
}
Expand Down
Loading