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

Change controller-runtime List option from MatchingFields to ListOpti… #6958

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

blackpiglet
Copy link
Contributor

@blackpiglet blackpiglet commented Oct 15, 2023

…ons.

Thank you for contributing to Velero!

Please add a summary of your change

Does your change fix a particular issue?

Fixes #5156

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

@codecov
Copy link

codecov bot commented Oct 15, 2023

Codecov Report

Merging #6958 (79c7571) into main (fd8350f) will increase coverage by 0.01%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #6958      +/-   ##
==========================================
+ Coverage   61.05%   61.06%   +0.01%     
==========================================
  Files         251      251              
  Lines       26845    26855      +10     
==========================================
+ Hits        16389    16399      +10     
  Misses       9303     9303              
  Partials     1153     1153              
Files Coverage Δ
pkg/cmd/cli/nodeagent/server.go 8.86% <0.00%> (ø)
pkg/cmd/server/server.go 23.17% <85.71%> (+0.99%) ⬆️

@@ -419,7 +419,7 @@ func (s *nodeAgentServer) markDataDownloadsCancel(r *controller.DataDownloadReco

func (s *nodeAgentServer) markInProgressPVBsFailed(client ctrlclient.Client) {
pvbs := &velerov1api.PodVolumeBackupList{}
if err := client.List(s.ctx, pvbs, &ctrlclient.MatchingFields{"metadata.namespace": s.namespace}); err != nil {
if err := client.List(s.ctx, pvbs, &ctrlclient.ListOptions{Namespace: s.namespace}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you think , use ctrlclient.ListOptions{ instead of ctrlclient.MatchingFields{ can do anything better?

Like the docs note client#hdr-Indexing , ctrlclient.MatchingFields will better than ctrlclient.ListOptions{ when it is used in index condition.

Copy link
Contributor Author

@blackpiglet blackpiglet Oct 20, 2023

Choose a reason for hiding this comment

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

This is used to address the error reported in the Velero with a limited permission scenario.

time="2023-10-09T23:56:44Z" level=error msg="failed to list backups" error="backups.velero.io is forbidden: User \"system:serviceaccount:arthur:velero-server\
" cannot list resource \"backups\" in API group \"velero.io\" at the cluster scope" error.file="/go/src/github.com/vmware-tanzu/velero/pkg/cmd/server/server.g
o:954" error.function=github.com/vmware-tanzu/velero/pkg/cmd/server.markInProgressBackupsFailed logSource="pkg/cmd/server/server.go:954"

I suppose this error is reported, instead of reading from cached, is due to the namespaced cache was not created before use.
https://github.com/kubernetes-sigs/controller-runtime/blob/15d79283523517f52ee30b28d2ae4c1ea3f113da/pkg/cache/cache_test.go#L1928-L1956

Copy link
Contributor

Choose a reason for hiding this comment

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

is forbidden: User \"system:serviceaccount:arthur:velero-server , I'm afraid cache have or have not , may not the error's root cause.😀😀

Copy link
Contributor Author

@blackpiglet blackpiglet Oct 20, 2023

Choose a reason for hiding this comment

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

It's related to the limited permission scenario.
Because the query parameter already has the namespace, I didn't expect the query to be in the cluster scope.
I'm not sure that MatchingFields will definitely query resources in the whole cluster or query according to the parameter setting.
ListOptions doesn't have the error-reported issue.

@blackpiglet blackpiglet merged commit d336e28 into vmware-tanzu:main Nov 27, 2023
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.

Backup requires cluster scope to succeed, even when installed without clusterAdministrator
5 participants