Improve text, error level, tests...

This commit is contained in:
Per Bernhardt 2019-03-12 13:52:52 +01:00
parent 8a40e82ffb
commit c995e13249
2 changed files with 33 additions and 31 deletions

View file

@ -1199,22 +1199,27 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
altUps := upstreams[upsName] altUps := upstreams[upsName]
merged := false if altUps == nil {
klog.Warningf("alternative backend %s has already been removed", upsName)
} else {
for _, loc := range servers[defServerName].Locations { merged := false
priUps := upstreams[loc.Backend]
if canMergeBackend(priUps, altUps) { for _, loc := range servers[defServerName].Locations {
klog.V(2).Infof("matching backend %v found for alternative backend %v", priUps := upstreams[loc.Backend]
priUps.Name, altUps.Name)
merged = mergeAlternativeBackend(priUps, altUps) if canMergeBackend(priUps, altUps) {
klog.V(2).Infof("matching backend %v found for alternative backend %v",
priUps.Name, altUps.Name)
merged = mergeAlternativeBackend(priUps, altUps)
}
} }
}
if !merged { if !merged {
klog.Warningf("unable to find real backend for alternative backend %v. Deleting.", altUps.Name) klog.Warningf("unable to find real backend for alternative backend %v. Deleting.", altUps.Name)
delete(upstreams, altUps.Name) delete(upstreams, altUps.Name)
}
} }
} }
@ -1225,7 +1230,7 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
altUps := upstreams[upsName] altUps := upstreams[upsName]
if altUps == nil { if altUps == nil {
klog.Errorf("alternative backend %s has already be removed", upsName) klog.Warningf("alternative backend %s has already been removed", upsName)
continue continue
} }

View file

@ -759,27 +759,24 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
}) })
}) })
Context("Single canary Ingress with multiple paths to same backend", func() { It("does not crash when canary ingress has multiple paths to the same non-matching backend", func() {
It("should work", func() { host := "foo"
host := "foo" canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIngName := fmt.Sprintf("%v-canary", host) annotations := map[string]string{
annotations := map[string]string{ "nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary": "true", "nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader", }
}
paths := []string{"/foo", "/bar"} paths := []string{"/foo", "/bar"}
ing := framework.NewSingleIngressWithMultiplePaths(canaryIngName, paths, host, f.Namespace, "httpy-svc-canary", 80, &annotations)
f.EnsureIngress(ing)
ing := framework.NewSingleIngressWithMultiplePaths(canaryIngName, paths, host, f.Namespace, "httpy-svc-canary", 80, &annotations) ing = framework.NewSingleIngress(host, "/", host, f.Namespace, "http-svc", 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
ing = framework.NewSingleIngress(host, "/", host, f.Namespace, "http-svc", 80, nil) f.WaitForNginxServer(host,
f.EnsureIngress(ing) func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
f.WaitForNginxServer(host, })
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
})
})
}) })
}) })