Detect path collisions in Ingress rules

This commit is contained in:
Manuel de Brito Fontes 2016-04-12 23:19:08 -03:00
parent 64791c35f0
commit 724a829eae

View file

@ -458,9 +458,9 @@ func (lbc *loadBalancerController) getUpstreamServers(data []interface{}) ([]*ng
} }
server := servers[rule.Host] server := servers[rule.Host]
locations := []*nginx.Location{}
for _, path := range rule.HTTP.Paths { for _, path := range rule.HTTP.Paths {
upsName := fmt.Sprintf("%v-%v-%v", ing.GetNamespace(), path.Backend.ServiceName, path.Backend.ServicePort.IntValue()) upsName := fmt.Sprintf("%v-%v-%v", ing.GetNamespace(), path.Backend.ServiceName, path.Backend.ServicePort.IntValue())
ups := upstreams[upsName] ups := upstreams[upsName]
@ -490,18 +490,23 @@ func (lbc *loadBalancerController) getUpstreamServers(data []interface{}) ([]*ng
} }
} }
for _, ups := range upstreams { // Validate that there is no another previuous rule
if upsName == ups.Name { // for the same host and path.
loc := &nginx.Location{Path: path.Path} skipLoc := false
loc.Upstream = *ups for _, loc := range server.Locations {
locations = append(locations, loc) if loc.Path == path.Path {
lbc.recorder.Eventf(ing, api.EventTypeWarning, "MAPPING", "Path '%v' already defined in another Ingress rule", path)
skipLoc = true
break break
} }
} }
}
for _, loc := range locations { if skipLoc == false {
server.Locations = append(server.Locations, loc) server.Locations = append(server.Locations, &nginx.Location{
Path: path.Path,
Upstream: *ups,
})
}
} }
} }
} }