Skip to content

Commit b6dc384

Browse files
committed
Bugfix: non-host canary ingress use default server name as host to merge
1 parent 0396b88 commit b6dc384

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

internal/ingress/controller/controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,11 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
13691369
}
13701370

13711371
for _, rule := range ing.Spec.Rules {
1372+
host := rule.Host
1373+
if host == "" {
1374+
host = defServerName
1375+
}
1376+
13721377
for _, path := range rule.HTTP.Paths {
13731378
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
13741379

@@ -1382,11 +1387,11 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
13821387
merged := false
13831388
altEqualsPri := false
13841389

1385-
server, ok := servers[rule.Host]
1390+
server, ok := servers[host]
13861391
if !ok {
13871392
klog.Errorf("cannot merge alternative backend %s into hostname %s that does not exist",
13881393
altUps.Name,
1389-
rule.Host)
1394+
host)
13901395

13911396
continue
13921397
}

internal/ingress/controller/controller_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,88 @@ func TestMergeAlternativeBackends(t *testing.T) {
694694
},
695695
},
696696
},
697+
"non-host canary ingress use default server name as host to merge": {
698+
&ingress.Ingress{
699+
Ingress: networking.Ingress{
700+
ObjectMeta: metav1.ObjectMeta{
701+
Namespace: "example",
702+
},
703+
Spec: networking.IngressSpec{
704+
Rules: []networking.IngressRule{
705+
{
706+
IngressRuleValue: networking.IngressRuleValue{
707+
HTTP: &networking.HTTPIngressRuleValue{
708+
Paths: []networking.HTTPIngressPath{
709+
{
710+
Path: "/",
711+
PathType: &pathTypePrefix,
712+
Backend: networking.IngressBackend{
713+
ServiceName: "http-svc-canary",
714+
ServicePort: intstr.IntOrString{
715+
IntVal: 80,
716+
},
717+
},
718+
},
719+
},
720+
},
721+
},
722+
},
723+
},
724+
},
725+
},
726+
},
727+
map[string]*ingress.Backend{
728+
"example-http-svc-80": {
729+
Name: "example-http-svc-80",
730+
NoServer: false,
731+
},
732+
"example-http-svc-canary-80": {
733+
Name: "example-http-svc-canary-80",
734+
NoServer: true,
735+
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
736+
Weight: 20,
737+
},
738+
},
739+
},
740+
map[string]*ingress.Server{
741+
"_": {
742+
Hostname: "_",
743+
Locations: []*ingress.Location{
744+
{
745+
Path: "/",
746+
PathType: &pathTypePrefix,
747+
Backend: "example-http-svc-80",
748+
},
749+
},
750+
},
751+
},
752+
map[string]*ingress.Backend{
753+
"example-http-svc-80": {
754+
Name: "example-http-svc-80",
755+
NoServer: false,
756+
AlternativeBackends: []string{"example-http-svc-canary-80"},
757+
},
758+
"example-http-svc-canary-80": {
759+
Name: "example-http-svc-canary-80",
760+
NoServer: true,
761+
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
762+
Weight: 20,
763+
},
764+
},
765+
},
766+
map[string]*ingress.Server{
767+
"_": {
768+
Hostname: "_",
769+
Locations: []*ingress.Location{
770+
{
771+
Path: "/",
772+
PathType: &pathTypePrefix,
773+
Backend: "example-http-svc-80",
774+
},
775+
},
776+
},
777+
},
778+
},
697779
}
698780

699781
for title, tc := range testCases {

0 commit comments

Comments
 (0)