fix: auto read kubernetes service discovery token#12057
Merged
Baoyuantop merged 16 commits intoapache:masterfrom Mar 25, 2025
Merged
fix: auto read kubernetes service discovery token#12057Baoyuantop merged 16 commits intoapache:masterfrom
Baoyuantop merged 16 commits intoapache:masterfrom
Conversation
membphis
requested changes
Mar 19, 2025
Member
membphis
left a comment
There was a problem hiding this comment.
- 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
| end | ||
|
|
||
| if handle.token_file then | ||
| refresh_token(handle, handle.token_file) |
Member
There was a problem hiding this comment.
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
membphis
reviewed
Mar 21, 2025
apisix/discovery/kubernetes/init.lua
Outdated
| end | ||
|
|
||
| -- remove possible extra whitespace | ||
| local trimmed_token = token:gsub("%s+", "") |
apisix/discovery/kubernetes/init.lua
Outdated
|
|
||
| local token, err = read_token(token_file_path) | ||
| if err then | ||
| return nil, err |
Member
There was a problem hiding this comment.
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") |
Member
There was a problem hiding this comment.
use log.info、log.notice is suitable
apisix/discovery/kubernetes/init.lua
Outdated
|
|
||
| local function update_token(handle) | ||
| if not handle.apiserver.token_file or handle.apiserver.token_file == "" then | ||
| return |
Member
There was a problem hiding this comment.
for succ or fail, we should return different value
nic-6443
reviewed
Mar 24, 2025
nic-6443
reviewed
Mar 24, 2025
nic-6443
previously approved these changes
Mar 25, 2025
AlinsRan
approved these changes
Mar 25, 2025
nic-6443
approved these changes
Mar 25, 2025
membphis
approved these changes
Mar 25, 2025
laz-xyr
pushed a commit
to laz-xyr/apisix
that referenced
this pull request
Jun 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Automatically reads the latest content from the token file before the program reads the token value, ensuring that the latest token is used for every request.
Fixes #11779
Checklist