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

Fix incorrect service name being set in the nginx template #11294

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adrianmoisey
Copy link

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: #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

  • 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.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

Fix: kubernetes#10210

This handles the case where multiple rules have identical paths, but
differing types.
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added needs-priority size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 22, 2024
Copy link

netlify bot commented Apr 22, 2024

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit aab1a97
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/66265cc16d64400008a88232

@k8s-ci-robot
Copy link
Contributor

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

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 requested a review from Gacko April 22, 2024 12:41
Comment on lines 1083 to 1086
ingressPathType, ok := t.(*v1.PathType)
if !ok {
klog.Errorf("expected a '*v1.PathType' type but %T was returned", t)
}
Copy link
Author

Choose a reason for hiding this comment

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

I'm unsure if this is the best way to handle the type assertion.
It seems like we may get the correct type, or nothing at all (empty string I think).
Happy to change this if anyone has a suggestion.

@Gacko
Copy link
Member

Gacko commented Apr 22, 2024

/triage accepted
/kind bug
/priority backlog
/cc @strongjz @tao12345666333

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority labels Apr 22, 2024
@Gacko
Copy link
Member

Gacko commented Apr 22, 2024

/cherry-pick release-1.10

@k8s-infra-cherrypick-robot
Copy link
Contributor

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

@longwuyuan
Copy link
Contributor

@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

@adrianmoisey
Copy link
Author

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)

@longwuyuan
Copy link
Contributor

longwuyuan commented Apr 22, 2024

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

@longwuyuan
Copy link
Contributor

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.

@Gacko
Copy link
Member

Gacko commented Apr 23, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 23, 2024
@Gacko
Copy link
Member

Gacko commented Apr 24, 2024

/assign

Comment on lines +1082 to +1085
ingressPathType, ok := t.(*networkingv1.PathType)
if !ok {
klog.Errorf("expected a '*v1.PathType' type but %T was returned", t)
}
Copy link
Author

Choose a reason for hiding this comment

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

I'm unsure if this is the best way to handle the type assertion.
It seems like we may get the correct type, or nothing at all (empty string I think).
Happy to change this if anyone has a suggestion.

I guess another option is to default to ImplementationSpecific , should this assertion fail (https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/758-ingress-api-group#defaults)

@adrianmoisey
Copy link
Author

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.

@longwuyuan
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect service name emitted in some metrics
5 participants