@@ -567,37 +567,40 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
567567
568568addLoc := true
569569for _ , loc := range server .Locations {
570- if loc .Path == nginxPath {
571- // Same paths but different types are allowed
572- // (same type means overlap in the path definition)
573- if ! apiequality .Semantic .DeepEqual (loc .PathType , path .PathType ) {
574- break
575- }
570+ if loc .Path != nginxPath {
571+ continue
572+ }
576573
577- addLoc = false
574+ // Same paths but different types are allowed
575+ // (same type means overlap in the path definition)
576+ if ! apiequality .Semantic .DeepEqual (loc .PathType , path .PathType ) {
577+ break
578+ }
578579
579- if ! loc .IsDefBackend {
580- klog .V (3 ).Infof ("Location %q already configured for server %q with upstream %q (Ingress %q)" ,
581- loc .Path , server .Hostname , loc .Backend , ingKey )
582- break
583- }
580+ addLoc = false
584581
585- klog .V (3 ).Infof ("Replacing location %q for server %q with upstream %q to use upstream %q (Ingress %q)" ,
586- loc .Path , server .Hostname , loc .Backend , ups .Name , ingKey )
582+ if ! loc .IsDefBackend {
583+ klog .V (3 ).Infof ("Location %q already configured for server %q with upstream %q (Ingress %q)" ,
584+ loc .Path , server .Hostname , loc .Backend , ingKey )
585+ break
586+ }
587587
588- loc .Backend = ups .Name
589- loc .IsDefBackend = false
590- loc .Port = ups .Port
591- loc .Service = ups .Service
592- loc .Ingress = ing
588+ klog .V (3 ).Infof ("Replacing location %q for server %q with upstream %q to use upstream %q (Ingress %q)" ,
589+ loc .Path , server .Hostname , loc .Backend , ups .Name , ingKey )
593590
594- locationApplyAnnotations (loc , anns )
591+ loc .Backend = ups .Name
592+ loc .IsDefBackend = false
593+ loc .Port = ups .Port
594+ loc .Service = ups .Service
595+ loc .Ingress = ing
595596
596- if loc . Redirect . FromToWWW {
597- server . RedirectFromToWWW = true
598- }
599- break
597+ locationApplyAnnotations ( loc , anns )
598+
599+ if loc . Redirect . FromToWWW {
600+ server . RedirectFromToWWW = true
600601}
602+
603+ break
601604}
602605
603606// new location
@@ -1048,14 +1051,14 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
10481051
10491052// special "catch all" case, Ingress with a backend but no rule
10501053defLoc := servers [defServerName ].Locations [0 ]
1054+ defLoc .Backend = backendUpstream .Name
1055+ defLoc .Service = backendUpstream .Service
1056+ defLoc .Ingress = ing
1057+
10511058if defLoc .IsDefBackend && len (ing .Spec .Rules ) == 0 {
1052- klog .V (2 ).Infof ("Ingress %q defines a backend but no rule. Using it to configure the catch-all server %q" ,
1053- ingKey , defServerName )
1059+ klog .V (2 ).Infof ("Ingress %q defines a backend but no rule. Using it to configure the catch-all server %q" , ingKey , defServerName )
10541060
10551061defLoc .IsDefBackend = false
1056- defLoc .Backend = backendUpstream .Name
1057- defLoc .Service = backendUpstream .Service
1058- defLoc .Ingress = ing
10591062
10601063// TODO: Redirect and rewrite can affect the catch all behavior, skip for now
10611064originalRedirect := defLoc .Redirect
@@ -1064,8 +1067,7 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
10641067defLoc .Redirect = originalRedirect
10651068defLoc .Rewrite = originalRewrite
10661069} else {
1067- klog .V (3 ).Infof ("Ingress %q defines both a backend and rules. Using its backend as default upstream for all its rules." ,
1068- ingKey )
1070+ klog .V (3 ).Infof ("Ingress %q defines both a backend and rules. Using its backend as default upstream for all its rules." , ingKey )
10691071}
10701072}
10711073}
@@ -1081,12 +1083,12 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
10811083continue
10821084}
10831085
1084- pathTypePrefix := networking .PathTypePrefix
10851086loc := & ingress.Location {
10861087Path : rootLocation ,
10871088PathType : & pathTypePrefix ,
10881089IsDefBackend : true ,
10891090Backend : un ,
1091+ Ingress : ing ,
10901092Service : & apiv1.Service {},
10911093}
10921094locationApplyAnnotations (loc , anns )
0 commit comments