Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
  • Loading branch information
csviri authored and metacosm committed Jan 25, 2025
1 parent b406787 commit 1280bf7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE;
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 @@ -88,7 +88,7 @@
* Set that in case of a runtime controller namespace changes, the informer should also follow the
* new namespace set.
*/
boolean followControllerNamespacesOnChange() default DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE;
boolean followControllerNamespaceChanges() default DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES;

/**
* Replaces the item store used by the informer for the associated primary resource controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class InformerConfiguration<R extends HasMetadata> {
private final String resourceTypeName;
private String name;
private Set<String> namespaces;
private Boolean followControllerNamespacesChanges;
private Boolean followsControllerNamespaceChanges;
private String labelSelector;
private OnAddFilter<? super R> onAddFilter;
private OnUpdateFilter<? super R> onUpdateFilter;
Expand All @@ -46,7 +46,7 @@ protected InformerConfiguration(Class<R> resourceClass, String name, Set<String>
this(resourceClass);
this.name = name;
this.namespaces = namespaces;
this.followControllerNamespacesChanges = followControllerNamespacesOnChange;
this.followsControllerNamespaceChanges = followControllerNamespacesOnChange;
this.labelSelector = labelSelector;
this.onAddFilter = onAddFilter;
this.onUpdateFilter = onUpdateFilter;
Expand Down Expand Up @@ -75,7 +75,7 @@ public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder(
public static <R extends HasMetadata> InformerConfiguration<R>.Builder builder(
InformerConfiguration<R> original) {
return new InformerConfiguration(original.resourceClass, original.name, original.namespaces,
original.followControllerNamespacesChanges, original.labelSelector, original.onAddFilter,
original.followsControllerNamespaceChanges, original.labelSelector, original.onAddFilter,
original.onUpdateFilter, original.onDeleteFilter, original.genericFilter,
original.itemStore, original.informerListLimit).builder;
}
Expand Down Expand Up @@ -184,8 +184,8 @@ public Set<String> getEffectiveNamespaces(ControllerConfiguration<?> controllerC
*
* @return if namespace changes should be followed
*/
public boolean getFollowControllerNamespacesChanges() {
return followControllerNamespacesChanges;
public boolean getFollowsControllerNamespaceChanges() {
return followsControllerNamespaceChanges;
}

/**
Expand Down Expand Up @@ -258,7 +258,7 @@ public InformerConfiguration<R> buildForController() {
namespaces = Constants.DEFAULT_NAMESPACES_SET;
}
// to avoid potential NPE
followControllerNamespacesChanges = false;
followsControllerNamespaceChanges = false;
return InformerConfiguration.this;
}

Expand All @@ -267,9 +267,9 @@ public InformerConfiguration<R> build() {
if (namespaces == null || namespaces.isEmpty()) {
namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES_SET;
}
if (followControllerNamespacesChanges == null) {
followControllerNamespacesChanges =
DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE;
if (followsControllerNamespaceChanges == null) {
followsControllerNamespaceChanges =
DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES;
}
return InformerConfiguration.this;
}
Expand Down Expand Up @@ -305,7 +305,7 @@ public InformerConfiguration<R>.Builder initFromAnnotation(Informer informerConf
context));

withFollowControllerNamespacesChanges(
informerConfig.followControllerNamespacesOnChange());
informerConfig.followControllerNamespaceChanges());

withItemStore(Utils.instantiate(informerConfig.itemStore(),
ItemStore.class, context));
Expand Down Expand Up @@ -373,7 +373,7 @@ public Builder withWatchCurrentNamespace() {
* @return the builder instance so that calls can be chained fluently
*/
public Builder withFollowControllerNamespacesChanges(boolean followChanges) {
InformerConfiguration.this.followControllerNamespacesChanges =
InformerConfiguration.this.followsControllerNamespaceChanges =
followChanges;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static Builder<GenericKubernetesResource> from(
* @return if namespace changes should be followed
*/
default boolean followControllerNamespaceChanges() {
return getInformerConfig().getFollowControllerNamespacesChanges();
return getInformerConfig().getFollowsControllerNamespaceChanges();
}

/**
Expand Down Expand Up @@ -195,7 +195,7 @@ public void updateFrom(InformerConfiguration<R> informerConfig) {
}
config.withNamespaces(informerConfig.getNamespaces())
.withFollowControllerNamespacesChanges(
informerConfig.getFollowControllerNamespacesChanges())
informerConfig.getFollowsControllerNamespaceChanges())
.withLabelSelector(informerConfig.getLabelSelector())
.withItemStore(informerConfig.getItemStore())
.withOnAddFilter(informerConfig.getOnAddFilter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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_NAMESPACES_ON_CHANGE = true;
public static final boolean DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES = true;

private Constants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void currentNamespaceWatched() {

@Test
void nullLabelSelectorByDefault() {
final var informerConfig =
InformerConfiguration.builder(ConfigMap.class).build();
final var informerConfig = InformerConfiguration.builder(ConfigMap.class).build();
assertNull(informerConfig.getLabelSelector());
}

Expand All @@ -61,7 +60,7 @@ void shouldWatchAllNamespacesByDefaultForControllers() {
@Test
void shouldFollowControllerNamespacesByDefaultForInformerEventSource() {
final var informerConfig = InformerConfiguration.builder(ConfigMap.class).build();
assertTrue(informerConfig.getFollowControllerNamespacesChanges());
assertTrue(informerConfig.getFollowsControllerNamespaceChanges());
}

@Test
Expand Down

0 comments on commit 1280bf7

Please sign in to comment.