Skip to content

fix: wrong namespace related endpoint in k8s#10917

Merged
juststillthinking merged 1 commit into
apache:masterfrom
dongjiang1989:fixbug
Feb 22, 2024
Merged

fix: wrong namespace related endpoint in k8s#10917
juststillthinking merged 1 commit into
apache:masterfrom
dongjiang1989:fixbug

Conversation

@dongjiang1989

@dongjiang1989 dongjiang1989 commented Feb 5, 2024

Copy link
Copy Markdown
Contributor

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)

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

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

@dongjiang1989

dongjiang1989 commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

@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

@juststillthinking

Copy link
Copy Markdown
Contributor

Could you add test cases to cover this?

@juststillthinking

Copy link
Copy Markdown
Contributor

@dongjiang1989

Copy link
Copy Markdown
Contributor Author


if namespace and namespace ~= "" then
path = path .. "/namespace/" .. namespace
path = path .. "/namespaces/" .. namespace

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread t/kubernetes/discovery/kubernetes2.t Outdated
$block->set_value("main_config", $main_config);

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@juststillthinking

Copy link
Copy Markdown
Contributor

@zhixiongdu027 Could you help to review this pr?

Comment thread t/kubernetes/discovery/kubernetes2.t Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread t/kubernetes/discovery/kubernetes2.t Outdated
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
Copy Markdown
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
Copy Markdown
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 thread t/kubernetes/discovery/kubernetes2.t Outdated
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
Copy Markdown
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
Copy Markdown
Contributor Author

ignore e2e test case

@juststillthinking juststillthinking changed the title fix: fix namespaces in informer factory fix: wrong namespace related endpoint in k8s Feb 22, 2024
@juststillthinking

Copy link
Copy Markdown
Contributor

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

@juststillthinking
juststillthinking merged commit 72f6364 into apache:master Feb 22, 2024
@dongjiang1989
dongjiang1989 deleted the fixbug branch February 22, 2024 16:16
@caibirdme

Copy link
Copy Markdown

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