dmvk commented on a change in pull request #15501: URL: https://github.com/apache/flink/pull/15501#discussion_r668590709
########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/resources/KubernetesSharedInformer.java ########## @@ -0,0 +1,288 @@ +/* + * 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.FlinkKubeClient.WatchCallbackHandler; +import org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher; +import org.apache.flink.runtime.util.ExecutorThreadFactory; +import org.apache.flink.util.CollectionUtil; +import org.apache.flink.util.ExecutorUtils; +import org.apache.flink.util.Preconditions; + +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.KubernetesResourceList; +import io.fabric8.kubernetes.client.NamespacedKubernetesClient; +import io.fabric8.kubernetes.client.informers.ResourceEventHandler; +import io.fabric8.kubernetes.client.informers.SharedIndexInformer; +import io.fabric8.kubernetes.client.informers.SharedInformerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.concurrent.GuardedBy; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Function; + +/** Base class for shared watcher based on {@link SharedIndexInformer}. */ +public abstract class KubernetesSharedInformer< + T extends HasMetadata, TList extends KubernetesResourceList<T>, R> + implements KubernetesSharedWatcher<R> { + + protected final Logger log = LoggerFactory.getLogger(getClass()); + + private final NamespacedKubernetesClient client; + private final SharedInformerFactory sharedInformerFactory; + private final SharedIndexInformer<T> sharedIndexInformer; + private final Function<T, R> eventWrapper; + + private final ExecutorService watchingExecutor; + + private final Object processorsLock = new Object(); + + @GuardedBy("processorsLock") + private final Map<String, Processor> watchingProcessors = new HashMap<>(); + + public KubernetesSharedInformer( + NamespacedKubernetesClient client, + Class<T> apiTypeClass, + Class<TList> apiListTypeClass, + Map<String, String> labels, + Function<T, R> eventWrapper) { + Preconditions.checkArgument( + !CollectionUtil.isNullOrEmpty(labels), "Labels must not be null or empty"); + this.client = client; + this.sharedInformerFactory = + client.informers( + Executors.newSingleThreadExecutor( + new ExecutorThreadFactory("KubernetesClient-Informer"))); + this.sharedInformerFactory.withLabels(labels); + this.sharedIndexInformer = + sharedInformerFactory.sharedIndexInformerFor( + apiTypeClass, apiListTypeClass, Long.MAX_VALUE); Review comment: fyi @zentol is looking into upgrading fabric8 client, so we may be able to get rid of the workaround soon -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
