-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend kubernetes interrelation variables in nginx.tmpl #2486
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@distol please sign the CLA |
rootfs/etc/nginx/template/nginx.tmpl
Outdated
@@ -834,6 +836,7 @@ stream { | |||
set $namespace "{{ $ing.Namespace }}"; | |||
set $ingress_name "{{ $ing.Rule }}"; | |||
set $service_name "{{ $ing.Service }}"; | |||
set $service_port "{{ if $location.Port }}{{ $location.Port }}{{ end }}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional is not necessary here.
rootfs/etc/nginx/template/nginx.tmpl
Outdated
@@ -829,6 +829,12 @@ stream { | |||
{{ end }} | |||
|
|||
location {{ $path }} { | |||
{{ $ing := (getIngressInformation $location.Ingress $location.Path) }} | |||
{{/* $ing.Metadata contains the Ingress metadata */}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated comment ($ing.Metadata is not referenced).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
rootfs/etc/nginx/template/nginx.tmpl
Outdated
set $namespace "{{ $ing.Namespace }}"; | ||
set $ingress_name "{{ $ing.Rule }}"; | ||
set $service_name "{{ $ing.Service }}"; | ||
set $service_port "{{ if $location.Port }}{{ $location.Port }}{{ end }}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional is not necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Oh, you also have to run |
/lgtm |
@distol please squash the commits and we are ready to merge |
@aledbf, commits are already squashed. I've made 3 small independent changes, so there are 3 commits, one for each change with its own comment. |
@distol friendly ping. Please rebase and squash |
set $ingress_name "{{ $ing.Rule }}"; | ||
set $service_name "{{ $ing.Service }}"; | ||
set $service_port "{{ $location.Port }}"; | ||
set $location_path "{{ $location.Path }}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe a use case for this? Are $request
or $request_uri
not enough to identify which path got hit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Ingress Controller lives between three worlds:
- HTTP world —
$scheme
,$host
,$request_uri
- Nginx world — vhost (
$server_name
) and location ($location_path
) - Kubernetes world — namespace (
$namespace
), ingress ($ingress_name
), and service ($service_name
,$service_port
).
So, depending on the task, we should be able to easily identify request in any of the "coordinate systems".
To make it more clear, that you could use $namespace, $ingress_name and $service_name variables anywhere in location (especialy in lua), move their definition to the very begining of the location.
According to TCP/IP (and common sense), $service_name is not enough to uniquely identify service, we need $service_port for that.
When you define rules in ingress resource, you use path. So it would be very useful to be able to use the same path in logs.
@aledbf, I've already written, that commits have been squashed from the very beginning. I've made 3 small independent changes, and to my sense, it should be 3 commits, one for each change with its own comment. And same time it looks not reasonable to make three pull requests because changes are too small. Please have a look at commit log and if after that you will not change your mind — no problem, I'll squash these three changes to one commit. P.S. Rebased to the master and removed bindata. |
/lgtm |
@distol thanks! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, antoineco, distol The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@distol next time, please squash the commits |
This PR improves variables, that allows associate (in logs and in lua) nginx servers and locations with related kubernetes resources:
$service_name
is not enough to uniquely identify "service", we need$service_port
for that.