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

fixed using reference to loop iterator #105433

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions test/e2e/framework/deployment/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func GetPodsForDeployment(client clientset.Interface, deployment *appsv1.Deploym
}

ownedReplicaSets := make([]*appsv1.ReplicaSet, 0, len(allReplicaSets.Items))
for _, rs := range allReplicaSets.Items {
if !metav1.IsControlledBy(&rs, deployment) {
for i := range allReplicaSets.Items {
if !metav1.IsControlledBy(&allReplicaSets.Items[i], deployment) {
continue
}

ownedReplicaSets = append(ownedReplicaSets, &rs)
ownedReplicaSets = append(ownedReplicaSets, &allReplicaSets.Items[i])
}

// We ignore pod-template-hash because:
Expand All @@ -126,8 +126,8 @@ func GetPodsForDeployment(client clientset.Interface, deployment *appsv1.Deploym
// see https://github.com/kubernetes/kubernetes/issues/40415
// We deterministically choose the oldest new ReplicaSet.
sort.Sort(replicaSetsByCreationTimestamp(ownedReplicaSets))
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) {
Copy link
Member

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?

Copy link
Contributor Author

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

continue
}

Expand All @@ -151,8 +151,8 @@ func GetPodsForDeployment(client clientset.Interface, deployment *appsv1.Deploym

replicaSetUID := replicaSet.UID
ownedPods := &v1.PodList{Items: make([]v1.Pod, 0, len(allPods.Items))}
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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

}
Expand Down