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 ingress updating for session-cookie-* annotation changes #3740

Merged
merged 1 commit into from
Feb 19, 2019

Conversation

alexkursell
Copy link
Contributor

What this PR does / why we need it: The sticky load balancer was ignoring changes in

nginx.ingress.kubernetes.io/session-cookie-name
nginx.ingress.kubernetes.io/session-cookie-hash
nginx.ingress.kubernetes.io/session-cookie-expires
nginx.ingress.kubernetes.io/session-cookie-max-age

requiring the creation of a new pod before the annotations were applied.

Which issue this PR fixes : fixes #3725

Special notes for your reviewer: @ElvinEfendi let me know if this change is big enough to add an e2e test.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 7, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 7, 2019
@alexkursell alexkursell force-pushed the session-annotation-reload branch from 9d63dfa to c1c98d6 Compare February 7, 2019 21:05
@alexkursell
Copy link
Contributor Author

alexkursell commented Feb 7, 2019

Side note: why does nginx.ingress.kubernetes.io/session-cookie-hash exist? The only thing I can tell that the hash function does is to make randomly generated cookie value look more random, so why does the hash function you use for that need to be swappable or user-configurable?

@aledbf
Copy link
Member

aledbf commented Feb 7, 2019

Side note: why does nginx.ingress.kubernetes.io/session-cookie-hash exist?

Because before the lua implementation we used bitbucket.org/nginx-goodies/nginx-sticky-module-ng where you can choose between index|md5|sha1 as implementation

@aledbf
Copy link
Member

aledbf commented Feb 7, 2019

@alexkursell @ElvinEfendi if this makes no sense now we could deprecate the annotation.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 8, 2019
@aledbf
Copy link
Member

aledbf commented Feb 12, 2019

@alexkursell please squash the commits

@ElvinEfendi
Copy link
Member

@alexkursell you can remove all individual attributes at https://github.com/kubernetes/ingress-nginx/pull/3740/files#diff-8f83606fdd5dc8d2406cda71b9609762R21 now, since you're storing the whole config object now.

@ElvinEfendi
Copy link
Member

This is a great find @alexkursell ! I'm sure chashsubset suffers from the similar issue since it's also skipping sync when endpoints don't change. cc @diegows

@alexkursell alexkursell force-pushed the session-annotation-reload branch 2 times, most recently from be79d13 to 6e41383 Compare February 13, 2019 15:41
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 13, 2019
@alexkursell
Copy link
Contributor Author

@alexkursell you can remove all individual attributes at https://github.com/kubernetes/ingress-nginx/pull/3740/files#diff-8f83606fdd5dc8d2406cda71b9609762R21 now, since you're storing the whole config object now.

Fixed

@diegows
Copy link
Contributor

diegows commented Feb 13, 2019

ack, I'll check chashsubset this week.

@@ -15,13 +15,10 @@ function _M.new(self, backend)
local o = {
instance = self.factory:new(nodes),
cookie_name = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["name"] or "route",
Copy link
Member

Choose a reason for hiding this comment

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

Why are you keeping this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought it looked cleaner than oring it with "route" in 2 different places. But this is probably more confusing, because everything else is in cookie_sesstion_affinity. fixed.

return
end

for key, val in pairs(self:new(backend)) do
Copy link
Member

Choose a reason for hiding this comment

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

This is not good - what you wanna do here is to update only the things that might change when self.cookie_session_affinity changes. But right now you are also creating a new resty balancer instance and updating the instance of self with new one unnecessarily.

All you need to do here is to update cookie_session_affinity and digest_func.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@alexkursell alexkursell force-pushed the session-annotation-reload branch from 20bb1f9 to 279bd0e Compare February 19, 2019 18:40
end)
end)

context("when backend does not specify cookie name", function()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this test not necessary anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it because the actual cookie name wasn't being stored on the balancer anymore. I've added the test back and made it use a method on the balancer to check the cookie name.

@@ -4,24 +4,26 @@ local util = require("util")
local ck = require("resty.cookie")

local _M = balancer_resty:new({ factory = resty_chash, name = "sticky" })
local default_cookie_name = "route"
Copy link
Member

Choose a reason for hiding this comment

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

The convention is to use uppercase for constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if not cookie_path then
cookie_path = ngx.var.location_path
end

local cookie_name = self.cookie_session_affinity.name or default_cookie_name
Copy link
Member

Choose a reason for hiding this comment

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

You could define a local function cookie_name to avoid duplicate oring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. I defined a method so thatsticky_test.lua can also use it to check that the logic is correct.

Copy link
Member

Choose a reason for hiding this comment

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

Usually we define local function in these cases and then conditionally export it for testing if _TEST global variable is defined. But it's OK.

@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2019
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2019
@alexkursell alexkursell force-pushed the session-annotation-reload branch from 90d3516 to c180a09 Compare February 19, 2019 22:27
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2019
@alexkursell
Copy link
Contributor Author

@ElvinEfendi , sorry, needs another lgtm after I squashed the commits.

@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexkursell, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 15d5ef9 into kubernetes:master Feb 19, 2019
@alexkursell alexkursell deleted the session-annotation-reload branch February 20, 2019 14:57
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No config reload is triggered when changing annotations (f.e. nginx.ingress.kubernetes.io/session-cookie-name)
5 participants