-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
fixed using reference to loop iterator #105433
fixed using reference to loop iterator #105433
Conversation
@shivanshu1333: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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/test-infra repository. |
/test pull-kubernetes-node-e2e-containerd |
/kind cleanup |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aojea, shivanshu1333 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 |
/hold kubernetes/test/e2e/framework/deployment/fixtures.go Lines 153 to 159 in 123864a
and kubernetes/test/e2e/framework/deployment/fixtures.go Lines 129 to 135 in 123864a
|
/lgtm cancel |
Missed it previously, my bad |
for _, pod := range allPods.Items { | ||
controllerRef := metav1.GetControllerOf(&pod) | ||
for i, pod := range allPods.Items { | ||
controllerRef := metav1.GetControllerOf(&allPods.Items[i]) | ||
if controllerRef != nil && controllerRef.UID == replicaSetUID { | ||
ownedPods.Items = append(ownedPods.Items, pod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the same pattern everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
for _, rs := range ownedReplicaSets { | ||
if !podTemplatesEqualsIgnoringHash(&rs.Spec.Template, &deployment.Spec.Template) { | ||
for i, rs := range ownedReplicaSets { | ||
if !podTemplatesEqualsIgnoringHash(&ownedReplicaSets[i].Spec.Template, &deployment.Spec.Template) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the same patter in line 134?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line number 134 since we're not passing the address of rs, we can use both rs and ownedReplicaSets[i].
The current code is more readable and it also highlights the reason behind why we are explicitly passing &ownedReplicaSets[i]
instead of &rs
@aojea if you think we still need to make the changes to the above review comments, kindly let me know. As far as I understand we can probably keep it like that. |
it is ok, but better if you can squash the commits |
using label to squash |
/lgtm |
/hold cancel |
/retest |
* fixed using reference to loop iterator * fixed other for loops
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Current code incorrectly uses for loop and passes wrong value as reference
Guide to refer https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable
Which issue(s) this PR fixes:
Fixes #105427
Special notes for your reviewer:
Please refer to sample code to understand the bug https://goplay.space/#TIT_IZEAEud
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: