From 4558ef6a52fd06f8bd2784336db57858fecb018b Mon Sep 17 00:00:00 2001 From: Joao Morais Date: Wed, 5 Apr 2017 22:21:34 -0300 Subject: [PATCH] Fix intermittent misconfiguration of backend.secure and sticky --- core/pkg/ingress/controller/controller.go | 38 +++++++++++++---------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/core/pkg/ingress/controller/controller.go b/core/pkg/ingress/controller/controller.go index ba15591c00..4a1b8d5e3a 100644 --- a/core/pkg/ingress/controller/controller.go +++ b/core/pkg/ingress/controller/controller.go @@ -807,30 +807,36 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing path.Backend.ServiceName, path.Backend.ServicePort.String()) - if _, ok := upstreams[name]; ok { - continue + upstream, ok := upstreams[name] + isNewUpstream := !ok + + if isNewUpstream { + glog.V(3).Infof("creating upstream %v", name) + upstream = newUpstream(name) + upstreams[name] = upstream } - glog.V(3).Infof("creating upstream %v", name) - upstreams[name] = newUpstream(name) - if !upstreams[name].Secure { - upstreams[name].Secure = secUpstream + if !upstream.Secure { + upstream.Secure = secUpstream } - if upstreams[name].SessionAffinity.AffinityType == "" { - upstreams[name].SessionAffinity.AffinityType = affinity.AffinityType + + if upstream.SessionAffinity.AffinityType == "" { + upstream.SessionAffinity.AffinityType = affinity.AffinityType if affinity.AffinityType == "cookie" { - upstreams[name].SessionAffinity.CookieSessionAffinity.Name = affinity.CookieConfig.Name - upstreams[name].SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieConfig.Hash + upstream.SessionAffinity.CookieSessionAffinity.Name = affinity.CookieConfig.Name + upstream.SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieConfig.Hash } } - svcKey := fmt.Sprintf("%v/%v", ing.GetNamespace(), path.Backend.ServiceName) - endp, err := ic.serviceEndpoints(svcKey, path.Backend.ServicePort.String(), hz) - if err != nil { - glog.Warningf("error obtaining service endpoints: %v", err) - continue + if isNewUpstream { + svcKey := fmt.Sprintf("%v/%v", ing.GetNamespace(), path.Backend.ServiceName) + endp, err := ic.serviceEndpoints(svcKey, path.Backend.ServicePort.String(), hz) + if err != nil { + glog.Warningf("error obtaining service endpoints: %v", err) + continue + } + upstream.Endpoints = endp } - upstreams[name].Endpoints = endp } } }