Skip to content

Commit

Permalink
refactor: rename based on JOSDK changes
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Laprun <[email protected]>
  • Loading branch information
metacosm committed Aug 12, 2024
1 parent ece9a34 commit 1ccf2b7
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.quarkiverse.operatorsdk.bundle.sources;

import io.javaoperatorsdk.operator.api.config.informer.Informer;
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.dependent.kubernetes.InformerConfig;
import io.quarkiverse.operatorsdk.annotations.CSVMetadata;
import io.quarkiverse.operatorsdk.annotations.RBACRule;

@CSVMetadata(bundleName = "second-operator")
@RBACRule(apiGroups = SecondReconciler.RBAC_RULE_GROUP, resources = SecondReconciler.RBAC_RULE_RES, verbs = SecondReconciler.RBAC_RULE_VERBS)
@ControllerConfiguration(informerConfig = @InformerConfig(namespaces = "foo"))
@ControllerConfiguration(informer = @Informer(namespaces = "foo"))
public class SecondReconciler implements Reconciler<Second> {
public static final String RBAC_RULE_GROUP = "halkyon.io";
public static final String RBAC_RULE_RES = "SomeResource";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder;
import io.fabric8.kubernetes.api.model.rbac.RoleRef;
import io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration;
import io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration;

Expand Down Expand Up @@ -60,7 +61,8 @@ private List<HasMetadata> bindingsFor(QuarkusControllerConfiguration<?> controll
final var controllerName = controllerConfiguration.getName();

// retrieve which namespaces should be used to generate either from annotation or from the build time configuration
final var desiredWatchedNamespaces = controllerConfiguration.getNamespaces();
final InformerConfiguration<?> informerConfig = controllerConfiguration.getInformerConfig();
final var desiredWatchedNamespaces = informerConfig.getNamespaces();

// if we validate the CRDs, also create a binding for the CRD validating role
List<HasMetadata> itemsToAdd;
Expand All @@ -75,6 +77,7 @@ private List<HasMetadata> bindingsFor(QuarkusControllerConfiguration<?> controll
}

final var roleBindingName = getRoleBindingName(controllerName);
// if (informerConfig.watchCurrentNamespace()) {
if (controllerConfiguration.watchCurrentNamespace()) {
// create a RoleBinding that will be applied in the current namespace if watching only the current NS
itemsToAdd.add(createRoleBinding(roleBindingName, serviceAccountName, null,
Expand All @@ -85,6 +88,7 @@ private List<HasMetadata> bindingsFor(QuarkusControllerConfiguration<?> controll
final var specificRoleBindingName = getSpecificRoleBindingName(controllerName, roleRef);
itemsToAdd.add(createRoleBinding(specificRoleBindingName, serviceAccountName, null, roleRef));
});
// } else if (informerConfig.watchAllNamespaces()) {
} else if (controllerConfiguration.watchAllNamespaces()) {
itemsToAdd.add(createClusterRoleBinding(serviceAccountName, controllerName,
getClusterRoleBindingName(controllerName), "watch all namespaces",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@
import io.quarkiverse.operatorsdk.common.Constants;
import io.quarkiverse.operatorsdk.common.ResourceAssociatedAugmentedClassInfo;
import io.quarkiverse.operatorsdk.deployment.devui.commands.ConsoleCommands;
import io.quarkiverse.operatorsdk.runtime.*;
import io.quarkiverse.operatorsdk.runtime.AppEventListener;
import io.quarkiverse.operatorsdk.runtime.BuildTimeOperatorConfiguration;
import io.quarkiverse.operatorsdk.runtime.ConfigurationServiceRecorder;
import io.quarkiverse.operatorsdk.runtime.KubernetesClientObjectMapperCustomizer;
import io.quarkiverse.operatorsdk.runtime.KubernetesClientSerializationCustomizer;
import io.quarkiverse.operatorsdk.runtime.NoOpMetricsProvider;
import io.quarkiverse.operatorsdk.runtime.OperatorHealthCheck;
import io.quarkiverse.operatorsdk.runtime.OperatorProducer;
import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService;
import io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration;
import io.quarkiverse.operatorsdk.runtime.RunTimeOperatorConfiguration;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
Expand All @@ -33,7 +43,13 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.*;
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.deployment.builditem.ApplicationIndexBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ConsoleCommandBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ForceNonWeakReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
Expand Down Expand Up @@ -253,7 +269,7 @@ void initializeRuntimeNamespacesFromBuildTimeValues(
BuildProducer<RunTimeConfigurationDefaultBuildItem> runtimeConfig) {
configurations.getControllerConfigs().forEach((name, configuration) -> {
@SuppressWarnings("unchecked")
final var namespaces = String.join(",", configuration.getNamespaces());
final var namespaces = String.join(",", configuration.getInformerConfig().getNamespaces());
runtimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(
"quarkus.operator-sdk.controllers." + configuration.getName() + ".namespaces",
namespaces));
Expand All @@ -266,8 +282,9 @@ private void registerAssociatedClassesForReflection(BuildProducer<ReflectiveHier
Set<String> classNamesToRegister) {
// todo: use builder API when/if https://github.com/quarkusio/quarkus/pull/38679 is available
classNamesToRegister.forEach(cn -> {
reflectionClasses.produce(new ReflectiveHierarchyBuildItem.Builder()
.type(Type.create(DotName.createSimple(cn), Type.Kind.CLASS)).build());
reflectionClasses.produce(
ReflectiveHierarchyBuildItem.builder(Type.create(DotName.createSimple(cn), Type.Kind.CLASS))
.build());
forcedReflectionClasses.produce(
new ForceNonWeakReflectiveClassBuildItem(cn));
log.infov("Registered ''{0}'' for reflection", cn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.MaxReconciliationInterval;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentConverter;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource;
Expand Down Expand Up @@ -69,7 +69,7 @@ public KubernetesDependentResourceConfig configFrom(KubernetesDependent configAn
// make the configuration bytecode-serializable
return new QuarkusKubernetesDependentResourceConfig(
original.useSSA(), original.createResourceOnlyIfNotExistingWithSSA(),
new QuarkusInformerConfigHolder(original.informerConfig()));
new QuarkusInformerConfiguration(original.informerConfig()));
}
};
private static final Supplier<AnnotationInstance> NULL_ANNOTATION_SUPPLIER = () -> null;
Expand Down Expand Up @@ -186,7 +186,7 @@ static QuarkusControllerConfiguration createConfiguration(

// deal with informer configuration
final var informerConfigAnnotation = ConfigurationUtils.annotationValueOrDefault(controllerAnnotation,
"informerConfig", AnnotationValue::asNested, NULL_ANNOTATION_SUPPLIER);
"informer", AnnotationValue::asNested, NULL_ANNOTATION_SUPPLIER);
if (informerConfigAnnotation != null) {
onAddFilter = ConfigurationUtils.instantiateImplementationClass(
informerConfigAnnotation, "onAddFilter", OnAddFilter.class, OnAddFilter.class, true, index);
Expand Down Expand Up @@ -261,7 +261,7 @@ static QuarkusControllerConfiguration createConfiguration(
final Class<? extends HasMetadata> resourceClass = (Class<? extends HasMetadata>) primaryInfo.loadAssociatedClass();
final String resourceFullName = primaryAsResource.fullResourceName();

final var informerConfigHolder = InformerConfigHolder.builder(resourceClass)
final var informerConfigHolder = InformerConfiguration.builder(resourceClass)
.withName(informerName)
.withNamespaces(namespaces)
.withLabelSelector(labelSelector)
Expand All @@ -271,7 +271,7 @@ static QuarkusControllerConfiguration createConfiguration(
.withItemStore(itemStore)
.withInformerListLimit(nullableInformerListLimit)
.buildForController();
final var informerConfig = new QuarkusInformerConfigHolder(informerConfigHolder);
final var informerConfig = new QuarkusInformerConfiguration(informerConfigHolder);

configuration = new QuarkusControllerConfiguration(
reconcilerClassName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public class DefaultConfigurationTest {
@Test
void checkDefaultOperatorLevelNamespaces() {
final var config = configurationService.getConfigurationFor(testReconciler);
assertEquals(Constants.DEFAULT_NAMESPACES_SET, config.getNamespaces());
assertEquals(Constants.DEFAULT_NAMESPACES_SET, config.getInformerConfig().getNamespaces());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public class OneNSConfigurationTest {
@Test
void checkDefaultOperatorLevelNamespaces() {
final var config = configurationService.getConfigurationFor(testReconciler);
assertEquals(Set.of(OneNSReconciler.NS), config.getNamespaces());
assertEquals(Set.of(OneNSReconciler.NS), config.getInformerConfig().getNamespaces());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.quarkiverse.operatorsdk.test.sources;

import io.javaoperatorsdk.operator.api.config.informer.Informer;
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.dependent.kubernetes.InformerConfig;

@ControllerConfiguration(informerConfig = @InformerConfig(namespaces = OneNSReconciler.NS))
@ControllerConfiguration(informer = @Informer(namespaces = OneNSReconciler.NS))
public class OneNSReconciler implements Reconciler<TestCR> {

public static final String NS = "foo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

import io.javaoperatorsdk.operator.api.config.informer.Informer;
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.dependent.kubernetes.InformerConfig;

@ControllerConfiguration(name = WatchAllNamespacesReconciler.NAME, informerConfig = @InformerConfig(namespaces = WATCH_ALL_NAMESPACES))
@ControllerConfiguration(name = WatchAllNamespacesReconciler.NAME, informer = @Informer(namespaces = WATCH_ALL_NAMESPACES))
public class WatchAllNamespacesReconciler implements Reconciler<SimpleCR> {

public static final String NAME = "all-namespaces-reconciler";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationProvider;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
import io.javaoperatorsdk.operator.processing.event.rate.LinearRateLimiter;
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class QuarkusControllerConfiguration<R extends HasMetadata> implements Co
private QuarkusManagedWorkflow<R> workflow;
private QuarkusConfigurationService parent;
private ExternalGradualRetryConfiguration gradualRetry;
private QuarkusInformerConfigHolder<R> informerConfig;
private QuarkusInformerConfiguration<R> informerConfig;

@RecordableConstructor
@SuppressWarnings("unchecked")
Expand All @@ -75,7 +75,7 @@ public QuarkusControllerConfiguration(
Class<? extends Retry> retryClass, Class<? extends Annotation> retryConfigurationClass,
Class<? extends RateLimiter> rateLimiterClass, Class<? extends Annotation> rateLimiterConfigurationClass,
List<PolicyRule> additionalRBACRules, List<RoleRef> additionalRBACRoleRefs, String fieldManager,
QuarkusInformerConfigHolder<R> informerConfig) {
QuarkusInformerConfiguration<R> informerConfig) {
this.informerConfig = informerConfig;
this.associatedReconcilerClassName = associatedReconcilerClassName;
this.name = name;
Expand Down Expand Up @@ -156,8 +156,8 @@ public String getAssociatedReconcilerClassName() {

void setNamespaces(Set<String> namespaces) {
if (!namespaces.equals(informerConfig.getNamespaces())) {
informerConfig = new QuarkusInformerConfigHolder<>(
InformerConfigHolder.builder(informerConfig)
informerConfig = new QuarkusInformerConfiguration<>(
InformerConfiguration.builder(informerConfig)
.withNamespaces(namespaces)
.buildForController());
wereNamespacesSet = true;
Expand All @@ -179,7 +179,7 @@ public void propagateNamespacesToDependents() {
dependentsMetadata().forEach((unused, spec) -> {
final var config = spec.getConfiguration().orElse(null);
if (config instanceof QuarkusKubernetesDependentResourceConfig qConfig) {
qConfig.setNamespaces(getNamespaces());
qConfig.setNamespaces(informerConfig.getNamespaces());
}
});
}
Expand All @@ -196,7 +196,7 @@ public Set<String> getEffectiveNamespaces() {
}

void setLabelSelector(String labelSelector) {
informerConfig = new QuarkusInformerConfigHolder<>(InformerConfigHolder.builder(informerConfig)
informerConfig = new QuarkusInformerConfiguration<>(InformerConfiguration.builder(informerConfig)
.withLabelSelector(labelSelector)
.buildForController());
}
Expand Down Expand Up @@ -306,10 +306,11 @@ void initAnnotationConfigurables(Reconciler<R> reconciler) {
if (gradualRetry != null) {
// configurable should be a GenericRetry as validated by RetryResolver
final var genericRetry = (GenericRetry) retry;
gradualRetry.maxAttempts.ifPresent(genericRetry::setMaxAttempts);
gradualRetry.interval.initial.ifPresent(genericRetry::setInitialInterval);
gradualRetry.interval.max.ifPresent(genericRetry::setMaxInterval);
gradualRetry.interval.multiplier.ifPresent(genericRetry::setIntervalMultiplier);
gradualRetry.maxAttempts().ifPresent(genericRetry::setMaxAttempts);
final var intervalConfiguration = gradualRetry.interval();
intervalConfiguration.initial().ifPresent(genericRetry::setInitialInterval);
intervalConfiguration.max().ifPresent(genericRetry::setMaxInterval);
intervalConfiguration.multiplier().ifPresent(genericRetry::setIntervalMultiplier);
}
retryClass = null;
retryConfigurationClass = null;
Expand Down Expand Up @@ -374,16 +375,10 @@ public ItemStore<R> getNullableItemStore() {
}

@Override
public InformerConfigHolder<R> getInformerConfig() {
public InformerConfiguration<R> getInformerConfig() {
return informerConfig;
}

// required until https://github.com/quarkusio/quarkus/pull/41609 is available in a Quarkus release
@Override
public Set<String> getNamespaces() {
return informerConfig.getNamespaces();
}

// Needed by Quarkus because LinearRateLimiter doesn't expose setters for byte recording
public final static class DefaultRateLimiter extends LinearRateLimiter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.informers.cache.ItemStore;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter;
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;
import io.quarkus.runtime.annotations.RecordableConstructor;

public class QuarkusInformerConfigHolder<R extends HasMetadata> extends InformerConfigHolder<R> {
public class QuarkusInformerConfiguration<R extends HasMetadata> extends InformerConfiguration<R> {

@RecordableConstructor
public QuarkusInformerConfigHolder(String name, Set<String> namespaces,
public QuarkusInformerConfiguration(String name, Set<String> namespaces,
String labelSelector, OnAddFilter<? super R> onAddFilter,
OnUpdateFilter<? super R> onUpdateFilter, OnDeleteFilter<? super R> onDeleteFilter,
GenericFilter<? super R> genericFilter, ItemStore<R> itemStore, Long informerListLimit) {
super(name, namespaces, false, labelSelector, onAddFilter, onUpdateFilter, onDeleteFilter,
genericFilter, itemStore, informerListLimit);
}

public QuarkusInformerConfigHolder(InformerConfigHolder<R> config) {
public QuarkusInformerConfiguration(InformerConfiguration<R> config) {
this(config.getName(), sanitizeNamespaces(config.getNamespaces()),
config.getLabelSelector(),
config.getOnAddFilter(), config.getOnUpdateFilter(), config.getOnDeleteFilter(), config.getGenericFilter(),
Expand Down
Loading

0 comments on commit 1ccf2b7

Please sign in to comment.