Skip to content

Commit 579662e

Browse files
committed
fix: remove isClusterScoped method from Controller
A controller is not cluster-scoped, its associated custom resource type is. As such, this functionality should (and is) controlled by the custom resource type associated with the controller, not the controller itself. If a custom resource implementation doesn't implement Namespaced then it is cluster-scoped.
1 parent b348ba6 commit 579662e

File tree

8 files changed

+15
-31
lines changed

8 files changed

+15
-31
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ Note that these docs are currently in progress.
6363
types, so you can have an empty default implementation that does what you'd expect. If you don't
6464
need a status, using `Void` for the associated type should work.
6565
- Custom Resources that are namespace-scoped need to implement the `Namespaced` interface so that
66-
the client can generate the proper URLs.
66+
the client can generate the proper URLs. This means, in particular, that `CustomResource`
67+
implementations that do **not** implement `Namespaced` are considered cluster-scoped. As a
68+
consequence, the `isClusterScoped` method/field has been removed from the appropriate
69+
classes (`Controller` annotation, in particular) as this is now inferred from the `CustomResource`
70+
type associated with your `Controller`.
6771

6872
Many of these changes might not be immediately apparent but will result in `404` errors when
6973
connecting to the cluster. Please check that the Custom Resource implementations are properly

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
*/
2727
boolean generationAwareEventProcessing() default true;
2828

29-
boolean isClusterScoped() default false;
30-
29+
/**
30+
* Specified which namespaces this Controller monitors for custom resources events. If no
31+
* namespace is specified then the controller will monitor the namespace it is deployed in (or the
32+
* namespace to which the Kubernetes client is connected to). To specify that the controller needs
33+
* to monitor all namespaces, add {@link
34+
* io.javaoperatorsdk.operator.api.config.ControllerConfiguration#WATCH_ALL_NAMESPACES_MARKER} to
35+
* this field.
36+
*
37+
* @return the list of namespaces this controller monitors
38+
*/
3139
String[] namespaces() default {};
3240
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public interface ControllerConfiguration<R extends CustomResource> {
2020

2121
String getAssociatedControllerClassName();
2222

23-
default boolean isClusterScoped() {
24-
return false;
25-
}
26-
2723
default Set<String> getNamespaces() {
2824
return Collections.emptySet();
2925
}

operator-framework-quarkus-extension/deployment/src/main/java/io/javaoperatorsdk/quarkus/extension/deployment/QuarkusExtensionProcessor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ private ControllerConfiguration createControllerConfiguration(
160160
"generationAwareEventProcessing",
161161
AnnotationValue::asBoolean,
162162
() -> true),
163-
valueOrDefault(
164-
controllerAnnotation, "isClusterScoped", AnnotationValue::asBoolean, () -> false),
165163
QuarkusControllerConfiguration.asSet(
166164
valueOrDefault(
167165
controllerAnnotation,

operator-framework-quarkus-extension/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/QuarkusControllerConfiguration.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class QuarkusControllerConfiguration<R extends CustomResource>
1414
private final String crdName;
1515
private final String finalizer;
1616
private final boolean generationAware;
17-
private final boolean clusterScoped;
1817
private final Set<String> namespaces;
1918
private final String crClass;
2019
private final boolean watchAllNamespaces;
@@ -27,7 +26,6 @@ public QuarkusControllerConfiguration(
2726
String crdName,
2827
String finalizer,
2928
boolean generationAware,
30-
boolean clusterScoped,
3129
Set<String> namespaces,
3230
String crClass,
3331
RetryConfiguration retryConfiguration) {
@@ -36,7 +34,6 @@ public QuarkusControllerConfiguration(
3634
this.crdName = crdName;
3735
this.finalizer = finalizer;
3836
this.generationAware = generationAware;
39-
this.clusterScoped = clusterScoped;
4037
this.namespaces = namespaces;
4138
this.crClass = crClass;
4239
this.watchAllNamespaces = this.namespaces.contains(WATCH_ALL_NAMESPACES_MARKER);
@@ -100,11 +97,6 @@ public String getAssociatedControllerClassName() {
10097
return associatedControllerClassName;
10198
}
10299

103-
@Override
104-
public boolean isClusterScoped() {
105-
return clusterScoped;
106-
}
107-
108100
@Override
109101
public Set<String> getNamespaces() {
110102
return namespaces;

operator-framework-quarkus-extension/tests/src/main/java/io/javaoperatorsdk/quarkus/it/TestOperatorApp.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public String getAssociatedControllerClassName() {
6565
return conf.getAssociatedControllerClassName();
6666
}
6767

68-
public boolean isClusterScoped() {
69-
return conf.isClusterScoped();
70-
}
71-
7268
public Set<String> getNamespaces() {
7369
return conf.getNamespaces();
7470
}

operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ public Class<R> getCustomResourceClass() {
100100
return super.getCustomResourceClass();
101101
}
102102

103-
@Override
104-
public boolean isClusterScoped() {
105-
return properties.map(ControllerProperties::isClusterScoped).orElse(super.isClusterScoped());
106-
}
107-
108103
@Override
109104
public Set<String> getNamespaces() {
110105
return properties.map(ControllerProperties::getNamespaces).orElse(super.getNamespaces());

operator-framework/src/main/java/io/javaoperatorsdk/operator/config/runtime/AnnotationConfiguration.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ public Class<R> getCustomResourceClass() {
4747
return RuntimeControllerMetadata.getCustomResourceClass(controller);
4848
}
4949

50-
@Override
51-
public boolean isClusterScoped() {
52-
return annotation.isClusterScoped();
53-
}
54-
5550
@Override
5651
public Set<String> getNamespaces() {
5752
return Set.of(annotation.namespaces());

0 commit comments

Comments
 (0)