Skip to content

Commit

Permalink
Fix nginx sticky sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Jun 26, 2017
1 parent fb32e47 commit 67e0e0b
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
for _, ingIf := range ings {
ing := ingIf.(*extensions.Ingress)

affinity := ic.annotations.SessionAffinity(ing)

if !class.IsValid(ing, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass) {
continue
}
Expand Down Expand Up @@ -672,6 +674,22 @@ func (ic *GenericController) getBackendServers() ([]*ingress.Backend, []*ingress
mergeLocationAnnotations(loc, anns)
server.Locations = append(server.Locations, loc)
}

if ups.SessionAffinity.AffinityType == "" {
ups.SessionAffinity.AffinityType = affinity.AffinityType
}

if affinity.AffinityType == "cookie" {
ups.SessionAffinity.CookieSessionAffinity.Name = affinity.CookieConfig.Name
ups.SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieConfig.Hash

locs := ups.SessionAffinity.CookieSessionAffinity.Locations
if _, ok := locs[host]; !ok {
locs[host] = []string{}
}

locs[host] = append(locs[host], path.Path)
}
}
}
}
Expand Down Expand Up @@ -758,7 +776,6 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing

secUpstream := ic.annotations.SecureUpstream(ing)
hz := ic.annotations.HealthCheck(ing)
affinity := ic.annotations.SessionAffinity(ing)

var defBackend string
if ing.Spec.Backend != nil {
Expand Down Expand Up @@ -803,19 +820,6 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing
upstreams[name].SecureCACert = secUpstream.CACert
}

if upstreams[name].SessionAffinity.AffinityType == "" {
upstreams[name].SessionAffinity.AffinityType = affinity.AffinityType
if affinity.AffinityType == "cookie" {
upstreams[name].SessionAffinity.CookieSessionAffinity.Name = affinity.CookieConfig.Name
upstreams[name].SessionAffinity.CookieSessionAffinity.Hash = affinity.CookieConfig.Hash

if _, ok := upstreams[name].SessionAffinity.CookieSessionAffinity.Locations[rule.Host]; !ok {
upstreams[name].SessionAffinity.CookieSessionAffinity.Locations[rule.Host] = []string{}
}
upstreams[name].SessionAffinity.CookieSessionAffinity.Locations[rule.Host] = append(upstreams[name].SessionAffinity.CookieSessionAffinity.Locations[rule.Host], path.Path)
}
}

svcKey := fmt.Sprintf("%v/%v", ing.GetNamespace(), path.Backend.ServiceName)
endp, err := ic.serviceEndpoints(svcKey, path.Backend.ServicePort.String(), hz)
if err != nil {
Expand Down

0 comments on commit 67e0e0b

Please sign in to comment.