12
12
import io .fabric8 .kubernetes .client .dsl .NonNamespaceOperation ;
13
13
import io .fabric8 .kubernetes .client .dsl .Resource ;
14
14
import io .javaoperatorsdk .operator .api .config .informer .InformerConfiguration ;
15
+ import io .javaoperatorsdk .operator .api .reconciler .Constants ;
15
16
import io .javaoperatorsdk .operator .api .reconciler .Context ;
16
17
import io .javaoperatorsdk .operator .api .reconciler .EventSourceContext ;
17
18
import io .javaoperatorsdk .operator .api .reconciler .dependent .managed .DependentResourceConfigurator ;
@@ -35,6 +36,7 @@ public abstract class KubernetesDependentResource<R extends HasMetadata, P exten
35
36
private final Matcher <R , P > matcher ;
36
37
private final ResourceUpdatePreProcessor <R > processor ;
37
38
private final Class <R > resourceType ;
39
+ private KubernetesDependentResourceConfig kubernetesDependentResourceConfig ;
38
40
39
41
@ SuppressWarnings ("unchecked" )
40
42
public KubernetesDependentResource (Class <R > resourceType ) {
@@ -49,12 +51,17 @@ public KubernetesDependentResource(Class<R> resourceType) {
49
51
50
52
@ Override
51
53
public void configureWith (KubernetesDependentResourceConfig config ) {
52
- configureWith ( config . labelSelector (), config . namespaces (), ! config . wereNamespacesConfigured ()) ;
54
+ this . kubernetesDependentResourceConfig = config ;
53
55
}
54
56
55
57
@ SuppressWarnings ("unchecked" )
56
58
private void configureWith (String labelSelector , Set <String > namespaces ,
57
- boolean inheritNamespacesOnChange ) {
59
+ boolean inheritNamespacesOnChange , EventSourceContext <P > context ) {
60
+
61
+ if (namespaces .equals (Constants .SAME_AS_CONTROLLER_NAMESPACES_SET )) {
62
+ namespaces = context .getControllerConfiguration ().getNamespaces ();
63
+ }
64
+
58
65
final SecondaryToPrimaryMapper <R > primaryResourcesRetriever =
59
66
(this instanceof SecondaryToPrimaryMapper ) ? (SecondaryToPrimaryMapper <R >) this
60
67
: Mappers .fromOwnerReference ();
@@ -136,9 +143,18 @@ protected NonNamespaceOperation<R, KubernetesResourceList<R>, Resource<R>> prepa
136
143
137
144
@ Override
138
145
protected InformerEventSource <R , P > createEventSource (EventSourceContext <P > context ) {
139
- configureWith (null , context .getControllerConfiguration ().getNamespaces (), true );
140
- log .warn ("Using default configuration for " + resourceType ().getSimpleName ()
141
- + " KubernetesDependentResource, call configureWith to provide configuration" );
146
+ if (kubernetesDependentResourceConfig != null ) {
147
+ configureWith (kubernetesDependentResourceConfig .labelSelector (),
148
+ kubernetesDependentResourceConfig .namespaces (),
149
+ !kubernetesDependentResourceConfig .wereNamespacesConfigured (), context );
150
+ } else {
151
+ configureWith (null , context .getControllerConfiguration ().getNamespaces (),
152
+ true , context );
153
+ log .warn (
154
+ "Using default configuration for "
155
+ + resourceType ().getSimpleName ()
156
+ + " KubernetesDependentResource, call configureWith to provide configuration" );
157
+ }
142
158
return eventSource ();
143
159
}
144
160
0 commit comments