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

Add linting for redefined builtin ids #4513

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ linters-settings:
- name: indent-error-flow
- name: unreachable-code
- name: var-naming
- name: redefines-builtin-id
Copy link
Member

Choose a reason for hiding this comment

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

Hi, @Affan-7 , To avoid multiple PR conflicts, you can add this and fix it locally. The modifications here will be submitted together in the end.

Copy link
Member

Choose a reason for hiding this comment

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

I just rebased this PR.

staticcheck:
checks:
- all
Expand Down
20 changes: 10 additions & 10 deletions pkg/util/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ func ConvertToClusterNames(clusters []workv1alpha2.TargetCluster) sets.Set[strin
}

// MergeTargetClusters will merge the replicas in two TargetCluster
func MergeTargetClusters(old, new []workv1alpha2.TargetCluster) []workv1alpha2.TargetCluster {
func MergeTargetClusters(oldCluster, newCluster []workv1alpha2.TargetCluster) []workv1alpha2.TargetCluster {
switch {
case len(old) == 0:
return new
case len(new) == 0:
return old
case len(oldCluster) == 0:
return newCluster
case len(newCluster) == 0:
return oldCluster
}
// oldMap is a map of the result for the old replicas so that it can be merged with the new result easily
oldMap := make(map[string]int32)
for _, cluster := range old {
for _, cluster := range oldCluster {
oldMap[cluster.Name] = cluster.Replicas
}
// merge the new replicas and the data of old replicas
for i, cluster := range new {
for i, cluster := range newCluster {
value, ok := oldMap[cluster.Name]
if ok {
new[i].Replicas = cluster.Replicas + value
newCluster[i].Replicas = cluster.Replicas + value
delete(oldMap, cluster.Name)
}
}
for key, value := range oldMap {
new = append(new, workv1alpha2.TargetCluster{Name: key, Replicas: value})
newCluster = append(newCluster, workv1alpha2.TargetCluster{Name: key, Replicas: value})
}
return new
return newCluster
}