diff --git a/internal/ingress/controller/location.go b/internal/ingress/controller/location.go index 556fafc6b..e6b6c44bd 100644 --- a/internal/ingress/controller/location.go +++ b/internal/ingress/controller/location.go @@ -51,6 +51,8 @@ func updateServerLocations(locations []*ingress.Location) []*ingress.Location { continue } + location.IngressPath = location.Path + // only Prefix locations could require an additional location block if *location.PathType != pathTypePrefix { newLocations = append(newLocations, location) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 0529369fe..3a6f02c64 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -809,6 +809,7 @@ func isValidByteSize(input interface{}, isOffset bool) bool { type ingressInformation struct { Namespace string + Path string Rule string Service string ServicePort string @@ -848,7 +849,7 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation { return &ingressInformation{} } - path, ok := p.(string) + ingressPath, ok := p.(string) if !ok { klog.Errorf("expected a 'string' type but %T was returned", p) return &ingressInformation{} @@ -862,6 +863,12 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation { Namespace: ing.GetNamespace(), Rule: ing.GetName(), Annotations: ing.Annotations, + Path: ingressPath, + } + + if ingressPath == "" { + ingressPath = "/" + info.Path = "/" } if ing.Spec.Backend != nil { @@ -890,7 +897,7 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation { } for _, rPath := range rule.HTTP.Paths { - if path != rPath.Path { + if ingressPath != rPath.Path { continue } diff --git a/internal/ingress/types.go b/internal/ingress/types.go index 35b574f8c..1be42cf74 100644 --- a/internal/ingress/types.go +++ b/internal/ingress/types.go @@ -232,6 +232,8 @@ type Location struct { IsDefBackend bool `json:"isDefBackend"` // Ingress returns the ingress from which this location was generated Ingress *Ingress `json:"ingress"` + // IngressPath original path defined in the ingress rule + IngressPath string `json:"ingressPath"` // Backend describes the name of the backend to use. Backend string `json:"backend"` // Service describes the referenced services from the ingress diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index b2f4543e5..b37cfe7b4 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1079,12 +1079,12 @@ stream { {{ end }} location {{ $path }} { - {{ $ing := (getIngressInformation $location.Ingress $server.Hostname $location.Path) }} + {{ $ing := (getIngressInformation $location.Ingress $server.Hostname $location.IngressPath) }} set $namespace {{ $ing.Namespace | quote}}; set $ingress_name {{ $ing.Rule | quote }}; set $service_name {{ $ing.Service | quote }}; set $service_port {{ $ing.ServicePort | quote }}; - set $location_path {{ $location.Path | escapeLiteralDollar | quote }}; + set $location_path {{ $ing.Path | escapeLiteralDollar | quote }}; {{ buildOpentracingForLocation $all.Cfg.EnableOpentracing $location }}