zhengcanbin commented on a change in pull request #11233: [FLINK-16194][k8s] 
Refactor the Kubernetes decorator design
URL: https://github.com/apache/flink/pull/11233#discussion_r385996299
 
 

 ##########
 File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/factory/KubernetesJobManagerFactory.java
 ##########
 @@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.kubernetes.kubeclient.factory;
+
+import org.apache.flink.kubernetes.kubeclient.FlinkPod;
+import 
org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.InitJobManagerDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.InternalServiceDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.JavaCmdJobManagerDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters;
+import org.apache.flink.kubernetes.utils.Constants;
+import org.apache.flink.kubernetes.utils.KubernetesUtils;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.HasMetadata;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodBuilder;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utility class for constructing all the Kubernetes components on the 
client-side. This can
+ * include the Deployment, the ConfigMap(s), and the Service(s).
+ */
+public class KubernetesJobManagerFactory {
+
+       public static KubernetesJobManagerSpecification 
createJobManagerComponent(
+                       KubernetesJobManagerParameters 
kubernetesJobManagerParameters) throws IOException {
+               FlinkPod flinkPod = new FlinkPod.Builder().build();
+               List<HasMetadata> accompanyingResources = new ArrayList<>();
+
+               final KubernetesStepDecorator[] stepDecorators = new 
KubernetesStepDecorator[] {
+                       new 
InitJobManagerDecorator(kubernetesJobManagerParameters),
+                       new 
JavaCmdJobManagerDecorator(kubernetesJobManagerParameters),
+                       new 
InternalServiceDecorator(kubernetesJobManagerParameters),
+                       new 
ExternalServiceDecorator(kubernetesJobManagerParameters),
+                       new 
FlinkConfMountDecorator(kubernetesJobManagerParameters)};
+
+               for (KubernetesStepDecorator stepDecorator: stepDecorators) {
+                       flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
+                       
accompanyingResources.addAll(stepDecorator.buildAccompanyingKubernetesResources());
+               }
+
+               final Deployment deployment = 
createJobManagerDeployment(flinkPod, kubernetesJobManagerParameters);
+
+               KubernetesUtils.setOwnerReference(deployment, 
accompanyingResources);
+
+               return new KubernetesJobManagerSpecification(deployment, 
accompanyingResources);
+       }
+
+       private static Deployment createJobManagerDeployment(
+                       FlinkPod flinkPod,
+                       KubernetesJobManagerParameters 
kubernetesJobManagerParameters) {
+               final Container resolvedMainContainer = 
flinkPod.getMainContainer();
+
+               final Pod resolvedPod = new PodBuilder(flinkPod.getPod())
+                       .editOrNewSpec()
+                               .addToContainers(resolvedMainContainer)
+                               .endSpec()
+                       .build();
+
+               final Map<String, String> labels = 
resolvedPod.getMetadata().getLabels();
 
 Review comment:
   The basic logic is:
   1. We use the Pod object built by the decorators to fill the pod template of 
the deployment.
   2. Then set the deployment.metadata.labels separately to help others realize 
that the labels of the deployment could be different from the labels of the 
underlying pod.
   
   For the usual case, the labels could be the same. For this PR,  
resolvedPod.getMetadata().getLabels() and 
kubernetesJobManagerParameters.getLabels() shares the same values. 
   
   So I think it is reasonable to use the resolvedPod.getMetadata().getLabels 
to fill the spec of the deployment.
   
   For the deployment metadata, maybe we could introduce a private wrapper 
method in KubernetesJobManagerFactory to get the deployment labels.
   
   

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


With regards,
Apache Git Services

Reply via email to