From 480297693f2d6520042a20bd221019fb6f9bc87a Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Mon, 2 Nov 2020 19:48:48 +0800 Subject: [PATCH] bug fix: not ready ep in /etc/hosts --- discover.v2/k8s_discover.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/discover.v2/k8s_discover.go b/discover.v2/k8s_discover.go index ee4738fe5..2ffc34aa2 100644 --- a/discover.v2/k8s_discover.go +++ b/discover.v2/k8s_discover.go @@ -3,6 +3,7 @@ package discover import ( "context" "errors" + "reflect" "sync" "time" @@ -90,18 +91,24 @@ func (k *k8sDiscover) discover(name string, callback CallbackUpdate) { DeleteFunc: func(obj interface{}) { pod := obj.(*corev1.Pod) ep := endpointForPod(pod) + ep.Mode = 2 callback.UpdateEndpoints(config.DELETE, ep) }, UpdateFunc: func(old, cur interface{}) { oldPod := old.(*corev1.Pod) curPod := cur.(*corev1.Pod) - if oldPod.Status.Phase == curPod.Status.Phase { - return - } - if !isPodReady(curPod) { + + if reflect.DeepEqual(oldPod, curPod) { return } + ep := endpointForPod(curPod) + if !isPodReady(curPod) { + logrus.Infof("unready pod(%s%s) received, delete endpoint based on the pod", curPod.Name, curPod.Namespace) + ep.Mode = 2 + callback.UpdateEndpoints(config.DELETE, ep) + return + } callback.UpdateEndpoints(config.SYNC, ep) }, }