Merge pull request #864 from GLYASAI/no-ready-endpoints

Bug Fix: bad argument #1 to 'pairs' (table expected, got nil)
This commit is contained in:
黄润豪 2020-10-22 11:36:01 +08:00 committed by GitHub
commit 4457250bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -690,7 +690,6 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
// ingressIsValid checks if the specified ingress is valid
func (s *k8sStore) ingressIsValid(ing *extensions.Ingress) bool {
var endpointKey string
if ing.Spec.Backend != nil { // stream
endpointKey = fmt.Sprintf("%s/%s", ing.Namespace, ing.Spec.Backend.ServiceName)
@ -719,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 (ep.Addresses == nil || len(ep.Addresses) == 0) && (ep.NotReadyAddresses == nil || len(ep.NotReadyAddresses) == 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)