Simplify urlmap update logic.
This commit is contained in:
parent
3464d1c5e3
commit
5b2de6e40b
1 changed files with 23 additions and 41 deletions
|
@ -642,48 +642,29 @@ func (l *L7) UpdateUrlMap(ingressRules utils.GCEURLMap) error {
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("Updating url map %+v", ingressRules)
|
glog.V(3).Infof("Updating url map %+v", ingressRules)
|
||||||
|
|
||||||
for hostname, urlToBackend := range ingressRules {
|
// Every update replaces the entire urlmap.
|
||||||
// Find the hostrule
|
// TODO: when we have multiple loadbalancers point to a single gce url map
|
||||||
// Find the path matcher
|
// this needs modification. For now, there is a 1:1 mapping of urlmaps to
|
||||||
// Add all given endpoint:backends to pathRules in path matcher
|
// Ingresses, so if the given Ingress doesn't have a host rule we should
|
||||||
var hostRule *compute.HostRule
|
// delete the path to that backend.
|
||||||
pmName := getNameForPathMatcher(hostname)
|
l.um.HostRules = []*compute.HostRule{}
|
||||||
for _, hr := range l.um.HostRules {
|
l.um.PathMatchers = []*compute.PathMatcher{}
|
||||||
// TODO: Hostnames must be exact match?
|
|
||||||
if hr.Hosts[0] == hostname {
|
|
||||||
hostRule = hr
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if hostRule == nil {
|
|
||||||
// This is a new host
|
|
||||||
hostRule = &compute.HostRule{
|
|
||||||
Hosts: []string{hostname},
|
|
||||||
PathMatcher: pmName,
|
|
||||||
}
|
|
||||||
// Why not just clobber existing host rules?
|
|
||||||
// Because we can have multiple loadbalancers point to a single
|
|
||||||
// gce url map when we have IngressClaims.
|
|
||||||
l.um.HostRules = append(l.um.HostRules, hostRule)
|
|
||||||
}
|
|
||||||
var pathMatcher *compute.PathMatcher
|
|
||||||
for _, pm := range l.um.PathMatchers {
|
|
||||||
if pm.Name == hostRule.PathMatcher {
|
|
||||||
pathMatcher = pm
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pathMatcher == nil {
|
|
||||||
// This is a dangling or new host
|
|
||||||
pathMatcher = &compute.PathMatcher{Name: pmName}
|
|
||||||
l.um.PathMatchers = append(l.um.PathMatchers, pathMatcher)
|
|
||||||
}
|
|
||||||
pathMatcher.DefaultService = l.um.DefaultService
|
|
||||||
|
|
||||||
// TODO: Every update replaces the entire path map. This will need to
|
for hostname, urlToBackend := range ingressRules {
|
||||||
// change when we allow joining. Right now we call a single method
|
// Create a host rule
|
||||||
// to verify current == desired and add new url mappings.
|
// Create a path matcher
|
||||||
pathMatcher.PathRules = []*compute.PathRule{}
|
// Add all given endpoint:backends to pathRules in path matcher
|
||||||
|
pmName := getNameForPathMatcher(hostname)
|
||||||
|
l.um.HostRules = append(l.um.HostRules, &compute.HostRule{
|
||||||
|
Hosts: []string{hostname},
|
||||||
|
PathMatcher: pmName,
|
||||||
|
})
|
||||||
|
|
||||||
|
pathMatcher := &compute.PathMatcher{
|
||||||
|
Name: pmName,
|
||||||
|
DefaultService: l.um.DefaultService,
|
||||||
|
PathRules: []*compute.PathRule{},
|
||||||
|
}
|
||||||
|
|
||||||
// Longest prefix wins. For equal rules, first hit wins, i.e the second
|
// Longest prefix wins. For equal rules, first hit wins, i.e the second
|
||||||
// /foo rule when the first is deleted.
|
// /foo rule when the first is deleted.
|
||||||
|
@ -691,6 +672,7 @@ func (l *L7) UpdateUrlMap(ingressRules utils.GCEURLMap) error {
|
||||||
pathMatcher.PathRules = append(
|
pathMatcher.PathRules = append(
|
||||||
pathMatcher.PathRules, &compute.PathRule{Paths: []string{expr}, Service: be.SelfLink})
|
pathMatcher.PathRules, &compute.PathRule{Paths: []string{expr}, Service: be.SelfLink})
|
||||||
}
|
}
|
||||||
|
l.um.PathMatchers = append(l.um.PathMatchers, pathMatcher)
|
||||||
}
|
}
|
||||||
um, err := l.cloud.UpdateUrlMap(l.um)
|
um, err := l.cloud.UpdateUrlMap(l.um)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue