ChuanFF commented on issue #12635:
URL: https://github.com/apache/apisix/issues/12635#issuecomment-3334698643

   I propose setting a flag in the shared_dict to indicate that APISIX has 
completed data ingestion in `apisix.discovery.kubernetes.post_list()`. The 
`post_list` function is called after APISIX pulls Kubernetes endpoints data. We 
can then check whether this flag has been written into every relevant 
shared_dict. The readiness check code is as follows:
   ```lua
   local function check_ready(dict_name)
       local endpoint_dict = ngx.shared[dict_name]
       if not endpoint_dict then
           core.log.error("failed to get lua_shared_dict:", dict_name, ", 
please check your APISIX version")
           return false, "failed to get lua_shared_dict: ", dict_name, ", 
please check your APISIX version"
       end
       local ready = endpoint_dict:get("discovery_ready")
       if not ready then
           return false, "discovery not ready"
       end
       return true
   end
   
   local function single_mode_check_discovery_ready()
       local _, err = check_ready(dict_base_name)
       if err then
           core.log.warn(err)
           return 500, err
       end
       return 200, "discovery ready"
   end
   
   local function multiple_mode_check_discovery_ready(confs)
       for _, conf in ipairs(confs) do
           local id = conf.id
           local dict_name = dict_base_name .. "-" .. id
           local _, err = check_ready(dict_name)
           if err then
               return 500, err
           end
       end
       return 200, "discovery ready"
   end
   
   local function check_discovery_ready()
       local discovery_conf = local_conf.discovery and 
local_conf.discovery.kubernetes
       if not discovery_conf then
           return 200, "discovery disable"
       end
       if #discovery_conf == 0 then
           return single_mode_check_discovery_ready()
       else
           return multiple_mode_check_discovery_ready(discovery_conf)
       end
   end
   ```
   


-- 
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