-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 bugs in Lua implementation of sticky sessions #2484
Fix bugs in Lua implementation of sticky sessions #2484
Conversation
824e445
to
9c49159
Compare
fc570b0
to
b042cf3
Compare
rootfs/etc/nginx/lua/balancer.lua
Outdated
|
||
if backend["upstream-hash-by"] then | ||
if is_sticky(backend) or backend["upstream-hash-by"] then |
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.
It seems like the only reason this or
is there is to not repeat fetching the endpoint (L57 - L60).
You will have some repeated code here - but I would separate the conditions (is_sticky(backend)
and backend["upstream-hash-by"]
) to keep it easy to read. This way you could also take out the condition on L62.
rootfs/etc/nginx/lua/balancer.lua
Outdated
|
||
local ok | ||
ok, err = cookie:set({ | ||
key = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["name"] or "route", |
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.
Seems more appropriate to default to route
higher up no?https://github.com/kubernetes/ingress-nginx/blob/master/internal/ingress/controller/controller.go#L501
rootfs/etc/nginx/lua/balancer.lua
Outdated
|
||
local endpoint_string = endpoint.address .. ":" .. endpoint.port | ||
local encrypted | ||
if backend["sessionAffinityConfig"]["cookieSessionAffinity"]["hash"] == "sha1" then |
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.
Would be nice to have a helper method here that generates the digested endpoint string rather than doing it over here.
1930ac5
to
8588dde
Compare
Codecov Report
@@ Coverage Diff @@
## master #2484 +/- ##
=========================================
- Coverage 41.66% 41.57% -0.1%
=========================================
Files 74 74
Lines 5282 5270 -12
=========================================
- Hits 2201 2191 -10
+ Misses 2783 2782 -1
+ Partials 298 297 -1
Continue to review full report at Codecov.
|
CI is failing because if a flaky test that's fixed at #2526. I'll rebase once that gets merged. |
8588dde
to
7ac4e1d
Compare
/assign @aledbf |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, ElvinEfendi 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 |
What this PR does / why we need it:
I've detected two bugs with current implementation of sticky sessions in Lua:
it does not re-set the cookie after setting it for the first timethis should be the case - just make it a session cookieThe PR adds regression test and fix the bugs.
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer: