ingress-nginx
ingress-nginx copied to clipboard
Fix incorrect service name being set in the nginx template
This handles the case where multiple rules have identical paths, but differing types. This should populate the $service_name variable with the correct service name.
What this PR does / why we need it:
Fixes: https://github.com/kubernetes/ingress-nginx/issues/10210
At the moment if multiple rules contain the same path, sometimes the incorrect service name may be set in the $service_name variable
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] CVE Report (Scanner found CVE and adding report)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation only
Which issue/s this PR fixes
fixes #10210
How Has This Been Tested?
Test case added in PR.
Manual testing locally and checking the outputted nginx.conf
file
Checklist:
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I've read the CONTRIBUTION guide
- [x] I have added unit and/or e2e tests to cover my changes.
- [ ] All new and existing tests passed.
Welcome @adrianmoisey!
It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes/ingress-nginx has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
Hi @adrianmoisey. Thanks for your PR.
I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test
on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test
label.
I understand the commands that are listed here.
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.
Deploy Preview for kubernetes-ingress-nginx canceled.
Name | Link |
---|---|
Latest commit | b59fcbdee8e3973d4cc078570f2e77bd232fc8ed |
Latest deploy log | https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/66e5a4cffdf60000083859d9 |
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: adrianmoisey Once this PR has been reviewed and has the lgtm label, please assign puerco for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment
/triage accepted /kind bug /priority backlog /cc @strongjz @tao12345666333
/cherry-pick release-1.10
@Gacko: once the present PR merges, I will cherry-pick it on top of release-1.10 in a new PR and assign it to you.
In response to this:
/cherry-pick release-1.10
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.
@adrianmoisey @Gacko Can you post the link proof from upstream K8S KEP, that clarifies, that identical host joined with identical path, is allowed to be a individual new rule, just because the pathType
is different
Can you post the link proof from upstream K8S KEP, that clarifies, that identical host joined with identical path, is allowed to be a individual new rule, just because the
pathType
is different
Bullet point 4 from: https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/758-ingress-api-group#path-matching-semantics
If there is more than one potential match: Exact match is preferred to a Prefix match. For multiple prefix matches, the longest Path p_i will be the matching path. If an ImplementationSpecific match exists in the spec, then the preference depends on the implementation
Note: This PR isn't adding new paths/rules to nginx. It already does that. This is just fixing the case where the incorrect service is set in $service_name in that location block, which causes metrics to be reported incorrectly (I'm unsure if other functionality relies on that variable)
@adrianmoisey thanks for the link.
I am not a developer.
Do the words preferred
and preference
, in the context of the word match
, imply that admission-webhook should allow 2 identical host+path rules, albeit with different pathTypes. Not being an expert, I think that itself is a mess, and a bigger mess than the current behavior of wrong-service-name.
I have just seen pattern of duplicates not being appropriate, for not-short-time now, simply because, regardless of admission-webook accepting duplicate combo of host+path
or wrong-service-name
in location, there is still a simple contention of which rule MATCHES
the request. And it seems that the link you provided just explains how (at least some) the duplicates are evaluated for a match
, to route the request.
These are my thoughts. Will wait to get educated on the intricacies. It means now we clearly support duplicates in the project.
Also, from the point of view of benefit to mass of users, admission-webhook should not allow duplicates.
I do understand that temporary duplicates help in migration as well as permanent duplicates as variants of pathType though.
So its a question of having a messy feature that is a antipattern to ingress traffic or having such a feature and maintaining it but only a couple of users getting benefit from the feature.
/ok-to-test
/assign
Also, from the point of view of benefit to mass of users, admission-webhook should not allow duplicates.
I do understand that temporary duplicates help in migration as well as permanent duplicates as variants of pathType though.
So its a question of having a messy feature that is a antipattern to ingress traffic or having such a feature and maintaining it but only a couple of users getting benefit from the feature.
I'm not sure I understand why this is considered an anti-pattern.
We have a valid use case where /
goes to one service, and /*
goes to another service.
However, my PR is simply a bug fix, it's not really related to if a feature should or shouldn't exist.
Hi @adrianmoisey , You are right. My comments are not directly related to the changes you propose in this PR.
However its the broader context that has become visible via this PR and hence my comments.
/uncc
/unassign
Hi @Gacko Just a friendly ping to see if it's possible to get a review on this. Is there anything I can do to help this along?
Thanks!