Merge pull request #867 from GLYASAI/V5.2

bug fix: not  ready ep in /etc/hosts
This commit is contained in:
黄润豪 2020-11-03 14:37:33 +08:00 committed by GitHub
commit 7e2550c278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
},
}