Fix a bug with Canary becoming main server
This commit is contained in:
parent
cc2b54472a
commit
af460f7e15
4 changed files with 449 additions and 28 deletions
|
|
@ -192,4 +192,54 @@ var _ = framework.IngressNginxDescribe("Annotations - canary", func() {
|
|||
Expect(body).ShouldNot(ContainSubstring("http-svc-canary"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Single canary Ingress", func() {
|
||||
It("should not use canary as a catch-all server", func() {
|
||||
host := "foo"
|
||||
canaryIngName := fmt.Sprintf("%v-canary", host)
|
||||
annotations := map[string]string{
|
||||
"nginx.ingress.kubernetes.io/canary": "true",
|
||||
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
|
||||
}
|
||||
|
||||
ing := framework.NewSingleCatchAllIngress(canaryIngName, f.IngressController.Namespace, "http-svc-canary", 80, &annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
ing = framework.NewSingleCatchAllIngress(host, f.IngressController.Namespace, "http-svc", 80, nil)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer("_",
|
||||
func(server string) bool {
|
||||
upstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.IngressController.Namespace, "http-svc", "80")
|
||||
canaryUpstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.IngressController.Namespace, "http-svc-canary", "80")
|
||||
return Expect(server).Should(ContainSubstring(`set $ingress_name "`+host+`";`)) &&
|
||||
Expect(server).ShouldNot(ContainSubstring(`set $proxy_upstream_name "upstream-default-backend";`)) &&
|
||||
Expect(server).ShouldNot(ContainSubstring(canaryUpstreamName)) &&
|
||||
Expect(server).Should(ContainSubstring(upstreamName))
|
||||
})
|
||||
})
|
||||
|
||||
It("should not use canary with domain as a server", func() {
|
||||
host := "foo"
|
||||
canaryIngName := fmt.Sprintf("%v-canary", host)
|
||||
annotations := map[string]string{
|
||||
"nginx.ingress.kubernetes.io/canary": "true",
|
||||
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
|
||||
}
|
||||
|
||||
ing := framework.NewSingleIngress(canaryIngName, "/", host, f.IngressController.Namespace, "http-svc-canary", 80, &annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
otherHost := "bar"
|
||||
ing = framework.NewSingleIngress(otherHost, "/", otherHost, f.IngressController.Namespace, "http-svc", 80, nil)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
time.Sleep(waitForLuaSync)
|
||||
|
||||
f.WaitForNginxConfiguration(func(cfg string) bool {
|
||||
return Expect(cfg).Should(ContainSubstring("server_name "+otherHost)) &&
|
||||
Expect(cfg).ShouldNot(ContainSubstring("server_name "+host))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -354,38 +354,28 @@ func UpdateDeployment(kubeClientSet kubernetes.Interface, namespace string, name
|
|||
|
||||
// NewSingleIngressWithTLS creates a simple ingress rule with TLS spec included
|
||||
func NewSingleIngressWithTLS(name, path, host, ns, service string, port int, annotations *map[string]string) *extensions.Ingress {
|
||||
return newSingleIngress(name, path, host, ns, service, port, annotations, true)
|
||||
return newSingleIngressWithRules(name, path, host, ns, service, port, annotations, true)
|
||||
}
|
||||
|
||||
// NewSingleIngress creates a simple ingress rule
|
||||
func NewSingleIngress(name, path, host, ns, service string, port int, annotations *map[string]string) *extensions.Ingress {
|
||||
return newSingleIngress(name, path, host, ns, service, port, annotations, false)
|
||||
return newSingleIngressWithRules(name, path, host, ns, service, port, annotations, false)
|
||||
}
|
||||
|
||||
func newSingleIngress(name, path, host, ns, service string, port int, annotations *map[string]string, withTLS bool) *extensions.Ingress {
|
||||
if annotations == nil {
|
||||
annotations = &map[string]string{}
|
||||
}
|
||||
func newSingleIngressWithRules(name, path, host, ns, service string, port int, annotations *map[string]string, withTLS bool) *extensions.Ingress {
|
||||
|
||||
ing := &extensions.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: ns,
|
||||
Annotations: *annotations,
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
{
|
||||
Host: host,
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
{
|
||||
Path: path,
|
||||
Backend: extensions.IngressBackend{
|
||||
ServiceName: service,
|
||||
ServicePort: intstr.FromInt(port),
|
||||
},
|
||||
spec := extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
{
|
||||
Host: host,
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
{
|
||||
Path: path,
|
||||
Backend: extensions.IngressBackend{
|
||||
ServiceName: service,
|
||||
ServicePort: intstr.FromInt(port),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -396,7 +386,7 @@ func newSingleIngress(name, path, host, ns, service string, port int, annotation
|
|||
}
|
||||
|
||||
if withTLS {
|
||||
ing.Spec.TLS = []extensions.IngressTLS{
|
||||
spec.TLS = []extensions.IngressTLS{
|
||||
{
|
||||
Hosts: []string{host},
|
||||
SecretName: host,
|
||||
|
|
@ -404,5 +394,33 @@ func newSingleIngress(name, path, host, ns, service string, port int, annotation
|
|||
}
|
||||
}
|
||||
|
||||
return newSingleIngress(name, ns, annotations, spec)
|
||||
}
|
||||
|
||||
// NewSingleCatchAllIngress creates a simple ingress with a catch-all backend
|
||||
func NewSingleCatchAllIngress(name, ns, service string, port int, annotations *map[string]string) *extensions.Ingress {
|
||||
spec := extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
ServiceName: service,
|
||||
ServicePort: intstr.FromInt(port),
|
||||
},
|
||||
}
|
||||
return newSingleIngress(name, ns, annotations, spec)
|
||||
}
|
||||
|
||||
func newSingleIngress(name, ns string, annotations *map[string]string, spec extensions.IngressSpec) *extensions.Ingress {
|
||||
if annotations == nil {
|
||||
annotations = &map[string]string{}
|
||||
}
|
||||
|
||||
ing := &extensions.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: ns,
|
||||
Annotations: *annotations,
|
||||
},
|
||||
Spec: spec,
|
||||
}
|
||||
|
||||
return ing
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue