Skip to content

Commit 71572c2

Browse files
authored
Merge pull request kubernetes-sigs#658 from jkh52/golint-122
Fix lint: move to Github Action
2 parents 0fb666d + a46af9a commit 71572c2

15 files changed

+61
-33
lines changed

.github/workflows/golangci-lint.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-0.31
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
env:
13+
GO_VERSION: v1.22
14+
GOLANGCI_LINT_VERSION: v1.56
15+
16+
jobs:
17+
golangci:
18+
name: lint
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ env.GO_VERSION }}
25+
- name: golangci-lint
26+
uses: golangci/golangci-lint-action@v6
27+
with:
28+
version: ${{ env.GOLANGCI_LINT_VERSION }}
29+
args: --verbose

.golangci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
timeout: 3m
2+
timeout: 5m
33
skip-dirs:
44
- vendor
55
linters:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ endif
3333
GOOS ?= $(shell go env GOOS)
3434
GOARCH ?= $(shell go env GOARCH)
3535
INSTALL_LOCATION:=$(shell go env GOPATH)/bin
36-
GOLANGCI_LINT_VERSION ?= 1.54.0
36+
GOLANGCI_LINT_VERSION ?= 1.56.2
3737
GOSEC_VERSION ?= 2.13.1
3838

3939
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)

cmd/agent/app/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewAgentCommand(a *Agent, o *options.GrpcProxyAgentOptions) *cobra.Command
6161
cmd := &cobra.Command{
6262
Use: "agent",
6363
Long: `A gRPC agent, Connects to the proxy and then allows traffic to be forwarded to it.`,
64-
RunE: func(cmd *cobra.Command, args []string) error {
64+
RunE: func(_ *cobra.Command, _ []string) error {
6565
drainCh, stopCh := SetupSignalHandler()
6666
return a.Run(o, drainCh, stopCh)
6767
},
@@ -183,7 +183,7 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
183183
}
184184

185185
func (a *Agent) runHealthServer(o *options.GrpcProxyAgentOptions, cs agent.ReadinessManager) error {
186-
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
186+
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
187187
fmt.Fprintf(w, "ok")
188188
})
189189

cmd/server/app/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewProxyCommand(p *Proxy, o *options.ProxyRunOptions) *cobra.Command {
6464
cmd := &cobra.Command{
6565
Use: "proxy",
6666
Long: `A gRPC proxy server, receives requests from the API server and forwards to the agent.`,
67-
RunE: func(cmd *cobra.Command, args []string) error {
67+
RunE: func(_ *cobra.Command, _ []string) error {
6868
stopCh := SetupSignalHandler()
6969
return p.Run(o, stopCh)
7070
},
@@ -452,10 +452,10 @@ func (p *Proxy) runAdminServer(o *options.ProxyRunOptions, _ *server.ProxyServer
452452
}
453453

454454
func (p *Proxy) runHealthServer(o *options.ProxyRunOptions, server *server.ProxyServer) error {
455-
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
455+
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
456456
fmt.Fprintf(w, "ok")
457457
})
458-
readinessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
458+
readinessHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
459459
ready, msg := server.Readiness.Ready()
460460
if ready {
461461
w.WriteHeader(200)

cmd/test-client/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func newGrpcProxyClientCommand(c *Client, o *GrpcProxyClientOptions) *cobra.Comm
216216
cmd := &cobra.Command{
217217
Use: "proxy-client",
218218
Long: `A gRPC proxy Client, primarily used to test the Kubernetes gRPC Proxy Server.`,
219-
RunE: func(cmd *cobra.Command, args []string) error {
219+
RunE: func(cmd *cobra.Command, _ []string) error {
220220
cmd.SilenceUsage = true
221221
return c.run(o)
222222
},
@@ -479,7 +479,7 @@ func (c *Client) getUDSDialer(o *GrpcProxyClientOptions) (func(ctx context.Conte
479479
return nil, fmt.Errorf("failed to process mode %s", o.mode)
480480
}
481481

482-
return func(ctx context.Context, network, addr string) (net.Conn, error) {
482+
return func(_ context.Context, _, _ string) (net.Conn, error) {
483483
return proxyConn, nil
484484
}, nil
485485
}
@@ -556,7 +556,7 @@ func (c *Client) getMTLSDialer(o *GrpcProxyClientOptions) (func(ctx context.Cont
556556
return nil, fmt.Errorf("failed to process mode %s", o.mode)
557557
}
558558

559-
return func(ctx context.Context, network, addr string) (net.Conn, error) {
559+
return func(_ context.Context, _, _ string) (net.Conn, error) {
560560
return proxyConn, nil
561561
}, nil
562562
}

cmd/test-server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func newTestServerCommand(p *TestServer, o *TestServerRunOptions) *cobra.Command
8989
cmd := &cobra.Command{
9090
Use: "test http server",
9191
Long: `A test http server, url determines behavior for certain tests.`,
92-
RunE: func(cmd *cobra.Command, args []string) error {
92+
RunE: func(_ *cobra.Command, _ []string) error {
9393
return p.run(o)
9494
},
9595
}

pkg/agent/client.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,14 @@ func (a *Client) remoteToProxy(connID int64, eConn *endpointConn) {
553553
klog.ErrorS(err, "connection read failure", "connectionID", connID)
554554
}
555555
return
556-
} else {
557-
resp.Payload = &client.Packet_Data{Data: &client.Data{
558-
Data: buf[:n],
559-
ConnectID: connID,
560-
}}
561-
if err := a.Send(resp); err != nil {
562-
klog.ErrorS(err, "could not send DATA", "connectionID", connID)
563-
}
556+
}
557+
558+
resp.Payload = &client.Packet_Data{Data: &client.Data{
559+
Data: buf[:n],
560+
ConnectID: connID,
561+
}}
562+
if err := a.Send(resp); err != nil {
563+
klog.ErrorS(err, "could not send DATA", "connectionID", connID)
564564
}
565565
}
566566
}

pkg/agent/client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestServeData_HTTP(t *testing.T) {
5454

5555
// Start test http server as remote service
5656
expectedBody := "Hello, client"
57-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
57+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
5858
fmt.Fprint(w, expectedBody)
5959
}))
6060
defer ts.Close()
@@ -152,7 +152,7 @@ func TestClose_Client(t *testing.T) {
152152
defer close(stopCh)
153153

154154
// Start test http server as remote service
155-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
155+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
156156
fmt.Fprint(w, "hello, world")
157157
}))
158158
defer ts.Close()

pkg/server/backend_manager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ func NewDefaultBackendStorage(idTypes []header.IdentifierType) *DefaultBackendSt
287287
metrics.Metrics.SetBackendCount(0)
288288
return &DefaultBackendStorage{
289289
backends: make(map[string][]*Backend),
290-
random: rand.New(rand.NewSource(time.Now().UnixNano())),
290+
random: rand.New(rand.NewSource(time.Now().UnixNano())), /* #nosec G404 */
291291
idTypes: idTypes,
292-
} /* #nosec G404 */
292+
}
293293
}
294294

295295
func containIDType(idTypes []header.IdentifierType, idType header.IdentifierType) bool {

pkg/server/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ func (c *ProxyClientConnection) send(pkt *client.Packet) error {
132132
return c.CloseHTTP()
133133
}
134134
return nil
135-
} else {
136-
return fmt.Errorf("attempt to send via unrecognized connection type %v", pkt.Type)
137135
}
136+
return fmt.Errorf("attempt to send via unrecognized connection type %v", pkt.Type)
138137
}
139138
return fmt.Errorf("attempt to send via unrecognized connection mode %q", c.Mode)
140139
}

pkg/server/server_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestAgentTokenAuthenticationErrorsToken(t *testing.T) {
137137
t.Run(tc.desc, func(t *testing.T) {
138138
kcs := k8sfake.NewSimpleClientset()
139139

140-
kcs.AuthenticationV1().(*fakeauthenticationv1.FakeAuthenticationV1).Fake.PrependReactor("create", "tokenreviews", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
140+
kcs.AuthenticationV1().(*fakeauthenticationv1.FakeAuthenticationV1).Fake.PrependReactor("create", "tokenreviews", func(_ k8stesting.Action) (handled bool, ret runtime.Object, err error) {
141141
tr := &authv1.TokenReview{
142142
Status: authv1.TokenReviewStatus{
143143
Authenticated: tc.authenticated,
@@ -809,7 +809,7 @@ func TestServerProxyRecvChanFull(t *testing.T) {
809809
}
810810

811811
func TestServerProxyNoDial(t *testing.T) {
812-
baseServerProxyTestWithBackend(t, func(frontendConn, agentConn *agentmock.MockAgentService_ConnectServer) {
812+
baseServerProxyTestWithBackend(t, func(frontendConn, _ *agentmock.MockAgentService_ConnectServer) {
813813
const connectID = 123456
814814
data := &client.Packet{
815815
Type: client.PacketType_DATA,

tests/agent_disconnect_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func createHTTPConnectClient(_ context.Context, proxyAddr, addr string) (*http.C
216216
return nil, fmt.Errorf("unexpected extra buffer")
217217
}
218218

219-
dialer := func(network, addr string) (net.Conn, error) {
219+
dialer := func(_, _ string) (net.Conn, error) {
220220
return conn, nil
221221
}
222222

tests/custom_alpn_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestCustomALPN(t *testing.T) {
4040
svr := httptest.NewUnstartedServer(http.DefaultServeMux)
4141
svr.TLS = &tls.Config{NextProtos: []string{proto}, MinVersion: tls.VersionTLS13}
4242
svr.Config.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){
43-
proto: func(svr *http.Server, conn *tls.Conn, handle http.Handler) {
43+
proto: func(*http.Server, *tls.Conn, http.Handler) {
4444
atomic.AddInt32(&protoUsed, 1)
4545
},
4646
}

tests/proxy_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func TestProxyDial_RequestCancelled_Concurrent_GRPC(t *testing.T) {
372372
waitForConnectedServerCount(t, 1, a)
373373

374374
wg := sync.WaitGroup{}
375-
dialFn := func(id int, cancelDelay time.Duration) {
375+
dialFn := func(_ int, cancelDelay time.Duration) {
376376
defer wg.Done()
377377

378378
// run test client
@@ -631,7 +631,7 @@ func TestBasicProxy_HTTPCONN(t *testing.T) {
631631
t.Error("unexpected extra buffer")
632632
}
633633

634-
dialer := func(network, addr string) (net.Conn, error) {
634+
dialer := func(_, _ string) (net.Conn, error) {
635635
return conn, nil
636636
}
637637

@@ -695,7 +695,7 @@ func TestFailedDNSLookupProxy_HTTPCONN(t *testing.T) {
695695
if br.Buffered() > 0 {
696696
t.Error("unexpected extra buffer")
697697
}
698-
dialer := func(network, addr string) (net.Conn, error) {
698+
dialer := func(_, _ string) (net.Conn, error) {
699699
return conn, nil
700700
}
701701

@@ -769,7 +769,7 @@ func TestFailedDial_HTTPCONN(t *testing.T) {
769769
t.Fatalf("expect 200; got %d", res.StatusCode)
770770
}
771771

772-
dialer := func(network, addr string) (net.Conn, error) {
772+
dialer := func(_, _ string) (net.Conn, error) {
773773
return conn, nil
774774
}
775775

0 commit comments

Comments
 (0)