-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: timed read kubernetes service discovery token #12057
base: master
Are you sure you want to change the base?
Conversation
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 is not a new feature, it should be a bug, pls update your title
- we should use cache, eg: 1hour or 1day, and then we can refresh it, this is more acceptable
apisix/discovery/kubernetes/init.lua
Outdated
local function start_fetch(handle) | ||
local timer_runner | ||
timer_runner = function(premature) | ||
if premature then | ||
return | ||
end | ||
|
||
if handle.token_file then | ||
refresh_token(handle, handle.token_file) |
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.
bad name
cache
-> refresh
: this is a good name
no cache -> refresh: it is weird
it should be name to read token
or fetch token
apisix/discovery/kubernetes/init.lua
Outdated
end | ||
|
||
-- remove possible extra whitespace | ||
local trimmed_token = token:gsub("%s+", "") |
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.
waiting
apisix/discovery/kubernetes/init.lua
Outdated
|
||
local token, err = read_token(token_file_path) | ||
if err then | ||
return nil, err |
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.
we only can choose one of them:
if not attributes then
core.log.error("failed to fetch ", token_file_path, " attributes: ", err)
return
end
if err then
return nil, err
end
apisix/discovery/kubernetes/init.lua
Outdated
|
||
handle.apiserver.token = token | ||
handle.token_file_mtime = last_modification_time | ||
core.log.warn("kubernetes service account token has been updated") |
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.
use log.info
、log.notice
is suitable
|
||
local function update_token(handle) | ||
if not handle.apiserver.token_file or handle.apiserver.token_file == "" then | ||
return |
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.
for succ
or fail
, we should return different value
Description
Get the token from
token_path
at regular intervals and update the configuration if the value is changed to avoid token expiration errors.Fixes #11779
Checklist