From 577bd9be901a7f07b5270871a49340bdc2f76e3e Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Thu, 22 Oct 2020 11:13:12 +0800 Subject: [PATCH] check ready addresses --- gateway/store/store.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gateway/store/store.go b/gateway/store/store.go index 8481a32d7..a9d6ebae6 100644 --- a/gateway/store/store.go +++ b/gateway/store/store.go @@ -718,20 +718,27 @@ func (s *k8sStore) ingressIsValid(ing *extensions.Ingress) bool { logrus.Errorf("Cant not convert %v to %v", reflect.TypeOf(item), reflect.TypeOf(endpoint)) return false } - if endpoint.Subsets == nil || len(endpoint.Subsets) == 0 { + if len(endpoint.Subsets) == 0 { logrus.Debugf("Endpoints(%s) is empty, ignore it", endpointKey) return false } - for _, ep := range endpoint.Subsets { - if len(ep.Addresses) == 0 { - logrus.Debugf("Endpoints(%s) is empty, ignore it", endpointKey) - return false - } + if !hasReadyAddresses(endpoint) { + logrus.Debugf("Endpoints(%s) is empty, ignore it", endpointKey) + return false } return true } +func hasReadyAddresses(endpoints *corev1.Endpoints) bool { + for _, ep := range endpoints.Subsets { + if len(ep.Addresses) > 0 { + return true + } + } + return false +} + // GetIngress returns the Ingress matching key. func (s *k8sStore) GetIngress(key string) (*extensions.Ingress, error) { return s.listers.Ingress.ByKey(key)