Skip to content

Commit

Permalink
fix: make DefaultRateLimiter class discoverable for configuration
Browse files Browse the repository at this point in the history
Fixes #756

Signed-off-by: Chris Laprun <[email protected]>
  • Loading branch information
metacosm committed Nov 20, 2023
1 parent 8bc9ccc commit f2ae45d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow;
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
Expand Down Expand Up @@ -201,7 +202,12 @@ static QuarkusControllerConfiguration createConfiguration(
controllerAnnotation,
"rateLimiter", av -> loadClass(av.asClass().name().toString(), RateLimiter.class),
() -> DefaultRateLimiter.class);
final var rateLimiterConfigurableInfo = configurableInfos.get(rateLimiterClass.getName());
// ugly hack: we currently need this because DefaultRateLimiter is not currently found as an implementor of AnnotationConfigurable
var rateLimiterClassNameForConfigurable = rateLimiterClass.getName();
if (DefaultRateLimiter.class.equals(rateLimiterClass)) {
rateLimiterClassNameForConfigurable = LinearRateLimiter.class.getName();
}
final var rateLimiterConfigurableInfo = configurableInfos.get(rateLimiterClassNameForConfigurable);
rateLimiterConfigurationClass = getConfigurationAnnotationClass(reconcilerInfo,
rateLimiterConfigurableInfo);
nullableInformerListLimit = ConfigurationUtils.annotationValueOrDefault(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.quarkiverse.operatorsdk.it;

import java.util.concurrent.TimeUnit;

import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.processing.event.rate.RateLimited;
import io.javaoperatorsdk.operator.processing.retry.GradualRetry;

@ControllerConfiguration(name = ConfiguredReconciler.NAME, namespaces = "foo")
@GradualRetry(maxAttempts = ConfiguredReconciler.MAX_ATTEMPTS)
@RateLimited(maxReconciliations = 1, within = 1, unit = TimeUnit.MINUTES)
public class ConfiguredReconciler implements Reconciler<ChildTestResource2> {

public static final String NAME = "annotation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig;
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow;
import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
import io.javaoperatorsdk.operator.processing.retry.Retry;
import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService;
import io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration;
Expand Down Expand Up @@ -224,6 +225,20 @@ public List<JSONDependentResourceSpec> getDependents() {
public long maxReconciliationIntervalSeconds() {
return conf.maxReconciliationInterval().map(Duration::getSeconds).orElseThrow();
}

public String getRateLimiterClass() {
return conf.getRateLimiter().getClass().getCanonicalName();
}

public long getRefreshPeriodSeconds() {
final var rateLimiter = conf.getRateLimiter();
if (rateLimiter instanceof LinearRateLimiter) {
LinearRateLimiter limiter = (LinearRateLimiter) rateLimiter;
return limiter.getRefreshPeriod().getSeconds();
} else {
return -1;
}
}
}

static class JSONDependentResourceSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.api.Test;

import io.javaoperatorsdk.operator.ReconcilerUtils;
import io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.DisabledOnIntegrationTest;
import io.quarkus.test.junit.QuarkusTest;
Expand Down Expand Up @@ -149,6 +150,8 @@ void applicationPropertiesShouldOverrideDefaultAndAnnotation() {
"retryConfiguration.maxAttempts", equalTo(10),
"retry.maxAttempts", equalTo(ConfiguredReconciler.MAX_ATTEMPTS),
"retryConfiguration.initialInterval", equalTo(20000),
"rateLimiterClass", equalTo(QuarkusControllerConfiguration.DefaultRateLimiter.class.getCanonicalName()),
"refreshPeriodSeconds", equalTo(60),
"labelSelector", equalTo("environment=production,tier!=frontend"));

given()
Expand Down

0 comments on commit f2ae45d

Please sign in to comment.