Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit a4b6704

Browse files
committed
Fix Go 1.22 linting issues
Signed-off-by: Dale Haiducek <[email protected]>
1 parent 923093c commit a4b6704

File tree

16 files changed

+16
-27
lines changed

16 files changed

+16
-27
lines changed

pkg/controller/appsubsummary/appsubsummary_controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ func (r *ReconcileAppSubSummary) cleanManagedClusterViewPerApp(appsubName, appsu
286286
continue
287287
}
288288

289-
// reassign the iteration variable inside the loop to avoid the sonarcloud warning - "Implicit memory aliasing in for loop"
290-
managedClusterView := managedClusterView
291-
292289
if err = r.Delete(context.TODO(), &managedClusterView); err != nil {
293290
klog.Errorf("Error deleting managedClusterView :%v/%v, err:%v", managedClusterView.Namespace, managedClusterView.Name, err)
294291
}

pkg/controller/mcmhub/ansiblejob.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
7373

7474
klog.Infof("total prehook/posthook ansible jobs num: %v", len(ansibleJobList.Items))
7575

76-
for i := 0; i < len(ansibleJobList.Items); i++ {
77-
hostingAppsub, ok := ansibleJobList.Items[i].Annotations[subv1.AnnotationHosting]
76+
for _, ansibleJob := range ansibleJobList.Items {
77+
hostingAppsub, ok := ansibleJob.Annotations[subv1.AnnotationHosting]
7878

7979
if !ok {
8080
continue
@@ -84,7 +84,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
8484
continue
8585
}
8686

87-
curHookType, ok := ansibleJobList.Items[i].Annotations[subv1.AnnotationHookType]
87+
curHookType, ok := ansibleJob.Annotations[subv1.AnnotationHookType]
8888

8989
if !ok {
9090
continue
@@ -94,7 +94,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
9494
continue
9595
}
9696

97-
hookTpl, ok := ansibleJobList.Items[i].Annotations[subv1.AnnotationHookTemplate]
97+
hookTpl, ok := ansibleJob.Annotations[subv1.AnnotationHookTemplate]
9898

9999
if !ok {
100100
continue
@@ -104,7 +104,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
104104
continue
105105
}
106106

107-
lastAnsibleJob := ansibleJobList.Items[i].DeepCopy()
107+
lastAnsibleJob := ansibleJob.DeepCopy()
108108

109109
klog.Infof("last ansible job: %v/%v, hookType: %v, hookTemplate: %v", lastAnsibleJob.Namespace, lastAnsibleJob.Name, hookType, jobKey.String())
110110

pkg/controller/mcmhub/gitrepo_sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func (r *ReconcileSubscription) subscribeKustomizations(sub *appv1.Subscription,
263263
for _, kustomizeDir := range kustomizeDirs {
264264
klog.Info("Applying kustomization ", kustomizeDir)
265265

266+
//nolint:copyloopvar
266267
relativePath := kustomizeDir
267268

268269
if len(strings.SplitAfter(kustomizeDir, baseDir+"/")) > 1 {

pkg/controller/mcmhub/propagate_manifestwork.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ func (r *ReconcileSubscription) setLocalManifestWork(cluster ManageClusters, hos
277277
},
278278
}
279279

280-
for i := 0; i < len(localManifestWork.Spec.Workload.Manifests); i++ {
281-
klog.V(1).Infof("workload manifest: %#v", string(localManifestWork.Spec.Workload.Manifests[i].Raw))
280+
for _, manifest := range localManifestWork.Spec.Workload.Manifests {
281+
klog.V(1).Infof("workload manifest: %#v", string(manifest.Raw))
282282
}
283283

284284
return localManifestWork, nil

pkg/placementrule/controller/placementrule/placementdecision.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ func (r *ReconcilePlacementRuleStatus) syncPlacementDecisions(ctx context.Contex
122122
continue
123123
}
124124

125-
placementDecision := placementDecision
126-
127125
err := r.Delete(ctx, &placementDecision)
128126
if errors.IsNotFound(err) {
129127
continue

pkg/placementrule/utils/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func IfClusterAdmin(user string, groups []string) bool {
169169
}
170170

171171
for _, group := range groups {
172+
//nolint:copyloopvar
172173
newGroup := group
173174

174175
gg := strings.Split(group, ":")

pkg/placementrule/utils/eventlog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecord
8484
// RecordEvent - record kuberentes event
8585
func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error) {
8686
eventType := corev1.EventTypeNormal
87-
evnetMsg := msg
87+
eventMsg := msg
8888

8989
if err != nil {
9090
eventType = corev1.EventTypeWarning
9191
}
9292

93-
rec.EventRecorder.Event(obj, eventType, reason, evnetMsg)
93+
rec.EventRecorder.Event(obj, eventType, reason, eventMsg)
9494
}

pkg/subscriber/git/git_subscriber_item.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ func (ghsi *SubscriberItem) subscribeKustomizations() error {
454454
for _, kustomizeDir := range ghsi.kustomizeDirs {
455455
klog.Info("Applying kustomization ", kustomizeDir)
456456

457+
//nolint:copyloopvar
457458
relativePath := kustomizeDir
458459

459460
if len(strings.SplitAfter(kustomizeDir, ghsi.repoRoot+"/")) > 1 {

pkg/subscriber/objectbucket/objectbucket_subscriber_item.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ func (obsi *SubscriberItem) doSubscription() {
372372
var doErr error
373373

374374
for _, tpl := range tpls {
375-
tpl := tpl
376375
resource, err := obsi.doSubscribeManifest(&tpl) // this is now the address of the inner tpl
377376

378377
if err != nil {

pkg/synchronizer/kubernetes/sync_server.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ func cleanup(synchronizer *KubeSynchronizer) {
246246

247247
if appsubStatusList != nil && len(appsubStatusList.Items) > 0 {
248248
for _, appsubStatus := range appsubStatusList.Items {
249-
appsubStatus := appsubStatus
250-
251249
appsub := &appv1.Subscription{}
252250

253251
nsn := types.NamespacedName{Namespace: appsubStatus.Namespace, Name: appsubStatus.Name}

pkg/synchronizer/kubernetes/synchronizer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ func (sync *KubeSynchronizer) ProcessSubResources(appsub *appv1alpha1.Subscripti
279279
for _, resource := range resources {
280280
appSubUnitStatus := SubscriptionUnitStatus{}
281281

282-
resource := resource
283-
284282
template, err := sync.OverrideResource(hostSub, &resource)
285283

286284
if err != nil {

pkg/utils/eventlog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecord
8484
// RecordEvent - record kuberentes event
8585
func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error) {
8686
eventType := corev1.EventTypeNormal
87-
evnetMsg := msg
87+
eventMsg := msg
8888

8989
if err != nil {
9090
eventType = corev1.EventTypeWarning
9191
}
9292

93-
rec.EventRecorder.Event(obj, eventType, reason, evnetMsg)
93+
rec.EventRecorder.Event(obj, eventType, reason, eventMsg)
9494
}

pkg/utils/helmrepo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ func DeleteHelmReleaseCRD(runtimeClient client.Client, crdx *clientsetx.Clientse
679679
os.Exit(0)
680680
} else {
681681
for _, hr := range hrlist.Items {
682-
hr := hr
683682
klog.V(1).Infof("Found %s", hr.SelfLink)
684683
// remove all finalizers
685684
hr = *hr.DeepCopy()

pkg/utils/subscription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ func CompareManifestWork(oldManifestWork, newManifestWork *manifestWorkV1.Manife
10701070
return false
10711071
}
10721072

1073-
for i := 0; i < len(oldManifestWork.Spec.Workload.Manifests); i++ {
1073+
for i := range oldManifestWork.Spec.Workload.Manifests {
10741074
oldManifest := &unstructured.Unstructured{}
10751075
newManifest := &unstructured.Unstructured{}
10761076

pkg/utils/subscription_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ func TestIsEqaulSubscriptionStatus(t *testing.T) {
642642
}
643643

644644
for _, tt := range tests {
645-
tt := tt
646645
t.Run(tt.name, func(t *testing.T) {
647646
actual := isEqualSubscriptionStatus(tt.givena, tt.givenb)
648647

@@ -666,7 +665,6 @@ func TestIsEmptySubscriptionStatus(t *testing.T) {
666665
}
667666

668667
for _, tt := range tests {
669-
tt := tt
670668
t.Run(tt.name, func(t *testing.T) {
671669
actual := isEmptySubscriptionStatus(tt.given)
672670
if actual != tt.expected {
@@ -945,7 +943,6 @@ func TestIsSubscriptionBasicChanged(t *testing.T) {
945943
}
946944

947945
for _, tt := range tests {
948-
tt := tt
949946
t.Run(tt.name, func(t *testing.T) {
950947
actual := IsSubscriptionBasicChanged(tt.oldIns, tt.newIns)
951948
if actual != tt.expected {

pkg/utils/timewindow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ func assertHourRangesInTime(t *testing.T, got, wanted []hourRangesInTime) {
420420
t.Fatalf("validateHourRange length is wrong, got %v, wanted %v", len(got), len(wanted))
421421
}
422422

423-
for i := 0; i < len(got); i++ {
423+
for i := range got {
424424
if got[i].start.Equal(wanted[i].start) == false {
425425
t.Errorf("item idx %v got %v, wanted %v", i, got[i].start.String(), wanted[i].start.String())
426426
}

0 commit comments

Comments
 (0)