File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
operator-framework-core/src/main/java/io/javaoperatorsdk/operator Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -137,13 +137,21 @@ public <R extends CustomResource> void register(
137
137
controller .init (eventSourceManager );
138
138
closeables .add (eventSourceManager );
139
139
140
+ final var effectiveNamespaces = configuration .getEffectiveNamespaces ();
141
+ if (configuration .isCurrentNamespaceMissing () && configuration .watchCurrentNamespace ()) {
142
+ throw new OperatorException (
143
+ "Controller '"
144
+ + controllerName
145
+ + "' is configured to watch the current namespace but it couldn't be inferred from the current configuration. " );
146
+ }
147
+
148
+ final var watchedNS =
149
+ configuration .watchAllNamespaces () ? "[all namespaces]" : effectiveNamespaces ;
140
150
log .info (
141
151
"Registered Controller: '{}' for CRD: '{}' for namespace(s): {}" ,
142
152
controllerName ,
143
153
resClass ,
144
- configuration .watchAllNamespaces ()
145
- ? "[all namespaces]"
146
- : configuration .getEffectiveNamespaces ());
154
+ watchedNS );
147
155
}
148
156
}
149
157
}
Original file line number Diff line number Diff line change 3
3
import io .fabric8 .kubernetes .client .CustomResource ;
4
4
import io .javaoperatorsdk .operator .api .Controller ;
5
5
import java .util .Collections ;
6
+ import java .util .Objects ;
6
7
import java .util .Set ;
7
8
8
9
public interface ControllerConfiguration <R extends CustomResource > {
@@ -41,6 +42,13 @@ static boolean currentNamespaceWatched(Set<String> namespaces) {
41
42
&& namespaces .contains (Controller .WATCH_CURRENT_NAMESPACE );
42
43
}
43
44
45
+ /**
46
+ * Computes the effective namespaces based on the set specified by the user, in particular
47
+ * retrieves the current namespace from the client when the user specified that they wanted to
48
+ * watch the current namespace only.
49
+ *
50
+ * @return a Set of namespace names the associated controller will watch
51
+ */
44
52
default Set <String > getEffectiveNamespaces () {
45
53
var targetNamespaces = getNamespaces ();
46
54
if (watchCurrentNamespace ()) {
@@ -54,6 +62,12 @@ default Set<String> getEffectiveNamespaces() {
54
62
return targetNamespaces ;
55
63
}
56
64
65
+ default boolean isCurrentNamespaceMissing () {
66
+ final var effectiveNamespaces = getEffectiveNamespaces ();
67
+ return effectiveNamespaces .size () == 1
68
+ && effectiveNamespaces .stream ().allMatch (Objects ::isNull );
69
+ }
70
+
57
71
default RetryConfiguration getRetryConfiguration () {
58
72
return RetryConfiguration .DEFAULT ;
59
73
}
You can’t perform that action at this time.
0 commit comments