Skip to content

Commit 77cddfa

Browse files
committed
fix golang-lint.
1 parent 2d3315e commit 77cddfa

File tree

23 files changed

+77
-141
lines changed

23 files changed

+77
-141
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ jobs:
2121
docker-push:
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
25-
- uses: actions/setup-go@v3
24+
- uses: actions/checkout@v5
25+
- uses: actions/setup-go@v6
2626
with:
27-
go-version: "^1.18"
27+
go-version: "^1.25"
2828
- name: Set up QEMU
2929
uses: docker/setup-qemu-action@v1
3030

3131
- name: Set up Docker Buildx
3232
uses: docker/setup-buildx-action@v1
3333

3434
- name: Cache Docker layers
35-
uses: actions/cache@v2
35+
uses: actions/cache@v4
3636
with:
3737
path: /tmp/.buildx-cache
3838
key: ${{ runner.os }}-buildx-${{ github.sha }}
@@ -88,18 +88,18 @@ jobs:
8888
docker-push-ali-registry:
8989
runs-on: ubuntu-latest
9090
steps:
91-
- uses: actions/checkout@v3
92-
- uses: actions/setup-go@v3
91+
- uses: actions/checkout@v5
92+
- uses: actions/setup-go@v6
9393
with:
94-
go-version: "^1.18"
94+
go-version: "^1.25"
9595
- name: Set up QEMU
9696
uses: docker/setup-qemu-action@v1
9797

9898
- name: Set up Docker Buildx
9999
uses: docker/setup-buildx-action@v1
100100

101101
- name: Cache Docker layers
102-
uses: actions/cache@v2
102+
uses: actions/cache@v4
103103
with:
104104
path: /tmp/.buildx-cache
105105
key: ${{ runner.os }}-buildx-${{ github.sha }}
@@ -146,18 +146,18 @@ jobs:
146146
docker-push-github-registry:
147147
runs-on: ubuntu-latest
148148
steps:
149-
- uses: actions/checkout@v3
150-
- uses: actions/setup-go@v3
149+
- uses: actions/checkout@v5
150+
- uses: actions/setup-go@v6
151151
with:
152-
go-version: "^1.18"
152+
go-version: "^1.25"
153153
- name: Set up QEMU
154154
uses: docker/setup-qemu-action@v1
155155

156156
- name: Set up Docker Buildx
157157
uses: docker/setup-buildx-action@v1
158158

159159
- name: Cache Docker layers
160-
uses: actions/cache@v2
160+
uses: actions/cache@v4
161161
with:
162162
path: /tmp/.buildx-cache
163163
key: ${{ runner.os }}-buildx-${{ github.sha }}
@@ -169,6 +169,7 @@ jobs:
169169
sudo apt-get update -y
170170
sudo apt-get install -y ipset
171171
sudo apt-get install -y iptables
172+
sudo go version
172173
sudo go test -v -short ./pkg/... ./cmd/...
173174
174175
- name: Docker meta

.github/workflows/check.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
go-mod:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v5
2020
- name: Set up Go
2121
uses: actions/setup-go@v2.1.3
2222
with:
23-
go-version: 1.18
24-
- uses: actions/cache@v2
23+
go-version: 1.25
24+
- uses: actions/cache@v4
2525
with:
2626
path: ~/go/pkg/mod
2727
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -37,22 +37,22 @@ jobs:
3737
name: lint
3838
runs-on: ubuntu-latest
3939
steps:
40-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v5
4141
- name: Set up Go
42-
uses: actions/setup-go@v3
42+
uses: actions/setup-go@v6
4343
with:
44-
go-version: 1.18
44+
go-version: 1.25
4545
- name: Run golangci-lint
46-
uses: golangci/golangci-lint-action@v3
46+
uses: golangci/golangci-lint-action@v9
4747
with:
48-
version: v1.51.2
49-
args: --timeout 300s --skip-dirs-use-default -v -E goconst -E gofmt -E ineffassign -E goimports -E revive -E misspell -E vet -E unused
48+
version: v2.6
49+
args: --timeout 300s
5050

5151
shellcheck:
5252
name: Shellcheck
5353
runs-on: ubuntu-latest
5454
steps:
55-
- uses: actions/checkout@v3
55+
- uses: actions/checkout@v5
5656
- name: Run ShellCheck
5757
uses: ludeeus/action-shellcheck@1.1.0
5858
env:
@@ -63,7 +63,7 @@ jobs:
6363
super-linter:
6464
runs-on: ubuntu-latest
6565
steps:
66-
- uses: actions/checkout@v3
66+
- uses: actions/checkout@v5
6767
- name: Lint Code Base
6868
uses: github/super-linter@v4.8.5
6969
env:

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
steps:
3838
- name: Checkout repository
39-
uses: actions/checkout@v3
39+
uses: actions/checkout@v5
4040

4141
- name: Initialize CodeQL
4242
uses: github/codeql-action/init@v2

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
release:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v5
1717
- name: Build Changelog
1818
id: github_release
1919
uses: mikepenz/release-changelog-builder-action@v1

.github/workflows/sync-charts.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-22.04
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818

1919
- name: Sync to openyurtio/charts Repo
2020
env:

cmd/agent/app/options/options.go

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import (
1414
v1 "k8s.io/api/core/v1"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/runtime"
17-
"k8s.io/apiserver/pkg/endpoints/discovery"
1817
restclient "k8s.io/client-go/rest"
19-
"k8s.io/client-go/restmapper"
2018
"k8s.io/client-go/tools/clientcmd"
2119
"k8s.io/klog/v2"
2220
ctrl "sigs.k8s.io/controller-runtime"
@@ -93,7 +91,7 @@ func (o *AgentOptions) Validate() error {
9391
return fmt.Errorf("mac prefix %s is nonstandard", o.MACPrefix)
9492
}
9593
}
96-
94+
9795
if o.SyncPeriod.Duration < time.Minute {
9896
o.SyncPeriod.Duration = time.Minute
9997
}
@@ -220,73 +218,6 @@ func newMgr(cfg *restclient.Config, metricsBindAddress, healthyProbeAddress stri
220218
return mgr, nil
221219
}
222220

223-
func getLegacyAPIGroupResource() *restmapper.APIGroupResources {
224-
return &restmapper.APIGroupResources{
225-
Group: metav1.APIGroup{
226-
Versions: []metav1.GroupVersionForDiscovery{{GroupVersion: "v1", Version: "v1"}},
227-
PreferredVersion: metav1.GroupVersionForDiscovery{GroupVersion: "v1", Version: "v1"},
228-
},
229-
VersionedResources: map[string][]metav1.APIResource{
230-
"v1": {
231-
{
232-
Name: "nodes",
233-
Namespaced: false,
234-
Kind: "Node",
235-
Verbs: metav1.Verbs{"create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"},
236-
ShortNames: []string{"no"},
237-
StorageVersionHash: discovery.StorageVersionHash("", "v1", "Node"),
238-
},
239-
{
240-
Name: "pods",
241-
Namespaced: true,
242-
Kind: "Pod",
243-
Verbs: metav1.Verbs{"create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"},
244-
ShortNames: []string{"po"},
245-
StorageVersionHash: discovery.StorageVersionHash("", "v1", "Pod"),
246-
},
247-
{
248-
Name: "services",
249-
Namespaced: true,
250-
Kind: "Service",
251-
Verbs: metav1.Verbs{"create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"},
252-
ShortNames: []string{"svc"},
253-
StorageVersionHash: discovery.StorageVersionHash("", "v1", "Service"),
254-
},
255-
},
256-
},
257-
}
258-
}
259-
260-
func getGatewayAPIGroupResource() *restmapper.APIGroupResources {
261-
return &restmapper.APIGroupResources{
262-
Group: metav1.APIGroup{
263-
Name: v1beta1.GroupVersion.Group,
264-
Versions: []metav1.GroupVersionForDiscovery{{GroupVersion: v1beta1.GroupVersion.String(), Version: v1beta1.GroupVersion.Version}},
265-
PreferredVersion: metav1.GroupVersionForDiscovery{GroupVersion: v1beta1.GroupVersion.String(), Version: v1beta1.GroupVersion.Version},
266-
},
267-
VersionedResources: map[string][]metav1.APIResource{
268-
v1beta1.GroupVersion.Version: {
269-
{
270-
Name: "gateways",
271-
Namespaced: false,
272-
SingularName: "gateway",
273-
Kind: "Gateway",
274-
Verbs: metav1.Verbs{"create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"},
275-
ShortNames: []string{"gw"},
276-
Categories: []string{"all"},
277-
StorageVersionHash: discovery.StorageVersionHash(v1beta1.GroupVersion.Group, v1beta1.GroupVersion.Version, "Gateway"),
278-
},
279-
{
280-
Name: "gateways/status",
281-
Namespaced: false,
282-
Kind: "Gateway",
283-
Verbs: metav1.Verbs{"get", "patch", "update"},
284-
},
285-
},
286-
},
287-
}
288-
}
289-
290221
func resolveLocalHost() string {
291222
ipv4Addr, err := net.ResolveIPAddr("ip4", "localhost")
292223
if err != nil {

pkg/engine/engine.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Engine struct {
3232
manager manager.Manager
3333
client client.Client
3434
option *Option
35-
queue workqueue.RateLimitingInterface
35+
queue workqueue.TypedRateLimitingInterface[*v1beta1.Gateway]
3636

3737
tunnel *TunnelEngine
3838
proxy *ProxyEngine
@@ -47,7 +47,7 @@ func NewEngine(ctx context.Context, cfg *config.Config) (*Engine, error) {
4747
manager: cfg.Manager,
4848
context: ctx,
4949
option: NewEngineOption(),
50-
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "raven"),
50+
queue: workqueue.NewTypedRateLimitingQueue[*v1beta1.Gateway](workqueue.DefaultTypedControllerRateLimiter[*v1beta1.Gateway]()),
5151
}
5252
err := ctrl.NewControllerManagedBy(engine.manager).
5353
For(&v1beta1.Gateway{}, builder.WithPredicates(predicate.Funcs{
@@ -110,12 +110,11 @@ func (e *Engine) worker() {
110110
}
111111

112112
func (e *Engine) processNextWorkItem() bool {
113-
obj, quit := e.queue.Get()
113+
gw, quit := e.queue.Get()
114114
if quit {
115115
return false
116116
}
117-
gw, ok := obj.(*v1beta1.Gateway)
118-
if !ok {
117+
if gw == nil {
119118
return false
120119
}
121120
defer e.queue.Done(gw)

pkg/engine/tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *TunnelEngine) InitDriver() error {
7979
}
8080

8181
func (c *TunnelEngine) CleanupDriver() {
82-
_ = wait.PollImmediate(time.Second, 5*time.Second, func() (done bool, err error) {
82+
_ = wait.PollUntilContextTimeout(context.Background(), time.Second, 5*time.Second, true, func(ctx context.Context) (done bool, err error) {
8383
err = c.vpnDriver.Cleanup()
8484
if err != nil {
8585
klog.Errorf("fail to cleanup vpn driver: %s", err.Error())

pkg/networkengine/routedriver/driver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ func RegisterRouteDriver(name string, factory Factory) {
6060
driversMutex.Lock()
6161
defer driversMutex.Unlock()
6262
if _, found := drivers[name]; found {
63-
klog.Fatal("route drivers %q was registered twice", name)
63+
klog.Fatalf("route drivers %s was registered twice", name)
6464
}
65-
klog.Info("registered route driver %q", name)
65+
klog.Infof("registered route driver %s", name)
6666
drivers[name] = factory
6767
}
6868

6969
func New(name string, cfg *config.Config) (Driver, error) {
7070
driversMutex.Lock()
7171
defer driversMutex.Unlock()
7272
if _, found := drivers[name]; !found {
73-
klog.Fatal("route driver %q not found", name)
73+
klog.Fatalf("route driver %s not found", name)
7474
}
7575
return drivers[name](cfg)
7676
}

pkg/networkengine/routedriver/vxlan/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
/*
54
* Copyright 2022 The OpenYurt Authors.

0 commit comments

Comments
 (0)