Skip to content

refactor: clean namespaces constants #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -15,7 +15,7 @@
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACES;

@SuppressWarnings({"rawtypes", "unused"})
public class ControllerConfigurationOverrider<R extends HasMetadata> {
Expand Down Expand Up @@ -56,7 +56,7 @@ public ControllerConfigurationOverrider<R> withGenerationAware(boolean generatio
}

public ControllerConfigurationOverrider<R> watchingOnlyCurrentNamespace() {
this.namespaces = WATCH_CURRENT_NAMESPACE_SET;
this.namespaces = WATCH_CURRENT_NAMESPACES;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.javaoperatorsdk.operator.api.reconciler.Constants;

import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_NAMESPACES;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACES;

public interface ResourceConfiguration<R extends HasMetadata> {

Expand Down Expand Up @@ -53,7 +53,7 @@ default boolean watchCurrentNamespace() {

static boolean currentNamespaceWatched(Set<String> namespaces) {
failIfNotValid(namespaces);
return WATCH_CURRENT_NAMESPACE_SET.equals(namespaces);
return WATCH_CURRENT_NAMESPACES.equals(namespaces);
}

static void failIfNotValid(Set<String> namespaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ public final class Constants {

public static final Set<String> DEFAULT_NAMESPACES =
Collections.singleton(Constants.WATCH_ALL_NAMESPACES);
public static final Set<String> WATCH_CURRENT_NAMESPACE_SET =
public static final Set<String> WATCH_CURRENT_NAMESPACES =
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 about this, in this simple plural form it says we can watch more current namespace. While the case is that this is only a helper to wrap the WATCH_CURRENT_NAMESPACE. That is why I just added the SET suffix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then let's rename all the Set constants with the _SET suffix

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree!

Collections.singleton(Constants.WATCH_CURRENT_NAMESPACE);

public static final Set<String> SAME_AS_CONTROLLER_NAMESPACES =
Collections.singleton(Constants.SAME_AS_CONTROLLER);

public static final String NO_VALUE_SET = "";
public static final String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT";
public static final String WATCH_ALL_NAMESPACES = "JOSDK_ALL_NAMESPACES";
public static final long NO_RECONCILIATION_MAX_INTERVAL = -1L;
public static final String SAME_AS_CONTROLLER = "JOSDK_SAME_AS_CONTROLLER";

private Constants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

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

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

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface KubernetesDependent {
String SAME_AS_CONTROLLER = "JOSDK_SAME_AS_CONTROLLER";

String[] DEFAULT_NAMESPACES = {SAME_AS_CONTROLLER};
String[] DEFAULT_NAMESPACES = {Constants.SAME_AS_CONTROLLER};

/**
* Specified which namespaces this Controller monitors for custom resources events. If no
Expand All @@ -21,7 +22,7 @@
*
* @return the list of namespaces this controller monitors
*/
String[] namespaces() default {SAME_AS_CONTROLLER};
String[] namespaces() default {Constants.SAME_AS_CONTROLLER};

/**
* Optional label selector used to identify the set of custom resources the controller will acc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.javaoperatorsdk.operator.processing.dependent.kubernetes;

import java.util.Collections;
import java.util.Set;

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

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

public class KubernetesDependentResourceConfig {

private Set<String> namespaces = Collections.emptySet();
private Set<String> namespaces = Constants.SAME_AS_CONTROLLER_NAMESPACES;
private String labelSelector = NO_VALUE_SET;

private boolean namespacesWereConfigured = false;
Expand Down