morhidi commented on code in PR #239:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/239#discussion_r880370389


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/controller/FlinkDeploymentController.java:
##########
@@ -152,26 +160,71 @@ private void handleDeploymentFailed(FlinkDeployment 
flinkApp, DeploymentFailedEx
     }
 
     @Override
-    public List<EventSource> 
prepareEventSources(EventSourceContext<FlinkDeployment> ctx) {
-        if (effectiveNamespaces.isEmpty()) {
-            return 
List.of(OperatorUtils.createJmDepInformerEventSource(kubernetesClient));
-        } else {
-            return effectiveNamespaces.stream()
-                    .map(ns -> 
OperatorUtils.createJmDepInformerEventSource(kubernetesClient, ns))
-                    .collect(Collectors.toList());
-        }
+    public Map<String, EventSource> prepareEventSources(
+            EventSourceContext<FlinkDeployment> context) {
+
+        return EventSourceInitializer.nameEventSources(
+                getSessionJobInformerEventSource(context),
+                getFlinkDeploymentInformerEventSource(context));
+    }
+
+    private InformerEventSource<Deployment, FlinkDeployment> 
getFlinkDeploymentInformerEventSource(
+            EventSourceContext<FlinkDeployment> context) {
+        final String labelSelector =
+                Map.of(
+                                Constants.LABEL_TYPE_KEY,
+                                Constants.LABEL_TYPE_NATIVE_TYPE,
+                                Constants.LABEL_COMPONENT_KEY,
+                                Constants.LABEL_COMPONENT_JOB_MANAGER)
+                        .entrySet().stream()
+                        .map(Object::toString)
+                        .collect(Collectors.joining(","));
+
+        var configuration =
+                InformerConfiguration.from(Deployment.class, context)
+                        .withLabelSelector(labelSelector)
+                        
.withSecondaryToPrimaryMapper(Mappers.fromLabel(Constants.LABEL_APP_KEY))
+                        .withNamespacesInheritedFromController(context)
+                        .followNamespaceChanges(true)
+                        .build();
+
+        return new InformerEventSource<>(configuration, context);
     }
 
-    @VisibleForTesting
-    public void setEffectiveNamespaces(Set<String> effectiveNamespaces) {
-        this.effectiveNamespaces = effectiveNamespaces;
+    private InformerEventSource<FlinkSessionJob, FlinkDeployment> 
getSessionJobInformerEventSource(
+            EventSourceContext<FlinkDeployment> context) {
+
+        final SecondaryToPrimaryMapper<FlinkSessionJob> 
secondaryToPrimaryMapper =
+                sessionJob ->
+                        context.getPrimaryCache()

Review Comment:
   thx!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to