wangyang0918 commented on a change in pull request #13644: URL: https://github.com/apache/flink/pull/13644#discussion_r508997664
########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/resources/KubernetesLeaderElector.java ########## @@ -0,0 +1,80 @@ +/* + * 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.resources; + +import org.apache.flink.kubernetes.kubeclient.KubernetesLeaderElectionConfiguration; + +import io.fabric8.kubernetes.client.NamespacedKubernetesClient; +import io.fabric8.kubernetes.client.extended.leaderelection.LeaderCallbacks; +import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectionConfigBuilder; +import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElector; +import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.ConfigMapLock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.UUID; + +/** + * Represent {@link KubernetesLeaderElector} in kubernetes. {@link LeaderElector#run()} is a blocking call. It should be + * run in the IO executor, not the main thread. The lifecycle is bound to single leader election. Once the leadership + * is revoked, as well as the {@link LeaderCallbackHandler#notLeader()} is called, the {@link LeaderElector#run()} will + * finish. To start another round of election, we need to trigger again. + */ +public class KubernetesLeaderElector extends LeaderElector<NamespacedKubernetesClient> { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesLeaderElector.class); + protected static final String LOCK_IDENTITY = UUID.randomUUID().toString(); Review comment: IIUC, each Flink cluster will have separate cluster-id. So they will have different ConfigMap name just like following. * k8s-ha-app1-restserver-leader * k8s-ha-app2-restserver-leader For multiple JobManagers in a Flink cluster(session mode), each JobManager will have a separate ConfigMap binding to the job id. * k8s-ha-app1-00000000000000000000000000000000-jobmanager-leader * k8s-ha-app1-00000000000000000000000000000002-jobmanager-leader Both the situation, I think one `LOCK_IDENTITY` could work. But follow xintong's suggestion, I will make it could be specified via `KubernetesLeaderElectionConfiguration`. ---------------------------------------------------------------- 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