wangyang0918 commented on a change in pull request #10898: [FLINK-15632][kubernetes] Make zookeeper HA service could work for active kubernetes integration URL: https://github.com/apache/flink/pull/10898#discussion_r368290749
########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/entrypoint/KubernetesEntrypointUtils.java ########## @@ -0,0 +1,65 @@ +/* + * 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.entrypoint; + +import org.apache.flink.configuration.ConfigConstants; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.GlobalConfiguration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.RestOptions; +import org.apache.flink.kubernetes.utils.Constants; +import org.apache.flink.runtime.jobmanager.HighAvailabilityMode; +import org.apache.flink.util.Preconditions; + +/** + * This class contains utility methods for the {@link KubernetesSessionClusterEntrypoint}. + */ +class KubernetesEntrypointUtils { + + /** + * For non-HA cluster, jobmanager rpc address has be set to Kubernetes service name on client side. So the TaskManager + * will use service address to connect with jobmanager. + * For HA cluster, jobmanager rpc address will be set to ip address. The TaskManager use Zookeeper or other + * high-availability service to find the address of jobmanager. The Kubernetes DNS creates A and SRV records only for + * Services. It doesn't generate pods' A records. So the ip address, not hostname, will be used as jobmanager address. + * + * @return Updated configuration + */ + static Configuration loadConfiguration() { + final String configDir = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR); + Preconditions.checkNotNull( + configDir, + "Flink configuration directory (%s) in environment should not be null!", + ConfigConstants.ENV_FLINK_CONF_DIR); + + final Configuration configuration = GlobalConfiguration.loadConfiguration(configDir); + + if (HighAvailabilityMode.isHighAvailabilityModeActivated(configuration)) { + final String ipAddress = System.getenv().get(Constants.ENV_FLINK_POD_IP_ADDRESS); + Preconditions.checkState( + ipAddress != null, + "JobManager ip address environment variable %s not set", + Constants.ENV_FLINK_POD_IP_ADDRESS); + configuration.setString(JobManagerOptions.ADDRESS, ipAddress); Review comment: In non-HA mode, we need to set the jobmanager rpc address to service name. So when the jobmanager failover, the taskmanager could register again. In HA mode, the taskmanager uses zookeeper to retrieve the jobmanager address. And there will be multiple jobmanagers in the future. So we set the ip address instead of jobmanager rpc address. So i think we could not always set `JobManagerOptions.ADDRESS` to ip address. ---------------------------------------------------------------- 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