zhengcanbin commented on a change in pull request #11010: [FLINK-15836][k8s] Throw fatal error in KubernetesResourceManager when the pods watcher is closed with exception URL: https://github.com/apache/flink/pull/11010#discussion_r410837172
########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/resources/KubernetesPodsWatcher.java ########## @@ -0,0 +1,79 @@ +/* + * 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; + +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collections; +import java.util.function.Consumer; + +/** + * Represent Watcher resource for Pods in kubernetes. + */ +public class KubernetesPodsWatcher implements Watcher<Pod> { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesPodsWatcher.class); + + private final FlinkKubeClient.PodCallbackHandler podsCallbackHandler; + private final Consumer<Exception> podsWatcherCloseHandler; + + public KubernetesPodsWatcher( + FlinkKubeClient.PodCallbackHandler callbackHandler, + Consumer<Exception> podsWatcherCloseHandler) { + this.podsCallbackHandler = callbackHandler; + this.podsWatcherCloseHandler = podsWatcherCloseHandler; + } + + @Override + public void eventReceived(Action action, Pod pod) { + LOG.debug("Received {} event for pod {}, details: {}", action, pod.getMetadata().getName(), pod.getStatus()); + switch (action) { + case ADDED: + podsCallbackHandler.onAdded(Collections.singletonList(new KubernetesPod(pod))); + break; + case MODIFIED: + podsCallbackHandler.onModified(Collections.singletonList(new KubernetesPod(pod))); + break; + case ERROR: + podsCallbackHandler.onError(Collections.singletonList(new KubernetesPod(pod))); + break; + case DELETED: + podsCallbackHandler.onDeleted(Collections.singletonList(new KubernetesPod(pod))); + break; + default: + LOG.debug("Ignore handling {} event for pod {}", action, pod.getMetadata().getName()); + break; + } + } + + @Override + public void onClose(KubernetesClientException cause) { + LOG.debug("The pods watcher is closing with exception {}.", cause == null ? "null" : cause); Review comment: If the `cause` equals to `null`, we'd better log in `INFO` level, otherwise, log a `WARNING` message instead. ---------------------------------------------------------------- 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
