Bugfix: non-host canary ingress use default server name as host to merge
This commit is contained in:
parent
0396b888f6
commit
b6dc384afb
2 changed files with 89 additions and 2 deletions
|
@ -1369,6 +1369,11 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range ing.Spec.Rules {
|
for _, rule := range ing.Spec.Rules {
|
||||||
|
host := rule.Host
|
||||||
|
if host == "" {
|
||||||
|
host = defServerName
|
||||||
|
}
|
||||||
|
|
||||||
for _, path := range rule.HTTP.Paths {
|
for _, path := range rule.HTTP.Paths {
|
||||||
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
|
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
|
||||||
|
|
||||||
|
@ -1382,11 +1387,11 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
|
||||||
merged := false
|
merged := false
|
||||||
altEqualsPri := false
|
altEqualsPri := false
|
||||||
|
|
||||||
server, ok := servers[rule.Host]
|
server, ok := servers[host]
|
||||||
if !ok {
|
if !ok {
|
||||||
klog.Errorf("cannot merge alternative backend %s into hostname %s that does not exist",
|
klog.Errorf("cannot merge alternative backend %s into hostname %s that does not exist",
|
||||||
altUps.Name,
|
altUps.Name,
|
||||||
rule.Host)
|
host)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -694,6 +694,88 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"non-host canary ingress use default server name as host to merge": {
|
||||||
|
&ingress.Ingress{
|
||||||
|
Ingress: networking.Ingress{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "example",
|
||||||
|
},
|
||||||
|
Spec: networking.IngressSpec{
|
||||||
|
Rules: []networking.IngressRule{
|
||||||
|
{
|
||||||
|
IngressRuleValue: networking.IngressRuleValue{
|
||||||
|
HTTP: &networking.HTTPIngressRuleValue{
|
||||||
|
Paths: []networking.HTTPIngressPath{
|
||||||
|
{
|
||||||
|
Path: "/",
|
||||||
|
PathType: &pathTypePrefix,
|
||||||
|
Backend: networking.IngressBackend{
|
||||||
|
ServiceName: "http-svc-canary",
|
||||||
|
ServicePort: intstr.IntOrString{
|
||||||
|
IntVal: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]*ingress.Backend{
|
||||||
|
"example-http-svc-80": {
|
||||||
|
Name: "example-http-svc-80",
|
||||||
|
NoServer: false,
|
||||||
|
},
|
||||||
|
"example-http-svc-canary-80": {
|
||||||
|
Name: "example-http-svc-canary-80",
|
||||||
|
NoServer: true,
|
||||||
|
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
|
||||||
|
Weight: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]*ingress.Server{
|
||||||
|
"_": {
|
||||||
|
Hostname: "_",
|
||||||
|
Locations: []*ingress.Location{
|
||||||
|
{
|
||||||
|
Path: "/",
|
||||||
|
PathType: &pathTypePrefix,
|
||||||
|
Backend: "example-http-svc-80",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]*ingress.Backend{
|
||||||
|
"example-http-svc-80": {
|
||||||
|
Name: "example-http-svc-80",
|
||||||
|
NoServer: false,
|
||||||
|
AlternativeBackends: []string{"example-http-svc-canary-80"},
|
||||||
|
},
|
||||||
|
"example-http-svc-canary-80": {
|
||||||
|
Name: "example-http-svc-canary-80",
|
||||||
|
NoServer: true,
|
||||||
|
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
|
||||||
|
Weight: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]*ingress.Server{
|
||||||
|
"_": {
|
||||||
|
Hostname: "_",
|
||||||
|
Locations: []*ingress.Location{
|
||||||
|
{
|
||||||
|
Path: "/",
|
||||||
|
PathType: &pathTypePrefix,
|
||||||
|
Backend: "example-http-svc-80",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for title, tc := range testCases {
|
for title, tc := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue