tillrohrmann commented on a change in pull request #15052:
URL: https://github.com/apache/flink/pull/15052#discussion_r585358719



##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesUtils.java
##########
@@ -83,6 +85,8 @@
 
     private static final Logger LOG = 
LoggerFactory.getLogger(KubernetesUtils.class);
 
+    private static final YAMLMapper yamlMapper = new YAMLMapper();

Review comment:
       Where does this dependency come from? I think it is pulled in from 
`io.fabric8:kubernetes-client`. If we need a dependency then we should add it 
as a dependency to `pom.xml` and not rely on transitive dependencies which 
might change when changing the direct dependency.

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesUtils.java
##########
@@ -490,6 +494,24 @@ public static String getServiceAccount(FlinkPod flinkPod) {
         return serviceAccount;
     }
 
+    /**
+     * Try to get the pretty print yaml for Kubernetes resource.
+     *
+     * @param kubernetesResource kubernetes resource
+     * @return the pretty print yaml, or the {@link 
KubernetesResource#toString()} if parse failed.
+     */
+    public static String tryToGetPrettyPrintYaml(KubernetesResource 
kubernetesResource) {
+        try {
+            return yamlMapper.writeValueAsString(kubernetesResource);
+        } catch (Exception ex) {
+            LOG.debug(
+                    "Failed to get the pretty print yaml, fallback to {}",
+                    kubernetesResource.toString(),

Review comment:
       ```suggestion
                       kubernetesResource,
   ```

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesUtils.java
##########
@@ -490,6 +494,24 @@ public static String getServiceAccount(FlinkPod flinkPod) {
         return serviceAccount;
     }
 
+    /**
+     * Try to get the pretty print yaml for Kubernetes resource.
+     *
+     * @param kubernetesResource kubernetes resource
+     * @return the pretty print yaml, or the {@link 
KubernetesResource#toString()} if parse failed.
+     */
+    public static String tryToGetPrettyPrintYaml(KubernetesResource 
kubernetesResource) {
+        try {
+            return yamlMapper.writeValueAsString(kubernetesResource);

Review comment:
       ```suggestion
               return yamlMapper
                   .writerWithDefaultPrettyPrinter()
                   .writeValueAsString(kubernetesResource);
   ```

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesUtils.java
##########
@@ -83,6 +85,8 @@
 
     private static final Logger LOG = 
LoggerFactory.getLogger(KubernetesUtils.class);
 
+    private static final YAMLMapper yamlMapper = new YAMLMapper();

Review comment:
       Maybe it is also better to rely on the shaded jackson dependency.




----------------------------------------------------------------
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.

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


Reply via email to