Skip to content

Commit 6931835

Browse files
authored
Fix defaultServer backend update for Ingress with defaultBackend. (#8825)
1 parent d5893d4 commit 6931835

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

internal/ingress/controller/controller.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,17 +1208,15 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
12081208
// use backend specified in Ingress as the default backend for all its rules
12091209
un = backendUpstream.Name
12101210

1211-
// special "catch all" case, Ingress with a backend but no rule
12121211
defLoc := servers[defServerName].Locations[0]
1213-
defLoc.Backend = backendUpstream.Name
1214-
defLoc.Service = backendUpstream.Service
1215-
defLoc.Ingress = ing
1216-
12171212
if defLoc.IsDefBackend && len(ing.Spec.Rules) == 0 {
12181213
klog.V(2).Infof("Ingress %q defines a backend but no rule. Using it to configure the catch-all server %q", ingKey, defServerName)
12191214

12201215
defLoc.IsDefBackend = false
1221-
1216+
// special "catch all" case, Ingress with a backend but no rule
1217+
defLoc.Backend = backendUpstream.Name
1218+
defLoc.Service = backendUpstream.Service
1219+
defLoc.Ingress = ing
12221220
// TODO: Redirect and rewrite can affect the catch all behavior, skip for now
12231221
originalRedirect := defLoc.Redirect
12241222
originalRewrite := defLoc.Rewrite

test/e2e/ingress/without_host.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,13 @@ var _ = framework.IngressNginxDescribe("[Ingress] definition without host", func
9393
WithHeader("Host", "only-backend").
9494
Expect().
9595
Status(http.StatusOK)
96+
// Following assertion added with respect to issue https://github.com/kubernetes/ingress-nginx/issues/8823
97+
// This check ensure that ingress having defaultBackend with rules should only be added as default backend
98+
// for the host mentioned in rule. It should not affect the default catch-all server_name _ block.
99+
f.HTTPTestClient().
100+
GET("/").
101+
WithHeader("Host", "only-backend-doesnotexist").
102+
Expect().
103+
Status(http.StatusNotFound)
96104
})
97105
})

0 commit comments

Comments
 (0)