Skip to content

⚠️ Change ClusterResourceSetBinding Bindings field from []*ResourceSetBinding to []ResourceSetBinding #12476

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

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

sbueringer
Copy link
Member

Signed-off-by: Stefan Büringer buringerst@vmware.com

What this PR does / why we need it:
One of the more interesting conversion PRs..

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #10852

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 10, 2025
@k8s-ci-robot k8s-ci-robot requested review from chrischdi and elmiko July 10, 2025 12:42
@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-main

@sbueringer
Copy link
Member Author

@sbueringer sbueringer added the area/clusterresourceset Issues or PRs related to clusterresourcesets label Jul 10, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-area PR is missing an area label label Jul 10, 2025
@sbueringer sbueringer changed the title ⚠️ Change ClusterResourceSetBinding Bindings field from []*ResourceSetBinding to []ResourceSetBinding [WIP] ⚠️ Change ClusterResourceSetBinding Bindings field from []*ResourceSetBinding to []ResourceSetBinding Jul 10, 2025
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2025
@sbueringer sbueringer force-pushed the pr-fix-crb branch 2 times, most recently from a711313 to 55cf6dc Compare July 10, 2025 12:52
@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-main

@sbueringer sbueringer changed the title [WIP] ⚠️ Change ClusterResourceSetBinding Bindings field from []*ResourceSetBinding to []ResourceSetBinding ⚠️ Change ClusterResourceSetBinding Bindings field from []*ResourceSetBinding to []ResourceSetBinding Jul 10, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2025
[]*ResourceSetBinding to []ResourceSetBinding

Signed-off-by: Stefan Büringer buringerst@vmware.com
@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-main

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 10, 2025

@sbueringer: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main 71a7db1 link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member Author

/override pull-cluster-api-e2e-main

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Overrode contexts on behalf of sbueringer: pull-cluster-api-e2e-main

In response to this:

/override pull-cluster-api-e2e-main

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@JoelSpeed
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b972e176da7c4ea4cb7bc6ea93a35f42dabe55aa

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2025
@JoelSpeed
Copy link
Contributor

/hold do we want anyone else to check on this first?

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 11, 2025
Copy link
Member

@sivchari sivchari left a comment

Choose a reason for hiding this comment

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

/lgtm

I left nit, but if you decide to go with it, feel free to merge.

for _, binding := range c.Spec.Bindings {
if binding.ClusterResourceSetName == clusterResourceSet.Name {
return binding
for i := range c.Spec.Bindings {
Copy link
Member

Choose a reason for hiding this comment

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

I've read the discussion and commented.
I can confirm that the copyloopvar linter is already in place and the original code is fine.
but it's certainly a good idea to keep it this way in terms of visualization.

Copy link
Member Author

@sbueringer sbueringer Jul 11, 2025

Choose a reason for hiding this comment

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

The original code was not fine, that's why I changed it :) (tests broke)

The original code with the pointer change returned a copy of the binding and not the same binding that is part of the c.Spec.Bindings slice

The code is fine for the linter, but that doesn't mean it works as expected :)

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Surely the only this codes aren't problem, but considering about entire code base, the copy element might be invalid. This case is good example.
Thanks!

Copy link
Member Author

@sbueringer sbueringer Jul 11, 2025

Choose a reason for hiding this comment

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

To give some more context.

The previous problem (a few Go versions ago) with returning a pointer to a loop var was that the pointer was basically always referring to the last element that was stored in the loop var.

Then they changed it in go so a pointer to the loop var refers to the correct element.

But the loop var is a copy of the slice element not the actual element

c.Spec.Bindings = append(c.Spec.Bindings, binding)
return binding
return &c.Spec.Bindings[len(c.Spec.Bindings)-1]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return &c.Spec.Bindings[len(c.Spec.Bindings)-1]
return &binding

I think it's simpler but is this to make the format consistent with the above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Simpler but it's not necessarily correct. I'm sure about the case above, I'm not entirely sure if binding here is the same element as in the slice (probably both would work here in this case, but I want to play it safe)

@sbueringer
Copy link
Member Author

Fine to let Fabrizio review as well pre-merge

@fabriziopandini
Copy link
Member

/lgtm
Nice to get rid of this pointer in front of each element

@sbueringer
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 14, 2025
@k8s-ci-robot k8s-ci-robot merged commit 5256214 into kubernetes-sigs:main Jul 14, 2025
19 of 20 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.11 milestone Jul 14, 2025
@sbueringer sbueringer deleted the pr-fix-crb branch July 14, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/clusterresourceset Issues or PRs related to clusterresourcesets cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants