Skip to content

Commit

Permalink
Merge pull request kubernetes#6740 from nic-6443/bug-fix
Browse files Browse the repository at this point in the history
Bugfix: non-host canary ingress use default server name as host to merge
  • Loading branch information
k8s-ci-robot authored May 17, 2021
2 parents 0396b88 + b6dc384 commit 1b1f7d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,11 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
}

for _, rule := range ing.Spec.Rules {
host := rule.Host
if host == "" {
host = defServerName
}

for _, path := range rule.HTTP.Paths {
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)

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

server, ok := servers[rule.Host]
server, ok := servers[host]
if !ok {
klog.Errorf("cannot merge alternative backend %s into hostname %s that does not exist",
altUps.Name,
rule.Host)
host)

continue
}
Expand Down
82 changes: 82 additions & 0 deletions internal/ingress/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1b1f7d3

Please sign in to comment.