Aitozi commented on a change in pull request #17554:
URL: https://github.com/apache/flink/pull/17554#discussion_r754923390



##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/KubernetesClusterDescriptor.java
##########
@@ -256,39 +247,50 @@ private String getWebMonitorAddress(Configuration 
configuration) throws Exceptio
                     flinkConfig.get(JobManagerOptions.PORT));
         }
 
+        final KubernetesJobManagerParameters kubernetesJobManagerParameters =
+                new KubernetesJobManagerParameters(flinkConfig, 
clusterSpecification);
+
+        final FlinkPod podTemplate =
+                kubernetesJobManagerParameters
+                        .getPodTemplateFilePath()
+                        .map(
+                                file ->
+                                        
KubernetesUtils.loadPodFromTemplateFile(
+                                                client, file, 
Constants.MAIN_CONTAINER_NAME))
+                        .orElse(new FlinkPod.Builder().build());
+        final KubernetesJobManagerSpecification kubernetesJobManagerSpec =
+                
KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(
+                        podTemplate, kubernetesJobManagerParameters);
+
+        client.createJobManagerComponent(kubernetesJobManagerSpec);
+
+        return createClusterClientProvider(clusterId);
+    }
+
+    private ClusterClientProvider<String> safelyDeployCluster(
+            SupplierWithException<ClusterClientProvider<String>, Exception> 
supplier)
+            throws ClusterDeploymentException {
         try {
-            final KubernetesJobManagerParameters 
kubernetesJobManagerParameters =
-                    new KubernetesJobManagerParameters(flinkConfig, 
clusterSpecification);
-
-            final FlinkPod podTemplate =
-                    kubernetesJobManagerParameters
-                            .getPodTemplateFilePath()
-                            .map(
-                                    file ->
-                                            
KubernetesUtils.loadPodFromTemplateFile(
-                                                    client, file, 
Constants.MAIN_CONTAINER_NAME))
-                            .orElse(new FlinkPod.Builder().build());
-            final KubernetesJobManagerSpecification kubernetesJobManagerSpec =
-                    
KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(
-                            podTemplate, kubernetesJobManagerParameters);
-
-            client.createJobManagerComponent(kubernetesJobManagerSpec);
-
-            return createClusterClientProvider(clusterId);
+
+            ClusterClientProvider<String> clusterClientProvider = 
supplier.get();
+
+            try (ClusterClient<String> clusterClient = 
clusterClientProvider.getClusterClient()) {
+                LOG.info(
+                        "Create flink cluster {} successfully, JobManager Web 
Interface: {}",
+                        clusterId,
+                        clusterClient.getWebInterfaceURL());
+            }
+            return clusterClientProvider;
         } catch (Exception e) {
             try {
-                LOG.warn(
-                        "Failed to create the Kubernetes cluster \"{}\", try 
to clean up the residual resources.",
-                        clusterId);
                 client.stopAndCleanupCluster(clusterId);
-            } catch (Exception e1) {
-                LOG.info(
+            } catch (Exception ex) {
+                LOG.warn(
                         "Failed to stop and clean up the Kubernetes cluster 
\"{}\".",
                         clusterId,
-                        e1);
+                        ex);
             }
-            throw new ClusterDeploymentException(

Review comment:
       fixed




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to