From d82544fe8055da234e7ed681a7e8a5ca068cf6ec Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 16 Mar 2017 08:20:52 -0300 Subject: [PATCH] Avoid upstreams with multiple servers with the same port --- core/pkg/ingress/controller/controller.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/pkg/ingress/controller/controller.go b/core/pkg/ingress/controller/controller.go index bbb96df36..96c5800c5 100644 --- a/core/pkg/ingress/controller/controller.go +++ b/core/pkg/ingress/controller/controller.go @@ -991,6 +991,11 @@ func (ic *GenericController) getEndpoints( upsServers := []ingress.Endpoint{} + // avoid duplicated upstream servers when the service + // contains multiple port definitions sharing the same + // targetport. + adus := make(map[string]bool, 0) + for _, ss := range ep.Subsets { for _, epPort := range ss.Ports { @@ -1031,6 +1036,10 @@ func (ic *GenericController) getEndpoints( } for _, epAddress := range ss.Addresses { + ep := fmt.Sprintf("%v:%v", epAddress.IP, targetPort) + if _, exists := adus[ep]; exists { + continue + } ups := ingress.Endpoint{ Address: epAddress.IP, Port: fmt.Sprintf("%v", targetPort), @@ -1038,6 +1047,7 @@ func (ic *GenericController) getEndpoints( FailTimeout: hz.FailTimeout, } upsServers = append(upsServers, ups) + adus[ep] = true } } }