Skip to content
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

Merged
merged 3 commits into from
Jun 8, 2018
Merged

Extend kubernetes interrelation variables in nginx.tmpl #2486

merged 3 commits into from
Jun 8, 2018

Conversation

dmgtn
Copy link
Contributor

@dmgtn dmgtn commented May 9, 2018

This PR improves variables, that allows associate (in logs and in lua) nginx servers and locations with related kubernetes resources:

  1. According to TCP/IP (and common sense), $service_name is not enough to uniquely identify "service", we need $service_port for that.
  2. 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 (and in lua).

@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 9, 2018
@aledbf
Copy link
Member

aledbf commented May 10, 2018

@distol please sign the CLA

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 10, 2018
@@ -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 }}";
Copy link
Contributor

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.

@@ -829,6 +829,12 @@ stream {
{{ end }}

location {{ $path }} {
{{ $ing := (getIngressInformation $location.Ingress $location.Path) }}
{{/* $ing.Metadata contains the Ingress metadata */}}
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

set $namespace "{{ $ing.Namespace }}";
set $ingress_name "{{ $ing.Rule }}";
set $service_name "{{ $ing.Service }}";
set $service_port "{{ if $location.Port }}{{ $location.Port }}{{ end }}";
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@antoineco
Copy link
Contributor

antoineco commented May 11, 2018

Oh, you also have to run make code-generator by the way :) It creates a gzipped bytes array of the nginx.tmpl file which gets unpacked in memory during tests, so it has to remain up-to-date with the actual template.

@antoineco
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2018
@aledbf
Copy link
Member

aledbf commented May 11, 2018

@distol please squash the commits and we are ready to merge

@dmgtn
Copy link
Contributor Author

dmgtn commented May 11, 2018

@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.

@aledbf
Copy link
Member

aledbf commented Jun 5, 2018

@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 }}";
Copy link
Member

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?

Copy link
Contributor Author

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".

Dmitry Stolyarov added 3 commits June 7, 2018 13:43
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.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 2018
@dmgtn
Copy link
Contributor Author

dmgtn commented Jun 7, 2018

@distol friendly ping. Please rebase and squash

@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.

@aledbf
Copy link
Member

aledbf commented Jun 8, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 8, 2018
@aledbf
Copy link
Member

aledbf commented Jun 8, 2018

@distol thanks!

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 8, 2018
@aledbf
Copy link
Member

aledbf commented Jun 8, 2018

@distol next time, please squash the commits

@k8s-ci-robot k8s-ci-robot merged commit fc96d5c into kubernetes:master Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants