Skip to content

Commit 2186c13

Browse files
authored
fix: go modernize doesn't work (#6262)
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 0f69833 commit 2186c13

File tree

7 files changed

+10
-64
lines changed

7 files changed

+10
-64
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ replace (
326326
)
327327

328328
tool (
329-
github.com/kubeovn/kube-ovn/tools/modernize
330329
github.com/onsi/ginkgo/v2/ginkgo
331330
github.com/ovn-kubernetes/libovsdb/cmd/modelgen
332331
go.uber.org/mock/mockgen

makefiles/build.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ifeq ($(strip $(GO_MOD_VERSION)),)
1515
$(error failed to determine Go version from go.mod)
1616
endif
1717
GOTOOLCHAIN_VERSION := go$(GO_MOD_VERSION)
18-
MODERNIZE_ENV := GOTOOLCHAIN=$(GOTOOLCHAIN_VERSION)
18+
MODERNIZE_EXCLUDE := github.com/kubeovn/kube-ovn/mocks|github.com/kubeovn/kube-ovn/pkg/apis/kubeovn|github.com/kubeovn/kube-ovn/pkg/client
1919

2020
.PHONY: build-go
2121
build-go:
@@ -148,11 +148,11 @@ lint:
148148
ifeq ($(CI),true)
149149
@echo "Running in GitHub Actions"
150150
golangci-lint run -v
151-
$(MODERNIZE_ENV) go tool github.com/kubeovn/kube-ovn/tools/modernize -test -skipgenerated ./...
151+
go list ./... | grep -vE '$(MODERNIZE_EXCLUDE)' | xargs go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test
152152
else
153153
@echo "Running in local environment"
154154
golangci-lint run -v --fix
155-
$(MODERNIZE_ENV) go tool github.com/kubeovn/kube-ovn/tools/modernize -test -skipgenerated -fix ./...
155+
go list ./... | grep -vE '$(MODERNIZE_EXCLUDE)' | xargs go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test -fix
156156
endif
157157

158158
.PHONY: scan

pkg/controller/vpc_nat_gateway.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"maps"
89
"os"
910
"reflect"
1011
"regexp"
@@ -1200,9 +1201,7 @@ func (c *Controller) updateCrdNatGwLabels(key, qos string) error {
12001201

12011202
// Create a new labels map to avoid modifying the informer cache
12021203
labels := make(map[string]string, len(oriGw.Labels)+3)
1203-
for k, v := range oriGw.Labels {
1204-
labels[k] = v
1205-
}
1204+
maps.Copy(labels, oriGw.Labels)
12061205

12071206
// vpc nat gw label may lost
12081207
if len(oriGw.Labels) == 0 {

pkg/speaker/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func (config *Configuration) initBgpServer() error {
400400
// It retries up to addPeerMaxRetries times with addPeerRetryInterval between attempts.
401401
func addPeerWithRetry(s *gobgp.BgpServer, peer *api.Peer) error {
402402
var err error
403-
for i := 0; i < addPeerMaxRetries; i++ {
403+
for i := range addPeerMaxRetries {
404404
if err = s.AddPeer(context.Background(), &api.AddPeerRequest{
405405
Peer: peer,
406406
}); err == nil {

pkg/util/vpc_nat_gateway.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package util
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"strings"
78

89
nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
@@ -75,9 +76,7 @@ func GenNatGwPodAnnotations(userAnnotations map[string]string, gw *kubeovnv1.Vpc
7576

7677
// Create a new map to avoid modifying the input map (which may be from informer cache)
7778
result := make(map[string]string, len(userAnnotations)+5)
78-
for k, v := range userAnnotations {
79-
result[k] = v
80-
}
79+
maps.Copy(result, userAnnotations)
8180

8281
// Set system annotations (overwrites any conflicting user annotations)
8382
result[nadv1.NetworkAttachmentAnnot] = attachedNetworks

test/e2e/iptables-eip-qos/e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ func createNatGwAndSetQosCases(f *framework.Framework,
10051005
// Returns slice of bandwidth values in bits per second
10061006
func parseBandwidthFromIperfOutput(text string) []float64 {
10071007
var bandwidths []float64
1008-
lines := strings.Split(text, "\n")
1009-
for _, line := range lines {
1008+
lines := strings.SplitSeq(text, "\n")
1009+
for line := range lines {
10101010
if line == "" {
10111011
continue
10121012
}

tools/modernize/modernize.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)