Fix custom default backend switch to default (#4611)
This commit is contained in:
parent
fd9acd412f
commit
a9f332704a
1 changed files with 32 additions and 25 deletions
|
@ -613,14 +613,22 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
|
||||||
for _, upstream := range upstreams {
|
for _, upstream := range upstreams {
|
||||||
aUpstreams = append(aUpstreams, upstream)
|
aUpstreams = append(aUpstreams, upstream)
|
||||||
|
|
||||||
|
if upstream.Name == defUpstreamName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
isHTTPSfrom := []*ingress.Server{}
|
isHTTPSfrom := []*ingress.Server{}
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
for _, location := range server.Locations {
|
for _, location := range server.Locations {
|
||||||
if shouldCreateUpstreamForLocationDefaultBackend(upstream, location) {
|
// use default backend
|
||||||
|
if !shouldCreateUpstreamForLocationDefaultBackend(upstream, location) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
sp := location.DefaultBackend.Spec.Ports[0]
|
sp := location.DefaultBackend.Spec.Ports[0]
|
||||||
endps := getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
|
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 {
|
if len(endps) > 0 {
|
||||||
|
|
||||||
name := fmt.Sprintf("custom-default-backend-%v", location.DefaultBackend.GetName())
|
name := fmt.Sprintf("custom-default-backend-%v", location.DefaultBackend.GetName())
|
||||||
klog.V(3).Infof("Creating \"%v\" upstream based on default backend annotation", name)
|
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)
|
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.ModSecurity = anns.ModSecurity
|
||||||
loc.Satisfy = anns.Satisfy
|
loc.Satisfy = anns.Satisfy
|
||||||
loc.Mirror = anns.Mirror
|
loc.Mirror = anns.Mirror
|
||||||
|
|
||||||
|
loc.DefaultBackendUpstreamName = defUpstreamName
|
||||||
}
|
}
|
||||||
|
|
||||||
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into
|
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into
|
||||||
|
|
Loading…
Reference in a new issue