-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(discovery): add kubernetes discovery data warm-up in master process #13054
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,7 +506,18 @@ local _M = { | |
| } | ||
|
|
||
|
|
||
| local function start_fetch(handle) | ||
| local function start_fetch(handle, immediate) | ||
| if immediate then | ||
| -- Execute immediately and synchronously without using timer | ||
| core.log.info(process.type(), " process immediately pulls the k8s endpoints list") | ||
| local ok, status = pcall(handle.list_watch, handle, handle.apiserver, true) | ||
| if not ok then | ||
| core.log.error("list_watch failed, kind: ", handle.kind, | ||
| ", reason: RuntimeException, message: ", status) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| local timer_runner | ||
| timer_runner = function(premature) | ||
| if premature then | ||
|
|
@@ -558,7 +569,7 @@ local function single_mode_init(conf) | |
| "please check your APISIX version") | ||
| end | ||
|
|
||
| if process.type() ~= "privileged agent" then | ||
| if process.type() == "worker" then | ||
| ctx = endpoint_dict | ||
| return | ||
| end | ||
|
|
@@ -605,7 +616,7 @@ local function single_mode_init(conf) | |
| default_weight = default_weight | ||
| }, { __index = endpoints_informer }) | ||
|
|
||
| start_fetch(ctx) | ||
| start_fetch(ctx, process.type() == "master") | ||
| end | ||
|
|
||
|
|
||
|
|
@@ -653,7 +664,7 @@ end | |
| local function multiple_mode_init(confs) | ||
| ctx = core.table.new(#confs, 0) | ||
|
|
||
| if process.type() ~= "privileged agent" then | ||
| if process.type() == "worker" then | ||
| multiple_mode_worker_init(confs) | ||
| return | ||
| end | ||
|
|
@@ -716,7 +727,7 @@ local function multiple_mode_init(confs) | |
| end | ||
|
|
||
| for _, item in pairs(ctx) do | ||
| start_fetch(item) | ||
| start_fetch(item, process.type() == "master") | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -762,6 +773,9 @@ function _M.init_worker() | |
| end | ||
|
|
||
|
|
||
| _M.init = _M.init_worker | ||
|
||
|
|
||
|
|
||
| local function dump_endpoints_from_dict(endpoint_dict) | ||
| local keys, err = endpoint_dict:get_keys(0) | ||
| if err 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.
The immediate path only handles pcall errors (Lua runtime exceptions) but doesn't check when
list_watchreturnsfalse(e.g., connection failure, list failure). Compare with the timer-based path below (line 530-536), which checks bothnot okandnot status. Whilelist_watchdoes log errors internally, this function loses track of whether the warm-up actually succeeded. Consider also checkingnot statusand logging appropriately, consistent with the timer path.