@@ -51,7 +51,7 @@ local function sort_nodes_cmp(left, right)
5151 return left .port < right .port
5252end
5353
54- local function on_endpoint_slices_modified (handle , endpoint )
54+ local function on_endpoint_slices_modified (handle , endpoint , operate )
5555 if handle .namespace_selector and
5656 not handle :namespace_selector (endpoint .metadata .namespace ) then
5757 return
@@ -114,10 +114,15 @@ local function on_endpoint_slices_modified(handle, endpoint)
114114 if err then
115115 core .log .error (" set endpoint into discovery DICT failed, " , err )
116116 handle .endpoint_dict :delete (endpoint_key .. " #version" )
117+ return
118+ end
119+ if operate == " list" then
120+ handle .current_keys_hash [endpoint_key ] = true
121+ handle .current_keys_hash [endpoint_key .. " #version" ] = true
117122 end
118123end
119124
120- local function on_endpoint_modified (handle , endpoint )
125+ local function on_endpoint_modified (handle , endpoint , operate )
121126 if handle .namespace_selector and
122127 not handle :namespace_selector (endpoint .metadata .namespace ) then
123128 return
@@ -177,6 +182,11 @@ local function on_endpoint_modified(handle, endpoint)
177182 if err then
178183 core .log .error (" set endpoint into discovery DICT failed, " , err )
179184 handle .endpoint_dict :delete (endpoint_key .. " #version" )
185+ return
186+ end
187+ if operate == " list" then
188+ handle .current_keys_hash [endpoint_key ] = true
189+ handle .current_keys_hash [endpoint_key .. " #version" ] = true
180190 end
181191end
182192
@@ -195,12 +205,23 @@ end
195205
196206
197207local function pre_list (handle )
198- handle .endpoint_dict :flush_all ()
208+ handle .current_keys_hash = {}
209+ handle .existing_keys = handle .endpoint_dict :get_keys (0 )
199210end
200211
201212
202213local function post_list (handle )
203- handle .endpoint_dict :flush_expired ()
214+ if not handle .existing_keys or not handle .current_keys_hash then
215+ return
216+ end
217+ for _ , key in ipairs (handle .existing_keys ) do
218+ if not handle .current_keys_hash [key ] then
219+ core .log .info (" kubernetes discovery module find dirty data in shared dict, key:" , key )
220+ handle .endpoint_dict :delete (key )
221+ end
222+ end
223+ handle .existing_keys = nil
224+ handle .current_keys_hash = nil
204225end
205226
206227
@@ -369,7 +390,7 @@ local function get_apiserver(conf)
369390end
370391
371392local function create_endpoint_lrucache (endpoint_dict , endpoint_key , endpoint_port )
372- local endpoint_content = endpoint_dict :get_stale (endpoint_key )
393+ local endpoint_content = endpoint_dict :get (endpoint_key )
373394 if not endpoint_content then
374395 core .log .error (" get empty endpoint content from discovery DIC, this should not happen " ,
375396 endpoint_key )
@@ -497,7 +518,7 @@ local function single_mode_nodes(service_name)
497518 local endpoint_dict = ctx
498519 local endpoint_key = match [1 ]
499520 local endpoint_port = match [2 ]
500- local endpoint_version = endpoint_dict :get_stale (endpoint_key .. " #version" )
521+ local endpoint_version = endpoint_dict :get (endpoint_key .. " #version" )
501522 if not endpoint_version then
502523 core .log .info (" get empty endpoint version from discovery DICT " , endpoint_key )
503524 return nil
@@ -612,7 +633,7 @@ local function multiple_mode_nodes(service_name)
612633
613634 local endpoint_key = match [2 ]
614635 local endpoint_port = match [3 ]
615- local endpoint_version = endpoint_dict :get_stale (endpoint_key .. " #version" )
636+ local endpoint_version = endpoint_dict :get (endpoint_key .. " #version" )
616637 if not endpoint_version then
617638 core .log .info (" get empty endpoint version from discovery DICT " , endpoint_key )
618639 return nil
0 commit comments