Skip to content

Commit

Permalink
Upgrade to Go 1.22 (#415)
Browse files Browse the repository at this point in the history
* Upgrade to Go 1.22

Signed-off-by: Dale Haiducek <[email protected]>

* Fix Go 1.22 linting issues

Signed-off-by: Dale Haiducek <[email protected]>

---------

Signed-off-by: Dale Haiducek <[email protected]>
  • Loading branch information
dhaiducek authored Dec 11, 2024
1 parent 5e1eee9 commit d284803
Show file tree
Hide file tree
Showing 23 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-postsubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# Common versions
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''
GOPATH: '/home/runner/work/multicloud-operators-subscription/multicloud-operators-subscription/go'
defaults:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# Common versions
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''
GOPATH: '/home/runner/work/multicloud-operators-subscription/multicloud-operators-subscription/go'
defaults:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*.*.*'
env:
# Common versions
GO_VERSION: '1.21'
GO_VERSION: '1.22'
GO_REQUIRED_MIN_VERSION: ''
GOPATH: '/home/runner/work/multicloud-operators-subscription/multicloud-operators-subscription/go'
GITHUB_REF: ${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.21-linux AS plugin-builder
FROM registry.ci.openshift.org/stolostron/builder:go1.22-linux AS plugin-builder
ENV POLICY_GENERATOR_TAG=v1.16.0

WORKDIR /go/src/github.com/open-cluster-management/multicloud-operators-subscription
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.prow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.21-linux AS builder
FROM registry.ci.openshift.org/stolostron/builder:go1.22-linux AS builder
ENV POLICY_GENERATOR_TAG=v1.16.0

WORKDIR /go/src/github.com/stolostron/multicluster-operators-subscription
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.rhtap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.21 AS plugin-builder
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_9_1.22 AS plugin-builder
ENV POLICY_GENERATOR_TAG=v1.16.0

WORKDIR /go/src/github.com/open-cluster-management/multicloud-operators-subscription
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module open-cluster-management.io/multicloud-operators-subscription

go 1.21
go 1.22.10

require (
github.com/Masterminds/semver/v3 v3.2.1
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/appsubsummary/appsubsummary_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ func (r *ReconcileAppSubSummary) cleanManagedClusterViewPerApp(appsubName, appsu
continue
}

// reassign the iteration variable inside the loop to avoid the sonarcloud warning - "Implicit memory aliasing in for loop"
managedClusterView := managedClusterView

if err = r.Delete(context.TODO(), &managedClusterView); err != nil {
klog.Errorf("Error deleting managedClusterView :%v/%v, err:%v", managedClusterView.Namespace, managedClusterView.Name, err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/mcmhub/ansiblejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType

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

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

if !ok {
continue
Expand All @@ -84,7 +84,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
continue
}

curHookType, ok := ansibleJobList.Items[i].Annotations[subv1.AnnotationHookType]
curHookType, ok := ansibleJob.Annotations[subv1.AnnotationHookType]

if !ok {
continue
Expand All @@ -94,7 +94,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
continue
}

hookTpl, ok := ansibleJobList.Items[i].Annotations[subv1.AnnotationHookTemplate]
hookTpl, ok := ansibleJob.Annotations[subv1.AnnotationHookTemplate]

if !ok {
continue
Expand All @@ -104,7 +104,7 @@ func findLastAnsibleJob(clt client.Client, subIns *subv1.Subscription, hookType
continue
}

lastAnsibleJob := ansibleJobList.Items[i].DeepCopy()
lastAnsibleJob := ansibleJob.DeepCopy()

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

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/mcmhub/gitrepo_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (r *ReconcileSubscription) subscribeKustomizations(sub *appv1.Subscription,
for _, kustomizeDir := range kustomizeDirs {
klog.Info("Applying kustomization ", kustomizeDir)

//nolint:copyloopvar
relativePath := kustomizeDir

if len(strings.SplitAfter(kustomizeDir, baseDir+"/")) > 1 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/mcmhub/propagate_manifestwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ func (r *ReconcileSubscription) setLocalManifestWork(cluster ManageClusters, hos
},
}

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

return localManifestWork, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (r *ReconcilePlacementRuleStatus) syncPlacementDecisions(ctx context.Contex
continue
}

placementDecision := placementDecision

err := r.Delete(ctx, &placementDecision)
if errors.IsNotFound(err) {
continue
Expand Down
1 change: 1 addition & 0 deletions pkg/placementrule/utils/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func IfClusterAdmin(user string, groups []string) bool {
}

for _, group := range groups {
//nolint:copyloopvar
newGroup := group

gg := strings.Split(group, ":")
Expand Down
4 changes: 2 additions & 2 deletions pkg/placementrule/utils/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecord
// RecordEvent - record kuberentes event
func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error) {
eventType := corev1.EventTypeNormal
evnetMsg := msg
eventMsg := msg

if err != nil {
eventType = corev1.EventTypeWarning
}

rec.EventRecorder.Event(obj, eventType, reason, evnetMsg)
rec.EventRecorder.Event(obj, eventType, reason, eventMsg)
}
1 change: 1 addition & 0 deletions pkg/subscriber/git/git_subscriber_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func (ghsi *SubscriberItem) subscribeKustomizations() error {
for _, kustomizeDir := range ghsi.kustomizeDirs {
klog.Info("Applying kustomization ", kustomizeDir)

//nolint:copyloopvar
relativePath := kustomizeDir

if len(strings.SplitAfter(kustomizeDir, ghsi.repoRoot+"/")) > 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ func (obsi *SubscriberItem) doSubscription() {
var doErr error

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

if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/synchronizer/kubernetes/sync_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ func cleanup(synchronizer *KubeSynchronizer) {

if appsubStatusList != nil && len(appsubStatusList.Items) > 0 {
for _, appsubStatus := range appsubStatusList.Items {
appsubStatus := appsubStatus

appsub := &appv1.Subscription{}

nsn := types.NamespacedName{Namespace: appsubStatus.Namespace, Name: appsubStatus.Name}
Expand Down
2 changes: 0 additions & 2 deletions pkg/synchronizer/kubernetes/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ func (sync *KubeSynchronizer) ProcessSubResources(appsub *appv1alpha1.Subscripti
for _, resource := range resources {
appSubUnitStatus := SubscriptionUnitStatus{}

resource := resource

template, err := sync.OverrideResource(hostSub, &resource)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func NewEventRecorder(cfg *rest.Config, scheme *apiruntime.Scheme) (*EventRecord
// RecordEvent - record kuberentes event
func (rec *EventRecorder) RecordEvent(obj apiruntime.Object, reason, msg string, err error) {
eventType := corev1.EventTypeNormal
evnetMsg := msg
eventMsg := msg

if err != nil {
eventType = corev1.EventTypeWarning
}

rec.EventRecorder.Event(obj, eventType, reason, evnetMsg)
rec.EventRecorder.Event(obj, eventType, reason, eventMsg)
}
1 change: 0 additions & 1 deletion pkg/utils/helmrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ func DeleteHelmReleaseCRD(runtimeClient client.Client, crdx *clientsetx.Clientse
os.Exit(0)
} else {
for _, hr := range hrlist.Items {
hr := hr
klog.V(1).Infof("Found %s", hr.SelfLink)
// remove all finalizers
hr = *hr.DeepCopy()
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ func CompareManifestWork(oldManifestWork, newManifestWork *manifestWorkV1.Manife
return false
}

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

Expand Down
3 changes: 0 additions & 3 deletions pkg/utils/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ func TestIsEqaulSubscriptionStatus(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
actual := isEqualSubscriptionStatus(tt.givena, tt.givenb)

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

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
actual := isEmptySubscriptionStatus(tt.given)
if actual != tt.expected {
Expand Down Expand Up @@ -945,7 +943,6 @@ func TestIsSubscriptionBasicChanged(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
actual := IsSubscriptionBasicChanged(tt.oldIns, tt.newIns)
if actual != tt.expected {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/timewindow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func assertHourRangesInTime(t *testing.T, got, wanted []hourRangesInTime) {
t.Fatalf("validateHourRange length is wrong, got %v, wanted %v", len(got), len(wanted))
}

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

0 comments on commit d284803

Please sign in to comment.