Skip to content
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

fix: wrong namespace related endpoint in k8s #10917

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

dongjiang1989
Copy link
Contributor

@dongjiang1989 dongjiang1989 commented Feb 5, 2024

Description

This PR fix url path splicing bug.

endpoints api url: /api/v1/namespaces/{namespace}/endpoints/{name}

ref: https://docs.openshift.com/container-platform/4.8/rest_api/network_apis/endpoints-core-v1.html#apiv1namespacesnamespaceendpointsname

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@shreemaan-abhishek
Copy link
Contributor

@dongjiang1989 please explain your bugfix, why is it required and also add test cases. Thanks.

@dongjiang1989
Copy link
Contributor Author

dongjiang1989 commented Feb 6, 2024

@dongjiang1989 please explain your bugfix, why is it required and also add test cases. Thanks.

This is url path splicing bug.

endpoints api url: /api/v1/namespaces/{namespace}/endpoints/{name}
ref: https://docs.openshift.com/container-platform/4.8/rest_api/network_apis/endpoints-core-v1.html#apiv1namespacesnamespaceendpointsname

@monkeyDluffy6017
Copy link
Contributor

Could you add test cases to cover this?

@monkeyDluffy6017
Copy link
Contributor

@dongjiang1989
Copy link
Contributor Author

@@ -355,7 +355,7 @@ function _M.new(group, version, kind, plural, namespace)
end

if namespace and namespace ~= "" then
path = path .. "/namespace/" .. namespace
path = path .. "/namespaces/" .. namespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you made the same change in another PR? #10916

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... Just split PR into bugfix and feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this change if it is not needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay my bad, it seems this is not needed in the newer PR.

@@ -99,6 +99,21 @@ _EOC_
$block->set_value("main_config", $main_config);

my $config = $block->config // <<_EOC_;
location /informer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case doesn't make sense. It is difficult to understand what problem this PR fixes (although from the link that you shared, it appears that the url is incorrect).. so in theory... namespace based queries should fail (given the path is incorrect)...

can you show in a test case that namespace related queries pass now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. It's difficult to verify in e2e case. Is there an example of unittest case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familar with this plugin, could you explain why the url you changed has anything to do with the document you are referencing?
We can ignore the test cases If they are too difficult

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fix Informer_factory.path splicing problem

@shreemaan-abhishek
Copy link
Contributor

If possible, please also provide some reproduction steps to show how the current state leads to a bug/failure. Thanks.

@monkeyDluffy6017
Copy link
Contributor

@zhixiongdu027 Could you help to review this pr?

Comment on lines 770 to 789
=== TEST 12: parse informer_factory information
--- yaml_config eval: $::yaml_config
--- request eval
[

"GET /queries
[
\"first/ns-a/ep:p1\",\"first/ns-a/ep:p2\",
\"second/ns-a/ep:p1\",\"second/ns-a/ep:p2\"
]",

"GET /informer
[]"

]
--- response_body eval
[
"{ 0 0 0 0 }\n",
"{ 0 }\n",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case seems meanless?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, I struggle to make any sense out of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.
The test case should indicate that using a namespace based informator can properly watch objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it.

local informer_factory = require("apisix.discovery.kubernetes.informer_factory")
ngx.sleep(1)
local response_body = "{"
local informer, err = informer_factory.new("", "v1", "Endpoints", "endpoints", "default")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informer_factory.new only creates a table object and does not watch resources.

You should call list_watch to attempt to retrieve endpoints resources from apiserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case just testing Informer_factory.path. e2e case watch apiserver is difficult

Comment on lines 770 to 789
=== TEST 12: parse informer_factory information
--- yaml_config eval: $::yaml_config
--- request eval
[

"GET /queries
[
\"first/ns-a/ep:p1\",\"first/ns-a/ep:p2\",
\"second/ns-a/ep:p1\",\"second/ns-a/ep:p2\"
]",

"GET /informer
[]"

]
--- response_body eval
[
"{ 0 0 0 0 }\n",
"{ 0 }\n",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.
The test case should indicate that using a namespace based informator can properly watch objects.

@dongjiang1989
Copy link
Contributor Author

ignore e2e test case

@monkeyDluffy6017 monkeyDluffy6017 changed the title fix: fix namespaces in informer factory fix: wrong namespace related endpoint in k8s Feb 22, 2024
@monkeyDluffy6017
Copy link
Contributor

It's a very little typo, @AlinsRan and i have checked twice, so i think missing test cases is ok

@monkeyDluffy6017 monkeyDluffy6017 merged commit 72f6364 into apache:master Feb 22, 2024
85 of 89 checks passed
@dongjiang1989 dongjiang1989 deleted the fixbug branch February 22, 2024 16:16
@caibirdme
Copy link

A little weird I want to say, does this mean that before this pr being merged, the apisix k8s discovery function is always broken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants