Always sort upstream list to provide stable iteration order

This commit is contained in:
Manuel de Brito Fontes 2018-06-02 15:17:14 -04:00 committed by Manuel Alejandro de Brito Fontes
parent 0b9eb96ec4
commit f3e9292c04
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
2 changed files with 4 additions and 15 deletions

View file

@ -572,12 +572,6 @@ func (n *NGINXController) getBackendServers(ingresses []*extensions.Ingress) ([]
aUpstreams = append(aUpstreams, upstream)
}
if n.cfg.SortBackends {
sort.SliceStable(aUpstreams, func(a, b int) bool {
return aUpstreams[a].Name < aUpstreams[b].Name
})
}
aServers := make([]*ingress.Server, 0, len(servers))
for _, value := range servers {
sort.SliceStable(value.Locations, func(i, j int) bool {
@ -586,6 +580,10 @@ func (n *NGINXController) getBackendServers(ingresses []*extensions.Ingress) ([]
aServers = append(aServers, value)
}
sort.SliceStable(aUpstreams, func(a, b int) bool {
return aUpstreams[a].Name < aUpstreams[b].Name
})
sort.SliceStable(aServers, func(i, j int) bool {
return aServers[i].Hostname < aServers[j].Hostname
})