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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort ingress rules by path length and pathType #2409

Merged
merged 4 commits into from Apr 12, 2022

Conversation

oliviassss
Copy link
Collaborator

@oliviassss oliviassss commented Dec 10, 2021

Issue

#2203

Description

Sort Ingress rules based on the strategy:

  • all exact match paths come first, no need to sort since exact match has to be unique
  • followed by prefix paths, sort by lengths - longer paths get precedence
  • followed by ImplementationSpecific paths or paths with no pathType specified, keep the original order

ref: Kubernetes Ingress (https://kubernetes.io/docs/concepts/services-networking/ingress/#multiple-matches).

Tests

  • Added unit test
  • Manual tested on Ingress creation with multiple ingress rules, verified that the rule with exact pathType has precedence, followed by paths with prefix pathType (order by length desc.), then followed by paths with implementationSpecific pathType.
  • Created Ingresses with controller on v2.4.1 image, then upgraded to the controller with this change. Verified that the ingresses got update, and the order of paths with ImplementationSpecific PathType will remain the same.

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 馃く

  • Backfilled missing tests for code in same general area 馃帀
  • Refactored something and made the world a better place 馃専

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 10, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @oliviassss. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 10, 2021
@kishorj kishorj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Dec 16, 2021
pkg/ingress/rule_optimizer.go Outdated Show resolved Hide resolved
pkg/ingress/rule_optimizer.go Outdated Show resolved Hide resolved
pkg/ingress/rule_optimizer_test.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2021

Codecov Report

Merging #2409 (1fefe3f) into main (b5c8905) will increase coverage by 0.10%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##             main    #2409      +/-   ##
==========================================
+ Coverage   53.83%   53.94%   +0.10%     
==========================================
  Files         144      144              
  Lines        8167     8195      +28     
==========================================
+ Hits         4397     4421      +24     
- Misses       3453     3455       +2     
- Partials      317      319       +2     
Impacted Files Coverage 螖
pkg/ingress/model_build_listener_rules.go 52.40% <85.71%> (+5.86%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update b5c8905...1fefe3f. Read the comment docs.

@kishorj
Copy link
Collaborator

kishorj commented Dec 22, 2021

/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 Dec 22, 2021
@kishorj
Copy link
Collaborator

kishorj commented Dec 22, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2021
@kishorj kishorj removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2021
@kishorj
Copy link
Collaborator

kishorj commented Dec 22, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kishorj, oliviassss

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 Dec 22, 2021
@oliviassss
Copy link
Collaborator Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 27, 2021
@oliviassss
Copy link
Collaborator Author

/remove-hold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 31, 2022
@sergeyshevch
Copy link

@oliviassss Is there any plans to get this merged?

@kishorj
Copy link
Collaborator

kishorj commented Mar 30, 2022

Lets ensure the following for backwards compatibility:

  • If all of the the path types are ImplementationSpecific, we keep the original order. For ingress group, we honor the ingress ordering as well
  • If all of the path types are Prefix/Exact, sort them according to the ingress spec
  • If mixed, order the prefix/exact before the implementation specific. Prefix/exact are always sorted. Implementation specific will follow the original order
    This will ensure users relying on ImplementationSpecific path types will continue to see the same behavior after upgrade

@oliviassss
Copy link
Collaborator Author

Sort Ingress rules based on the strategy:

  • all exact match paths come first, no need to sort since exact match has to be unique
  • followed by prefix paths, sort by lengths - longer paths get precedence
  • followed by ImplementationSpecific paths or paths with no pathType specified, keep the original order

@oliviassss oliviassss requested a review from kishorj April 6, 2022 16:47
@oliviassss
Copy link
Collaborator Author

/retest

@kishorj
Copy link
Collaborator

kishorj commented Apr 12, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 12, 2022
@k8s-ci-robot k8s-ci-robot merged commit ebe1a05 into kubernetes-sigs:main Apr 12, 2022
@oliviassss oliviassss deleted the sort_ingress_rules branch May 11, 2022 18:47
Timothy-Dougherty pushed a commit to adammw/aws-load-balancer-controller that referenced this pull request Nov 9, 2023
* sort ingress rules by path length

* add unit test

* sort paths instead of sorting rules directly

* update sorting strategy
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants