File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
operator-framework-core/src/main/java/io/javaoperatorsdk/operator Expand file tree Collapse file tree 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(
9595 }
9696
9797 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+
99106 Class <R > resClass = configuration .getCustomResourceClass ();
100107 String finalizer = configuration .getFinalizer ();
101108
Original file line number Diff line number Diff line change 1010public @interface Controller {
1111
1212 String NULL = "" ;
13+ String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT" ;
1314
1415 String name () default NULL ;
1516
Original file line number Diff line number Diff line change 11package io .javaoperatorsdk .operator .api .config ;
22
33import io .fabric8 .kubernetes .client .CustomResource ;
4+ import io .javaoperatorsdk .operator .api .Controller ;
45import java .util .Collections ;
56import java .util .Set ;
67
78public interface ControllerConfiguration <R extends CustomResource > {
9+
810 String getName ();
911
1012 String getCRDName ();
@@ -25,6 +27,11 @@ default boolean watchAllNamespaces() {
2527 return getNamespaces ().isEmpty ();
2628 }
2729
30+ default boolean watchCurrentNamespace () {
31+ final var namespaces = getNamespaces ();
32+ return namespaces .size () == 1 && namespaces .contains (Controller .WATCH_CURRENT_NAMESPACE );
33+ }
34+
2835 default RetryConfiguration getRetryConfiguration () {
2936 return RetryConfiguration .DEFAULT ;
3037 }
You can’t perform that action at this time.
0 commit comments