csviri commented on code in PR #239: URL: https://github.com/apache/flink-kubernetes-operator/pull/239#discussion_r880249891
########## 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: see sample here: https://github.com/java-operator-sdk/java-operator-sdk/blob/220c79b6a5942929dc0af9a162e90c648e0f49d0/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java#L16-L16 -- 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