-
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
fix for #1930, make sessions sticky, for ingress with multiple rules … #2451
fix for #1930, make sessions sticky, for ingress with multiple rules … #2451
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. |
/check-cla |
/assign @ingress-nginx-maintainers |
@nusx: GitHub didn't allow me to assign the following users: ingress-nginx-maintainers. Note that only kubernetes members and repo collaborators can be assigned. In response to this:
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. |
/assign @thockin |
Codecov Report
@@ Coverage Diff @@
## master #2451 +/- ##
=======================================
Coverage 40.68% 40.68%
=======================================
Files 75 75
Lines 5108 5108
=======================================
Hits 2078 2078
Misses 2751 2751
Partials 279 279 Continue to review full report at Codecov.
|
@nusx please add e2e tests |
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.
rootfs/etc/nginx/template/nginx.tmpl
Outdated
@@ -358,7 +358,7 @@ http { | |||
{{ range $name, $upstream := $backends }} | |||
{{ if eq $upstream.SessionAffinity.AffinityType "cookie" }} | |||
upstream sticky-{{ $upstream.Name }} { | |||
sticky hash={{ $upstream.SessionAffinity.CookieSessionAffinity.Hash }} name={{ $upstream.SessionAffinity.CookieSessionAffinity.Name }} httponly; | |||
sticky hash={{ $upstream.SessionAffinity.CookieSessionAffinity.Hash }} name={{ $upstream.SessionAffinity.CookieSessionAffinity.Name }}{{ range $locationName, $locationPaths := $upstream.SessionAffinity.CookieSessionAffinity.Locations }}{{ if eq (len $locationPaths) 1 }}{{ range $locationPath := $locationPaths }} path={{ $locationPath }}{{ end }}{{ end }}{{ end}} httponly; |
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.
if eq (len $locationPaths) 1 }}{{ range $locationPath := $locationPaths }}
why using a range if you expect a single element?
@aledbf added e2e tests and updated the template according to @antoineco s comment (now accessing the locationPaths array via index action). |
/assign @aledbf |
@@ -358,7 +358,7 @@ http { | |||
{{ range $name, $upstream := $backends }} | |||
{{ if eq $upstream.SessionAffinity.AffinityType "cookie" }} | |||
upstream sticky-{{ $upstream.Name }} { | |||
sticky hash={{ $upstream.SessionAffinity.CookieSessionAffinity.Hash }} name={{ $upstream.SessionAffinity.CookieSessionAffinity.Name }} httponly; | |||
sticky hash={{ $upstream.SessionAffinity.CookieSessionAffinity.Hash }} name={{ $upstream.SessionAffinity.CookieSessionAffinity.Name }}{{if eq (len $upstream.SessionAffinity.CookieSessionAffinity.Locations) 1 }}{{ range $locationName, $locationPaths := $upstream.SessionAffinity.CookieSessionAffinity.Locations }}{{ if eq (len $locationPaths) 1 }} path={{ index $locationPaths 0 }}{{ end }}{{ end }}{{ end }} httponly; |
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.
As a bonus, you could wrap this logic inside a template function (see internal/ingress/controller/template/template.go
) that receives a *ingress.CookieSessionAffinity
and returns either path=/xyz;
or nothing.
You can then call that function inside the template like {{ cookiepath $upstream.SessionAffinity.CookieSessionAffinity }}
.
No hard feeling on my side though, the Go template language also does the trick here.
@nusx thanks for addressing the different comments, the tests look good to me 👍 |
@antoineco updated the pull request (deleted bindata.go) |
@nusx please squash the commits |
54a6985
to
b08a178
Compare
…ple rules and backends * for an ingress with session affinity cookie, set the location as path on the cookie when unique * the previous behaviour ( cookie path=/ ) is preserved for ingresses with multiple rules for the same backend (locations not unique) added e2e tests for session affinity, setting path on sticky config added tests: * it should set the path to /something on the generated cookie * it should set the path to / on the generated cookie if there's more than one rule referring to the same backend
b08a178
to
1a320ae
Compare
@aledbf squashed the commits |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, antoineco, nusx 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 |
@nusx thanks! |
Sorry but is it not break if i have multiple path and want only ONE cookie hash for all ? |
Cookies are available to all subpaths, but not superpaths. With this fix, next time you'll send a request to |
…and backends
What this PR does / why we need it:
The current template generates upstreams without setting the path parameter on the sticky config. This leads to a new cookie beeing generated whenever the user requests a different path from the ingress. This change sets the path parameter whenever the backend contains only a single location. It falls back to the previous behaviour (not setting the path parameter) if multiple ingress rules exist for the same backend (leading to multiple locations for the backend).
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #1930Special notes for your reviewer: