Skip to content

Commit

Permalink
Fix defaultServer backend update for Ingress with defaultBackend. (ku…
Browse files Browse the repository at this point in the history
  • Loading branch information
harry1064 authored Aug 22, 2022
1 parent d5893d4 commit 6931835
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 4 additions & 6 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,17 +1208,15 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
// use backend specified in Ingress as the default backend for all its rules
un = backendUpstream.Name

// special "catch all" case, Ingress with a backend but no rule
defLoc := servers[defServerName].Locations[0]
defLoc.Backend = backendUpstream.Name
defLoc.Service = backendUpstream.Service
defLoc.Ingress = ing

if defLoc.IsDefBackend && len(ing.Spec.Rules) == 0 {
klog.V(2).Infof("Ingress %q defines a backend but no rule. Using it to configure the catch-all server %q", ingKey, defServerName)

defLoc.IsDefBackend = false

// special "catch all" case, Ingress with a backend but no rule
defLoc.Backend = backendUpstream.Name
defLoc.Service = backendUpstream.Service
defLoc.Ingress = ing
// TODO: Redirect and rewrite can affect the catch all behavior, skip for now
originalRedirect := defLoc.Redirect
originalRewrite := defLoc.Rewrite
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/ingress/without_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,13 @@ var _ = framework.IngressNginxDescribe("[Ingress] definition without host", func
WithHeader("Host", "only-backend").
Expect().
Status(http.StatusOK)
// Following assertion added with respect to issue https://github.com/kubernetes/ingress-nginx/issues/8823
// This check ensure that ingress having defaultBackend with rules should only be added as default backend
// for the host mentioned in rule. It should not affect the default catch-all server_name _ block.
f.HTTPTestClient().
GET("/").
WithHeader("Host", "only-backend-doesnotexist").
Expect().
Status(http.StatusNotFound)
})
})

0 comments on commit 6931835

Please sign in to comment.