wangyang0918 commented on a change in pull request #9965: 
[FLINK-10935][kubernetes]Implement KubeClient with Faric8 Kubernetes clients
URL: https://github.com/apache/flink/pull/9965#discussion_r352503712
 
 

 ##########
 File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java
 ##########
 @@ -0,0 +1,334 @@
+/*
+ * 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;
+
+import org.apache.flink.client.deployment.ClusterSpecification;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.kubernetes.kubeclient.decorators.ConfigMapDecorator;
+import org.apache.flink.kubernetes.kubeclient.decorators.Decorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.FlinkMasterDeploymentDecorator;
+import org.apache.flink.kubernetes.kubeclient.decorators.InitializerDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.OwnerReferenceDecorator;
+import org.apache.flink.kubernetes.kubeclient.decorators.ServiceDecorator;
+import 
org.apache.flink.kubernetes.kubeclient.decorators.TaskManagerPodDecorator;
+import org.apache.flink.kubernetes.kubeclient.resources.ActionWatcher;
+import org.apache.flink.kubernetes.kubeclient.resources.FlinkConfigMap;
+import org.apache.flink.kubernetes.kubeclient.resources.FlinkDeployment;
+import org.apache.flink.kubernetes.kubeclient.resources.FlinkPod;
+import org.apache.flink.kubernetes.kubeclient.resources.FlinkService;
+import org.apache.flink.kubernetes.utils.Constants;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServicePort;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
+import io.fabric8.kubernetes.client.Watcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+/**
+ * The implementation of {@link FlinkKubeClient}.
+ */
+public class Fabric8FlinkKubeClient implements FlinkKubeClient {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(Fabric8FlinkKubeClient.class);
+
+       private final Configuration flinkConfig;
+
+       private final KubernetesClient internalClient;
+
+       private final List<Decorator<ConfigMap, FlinkConfigMap>> 
configMapDecorators;
+
+       private final List<Decorator<Service, FlinkService>> 
internalServiceDecorators;
+       private final List<Decorator<Service, FlinkService>> 
restServiceDecorators;
+
+       private final List<Decorator<Deployment, FlinkDeployment>> 
flinkMasterDeploymentDecorators;
+
+       private final List<Decorator<Pod, FlinkPod>> taskManagerPodDecorators;
+
+       @Nonnull
+       private final String clusterId;
+
+       @Nonnull
+       private final String nameSpace;
+
+       public Fabric8FlinkKubeClient(Configuration flinkConfig, 
KubernetesClient client) {
+               this.internalClient = client;
+               this.flinkConfig = flinkConfig;
+               this.configMapDecorators = new ArrayList<>();
+               this.internalServiceDecorators = new ArrayList<>();
+               this.restServiceDecorators = new ArrayList<>();
+               this.flinkMasterDeploymentDecorators = new ArrayList<>();
+               this.taskManagerPodDecorators = new ArrayList<>();
+
+               this.clusterId = 
flinkConfig.getString(KubernetesConfigOptions.CLUSTER_ID);
+               this.nameSpace = 
flinkConfig.getString(KubernetesConfigOptions.NAMESPACE);
+
+               initialize();
+       }
+
+       private void initialize() {
+               this.configMapDecorators.add(new 
InitializerDecorator<>(Constants.CONFIG_MAP_PREFIX + clusterId));
+               this.configMapDecorators.add(new OwnerReferenceDecorator<>());
+               this.configMapDecorators.add(new ConfigMapDecorator());
+
+               this.internalServiceDecorators.add(new 
InitializerDecorator<>(clusterId));
+               this.internalServiceDecorators.add(new ServiceDecorator(
+                       KubernetesConfigOptions.ServiceExposedType.ClusterIP, 
false));
+
+               this.restServiceDecorators.add(new 
InitializerDecorator<>(clusterId + Constants.FLINK_REST_SERVICE_SUFFIX));
+               String exposedType = 
flinkConfig.getString(KubernetesConfigOptions.REST_SERVICE_EXPOSED_TYPE);
+               this.restServiceDecorators.add(new ServiceDecorator(
+                       
KubernetesConfigOptions.ServiceExposedType.valueOf(exposedType), true));
+               this.restServiceDecorators.add(new OwnerReferenceDecorator<>());
+
+               this.flinkMasterDeploymentDecorators.add(new 
InitializerDecorator<>(clusterId, Constants.APPS_API_VERSION));
+               this.flinkMasterDeploymentDecorators.add(new 
OwnerReferenceDecorator<>(Constants.APPS_API_VERSION));
+
+               this.taskManagerPodDecorators.add(new InitializerDecorator<>());
 
 Review comment:
   The name of taskmanager pod is generated by `KubernetesResourceManager`. It 
will be decorated in the `createTaskManagerPod`.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to