Copilot commented on code in PR #13054:
URL: https://github.com/apache/apisix/pull/13054#discussion_r2922639198


##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -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)

Review Comment:
   The immediate path only handles pcall errors (Lua runtime exceptions) but 
doesn't check when `list_watch` returns `false` (e.g., connection failure, list 
failure). Compare with the timer-based path below (line 530-536), which checks 
both `not ok` and `not status`. While `list_watch` does log errors internally, 
this function loses track of whether the warm-up actually succeeded. Consider 
also checking `not status` and logging appropriately, consistent with the timer 
path.
   ```suggestion
                              ", reason: RuntimeException, message: ", status)
           elseif not status then
               core.log.error("list_watch failed, kind: ", handle.kind,
                              ", reason: ListAndWatchFailure, message: 
list_watch returned false during immediate fetch")
   ```



##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -762,6 +773,9 @@ function _M.init_worker()
 end
 
 
+_M.init = _M.init_worker

Review Comment:
   `_M.init = _M.init_worker` means both the master warm-up call and the 
worker/privileged-agent call execute the same function. If `init_worker` is 
ever changed independently (e.g., to add worker-specific logic), it would 
unintentionally affect the master warm-up path too. Consider extracting the 
shared initialization logic into a separate helper, or at minimum, adding a 
comment documenting that `init` is intentionally aliased to `init_worker` and 
any changes to one affect the other.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to