Fix custom default backend switch to default (#4611)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2019-09-27 10:21:28 -03:00 committed by GitHub
parent fd9acd412f
commit a9f332704a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -613,14 +613,22 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
for _, upstream := range upstreams {
aUpstreams = append(aUpstreams, upstream)
if upstream.Name == defUpstreamName {
continue
}
isHTTPSfrom := []*ingress.Server{}
for _, server := range servers {
for _, location := range server.Locations {
if shouldCreateUpstreamForLocationDefaultBackend(upstream, location) {
// use default backend
if !shouldCreateUpstreamForLocationDefaultBackend(upstream, location) {
continue
}
sp := location.DefaultBackend.Spec.Ports[0]
endps := getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
// custom backend is valid only if contains at least one endpoint
if len(endps) > 0 {
name := fmt.Sprintf("custom-default-backend-%v", location.DefaultBackend.GetName())
klog.V(3).Infof("Creating \"%v\" upstream based on default backend annotation", name)
@ -647,9 +655,6 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
isHTTPSfrom = append(isHTTPSfrom, server)
}
}
} else {
location.DefaultBackendUpstreamName = "upstream-default-backend"
}
}
}
@ -1180,6 +1185,8 @@ func locationApplyAnnotations(loc *ingress.Location, anns *annotations.Ingress)
loc.ModSecurity = anns.ModSecurity
loc.Satisfy = anns.Satisfy
loc.Mirror = anns.Mirror
loc.DefaultBackendUpstreamName = defUpstreamName
}
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into