File tree 3 files changed +16
-1
lines changed
operator-framework-core/src/main/java/io/javaoperatorsdk/operator
3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,14 @@ public <R extends CustomResource> void register(
95
95
}
96
96
97
97
final var retry = GenericRetry .fromConfiguration (configuration .getRetryConfiguration ());
98
- final var targetNamespaces = configuration .getNamespaces ().toArray (new String [] {});
98
+
99
+ // check if we only want to watch the current namespace
100
+ var targetNamespaces = configuration .getNamespaces ().toArray (new String [] {});
101
+ if (configuration .watchCurrentNamespace ()) {
102
+ targetNamespaces =
103
+ new String [] {configurationService .getClientConfiguration ().getNamespace ()};
104
+ }
105
+
99
106
Class <R > resClass = configuration .getCustomResourceClass ();
100
107
String finalizer = configuration .getFinalizer ();
101
108
Original file line number Diff line number Diff line change 10
10
public @interface Controller {
11
11
12
12
String NULL = "" ;
13
+ String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT" ;
13
14
14
15
String name () default NULL ;
15
16
Original file line number Diff line number Diff line change 1
1
package io .javaoperatorsdk .operator .api .config ;
2
2
3
3
import io .fabric8 .kubernetes .client .CustomResource ;
4
+ import io .javaoperatorsdk .operator .api .Controller ;
4
5
import java .util .Collections ;
5
6
import java .util .Set ;
6
7
7
8
public interface ControllerConfiguration <R extends CustomResource > {
9
+
8
10
String getName ();
9
11
10
12
String getCRDName ();
@@ -25,6 +27,11 @@ default boolean watchAllNamespaces() {
25
27
return getNamespaces ().isEmpty ();
26
28
}
27
29
30
+ default boolean watchCurrentNamespace () {
31
+ final var namespaces = getNamespaces ();
32
+ return namespaces .size () == 1 && namespaces .contains (Controller .WATCH_CURRENT_NAMESPACE );
33
+ }
34
+
28
35
default RetryConfiguration getRetryConfiguration () {
29
36
return RetryConfiguration .DEFAULT ;
30
37
}
You can’t perform that action at this time.
0 commit comments