From 1819be7f75006d1382909510f01e2d067aca5dfe Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Fri, 13 Sep 2024 18:33:06 +0800 Subject: [PATCH 1/5] fix endpoint slices flush_all/flush_expired bug Signed-off-by: dongjiang1989 --- apisix/discovery/kubernetes/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apisix/discovery/kubernetes/init.lua b/apisix/discovery/kubernetes/init.lua index 5daf5d228516..d1843b729dca 100644 --- a/apisix/discovery/kubernetes/init.lua +++ b/apisix/discovery/kubernetes/init.lua @@ -557,10 +557,11 @@ local function multiple_mode_init(confs) else endpoints_informer.on_added = on_endpoint_modified endpoints_informer.on_modified = on_endpoint_modified + -- endpoints is fully updated and the cache is cleared first. + endpoints_informer.pre_list = pre_list + endpoints_informer.post_list = post_list end endpoints_informer.on_deleted = on_endpoint_deleted - endpoints_informer.pre_list = pre_list - endpoints_informer.post_list = post_list ctx[id] = setmetatable({ endpoint_dict = endpoint_dict, From 99e23c621d8b7fc78dc781ac96e390598941c0ee Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Sat, 14 Sep 2024 11:07:57 +0800 Subject: [PATCH 2/5] fix lua lint Signed-off-by: dongjiang1989 --- apisix/discovery/kubernetes/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/discovery/kubernetes/init.lua b/apisix/discovery/kubernetes/init.lua index d1843b729dca..c6da6784528e 100644 --- a/apisix/discovery/kubernetes/init.lua +++ b/apisix/discovery/kubernetes/init.lua @@ -557,7 +557,7 @@ local function multiple_mode_init(confs) else endpoints_informer.on_added = on_endpoint_modified endpoints_informer.on_modified = on_endpoint_modified - -- endpoints is fully updated and the cache is cleared first. + -- endpoints is fully updated and the cache is cleared first. endpoints_informer.pre_list = pre_list endpoints_informer.post_list = post_list end From f9069787e1174beb01005b9b9b8b1f9549b5293b Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Tue, 22 Oct 2024 16:49:04 +0800 Subject: [PATCH 3/5] add e2e casae Signed-off-by: dongjiang1989 --- t/kubernetes/discovery/kubernetes3.t | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/t/kubernetes/discovery/kubernetes3.t b/t/kubernetes/discovery/kubernetes3.t index e2242e9a8c13..f1b8cc1b3a75 100644 --- a/t/kubernetes/discovery/kubernetes3.t +++ b/t/kubernetes/discovery/kubernetes3.t @@ -427,3 +427,63 @@ qr{ 0 0 2 2 0 0 0 0 2 2 0 0 } GET /dump --- response_body_like .*"name":"default/kubernetes".* + +=== TEST 5: when endpoint_slices updated, old endpoints all flush_all/flush_expired +--- yaml_config eval: $::yaml_config +--- request +POST /operators +[ + { + "op": "replace_endpointslices", + "namespace": "ns-b", + "name": "ep", + "endpoints": [ + { + "addresses": [ + "10.0.0.1", + "10.0.0.2" + "10.0.0.3" + ], + "conditions": { + "ready": true, + "serving": true, + "terminating": false + }, + "nodeName": "kind-control-plane" + }, + { + "addresses": [ + "20.0.0.1", + "20.0.0.2" + "20.0.0.3" + ], + "conditions": { + "ready": true, + "serving": true, + "terminating": false + }, + "nodeName": "kind-control-plane" + } + ], + "ports": [ + { + "name": "p", + "port": 5002 + } + ] + } +] +--- more_headers +Content-type: application/json +--- response_body_like +.*"name":"default/kubernetes".* +--- request +GET /queries +[ + "first/ns-a/ep:p1","first/ns-a/ep:p2","first/ns-b/ep:p1","first/ns-b/ep:p2","first/ns-c/ep:5001","first/ns-c/ep:5002", + "second/ns-a/ep:p1","second/ns-a/ep:p2","second/ns-b/ep:p1","second/ns-b/ep:p2","second/ns-c/ep:5001","second/ns-c/ep:5002" +] +--- more_headers +Content-type: application/json +--- response_body eval +qr{ 0 0 2 2 0 0 0 0 2 2 0 0 } \ No newline at end of file From 9239b1dc4b83084b982506dcb68b53071f6414bf Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Tue, 22 Oct 2024 17:00:28 +0800 Subject: [PATCH 4/5] update case Signed-off-by: dongjiang1989 --- t/kubernetes/discovery/kubernetes3.t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/kubernetes/discovery/kubernetes3.t b/t/kubernetes/discovery/kubernetes3.t index f1b8cc1b3a75..54f9c680be00 100644 --- a/t/kubernetes/discovery/kubernetes3.t +++ b/t/kubernetes/discovery/kubernetes3.t @@ -428,6 +428,8 @@ GET /dump --- response_body_like .*"name":"default/kubernetes".* + + === TEST 5: when endpoint_slices updated, old endpoints all flush_all/flush_expired --- yaml_config eval: $::yaml_config --- request From cb98ef8a86a940625a0dd2ad579ed8d3f8e9138d Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Tue, 22 Oct 2024 17:03:02 +0800 Subject: [PATCH 5/5] fix e2e case Signed-off-by: dongjiang1989 --- t/kubernetes/discovery/kubernetes3.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/kubernetes/discovery/kubernetes3.t b/t/kubernetes/discovery/kubernetes3.t index 54f9c680be00..d1a90e92b389 100644 --- a/t/kubernetes/discovery/kubernetes3.t +++ b/t/kubernetes/discovery/kubernetes3.t @@ -488,4 +488,4 @@ GET /queries --- more_headers Content-type: application/json --- response_body eval -qr{ 0 0 2 2 0 0 0 0 2 2 0 0 } \ No newline at end of file +qr{ 0 0 2 2 0 0 0 0 2 2 0 0 }