Skip to content

Commit

Permalink
Fix lint errors found on linter upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkh52 committed Oct 4, 2024
1 parent 35153e7 commit a46af9a
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewAgentCommand(a *Agent, o *options.GrpcProxyAgentOptions) *cobra.Command
cmd := &cobra.Command{
Use: "agent",
Long: `A gRPC agent, Connects to the proxy and then allows traffic to be forwarded to it.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
drainCh, stopCh := SetupSignalHandler()
return a.Run(o, drainCh, stopCh)
},
Expand Down Expand Up @@ -182,7 +182,7 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
}

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

Expand Down
6 changes: 3 additions & 3 deletions cmd/server/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewProxyCommand(p *Proxy, o *options.ProxyRunOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "proxy",
Long: `A gRPC proxy server, receives requests from the API server and forwards to the agent.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
stopCh := SetupSignalHandler()
return p.Run(o, stopCh)
},
Expand Down Expand Up @@ -451,10 +451,10 @@ func (p *Proxy) runAdminServer(o *options.ProxyRunOptions, _ *server.ProxyServer
}

func (p *Proxy) runHealthServer(o *options.ProxyRunOptions, server *server.ProxyServer) error {
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, "ok")
})
readinessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
readinessHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
ready, msg := server.Readiness.Ready()
if ready {
w.WriteHeader(200)
Expand Down
6 changes: 3 additions & 3 deletions cmd/test-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func newGrpcProxyClientCommand(c *Client, o *GrpcProxyClientOptions) *cobra.Comm
cmd := &cobra.Command{
Use: "proxy-client",
Long: `A gRPC proxy Client, primarily used to test the Kubernetes gRPC Proxy Server.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
cmd.SilenceUsage = true
return c.run(o)
},
Expand Down Expand Up @@ -479,7 +479,7 @@ func (c *Client) getUDSDialer(o *GrpcProxyClientOptions) (func(ctx context.Conte
return nil, fmt.Errorf("failed to process mode %s", o.mode)
}

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

return func(ctx context.Context, network, addr string) (net.Conn, error) {
return func(_ context.Context, _, _ string) (net.Conn, error) {
return proxyConn, nil
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/test-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newTestServerCommand(p *TestServer, o *TestServerRunOptions) *cobra.Command
cmd := &cobra.Command{
Use: "test http server",
Long: `A test http server, url determines behavior for certain tests.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return p.run(o)
},
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ func (a *Client) remoteToProxy(connID int64, eConn *endpointConn) {
klog.ErrorS(err, "connection read failure", "connectionID", connID)
}
return
} else {
resp.Payload = &client.Packet_Data{Data: &client.Data{
Data: buf[:n],
ConnectID: connID,
}}
if err := a.Send(resp); err != nil {
klog.ErrorS(err, "could not send DATA", "connectionID", connID)
}
}

resp.Payload = &client.Packet_Data{Data: &client.Data{
Data: buf[:n],
ConnectID: connID,
}}
if err := a.Send(resp); err != nil {
klog.ErrorS(err, "could not send DATA", "connectionID", connID)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestServeData_HTTP(t *testing.T) {

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

// Start test http server as remote service
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, "hello, world")
}))
defer ts.Close()
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/backend_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ func NewDefaultBackendStorage(idTypes []header.IdentifierType) *DefaultBackendSt
metrics.Metrics.SetBackendCount(0)
return &DefaultBackendStorage{
backends: make(map[string][]*Backend),
random: rand.New(rand.NewSource(time.Now().UnixNano())),
random: rand.New(rand.NewSource(time.Now().UnixNano())), /* #nosec G404 */
idTypes: idTypes,
} /* #nosec G404 */
}
}

func containIDType(idTypes []header.IdentifierType, idType header.IdentifierType) bool {
Expand Down
3 changes: 1 addition & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ func (c *ProxyClientConnection) send(pkt *client.Packet) error {
return c.CloseHTTP()
}
return nil
} else {
return fmt.Errorf("attempt to send via unrecognized connection type %v", pkt.Type)
}
return fmt.Errorf("attempt to send via unrecognized connection type %v", pkt.Type)
}
return fmt.Errorf("attempt to send via unrecognized connection mode %q", c.Mode)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestAgentTokenAuthenticationErrorsToken(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
kcs := k8sfake.NewSimpleClientset()

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

func TestServerProxyNoDial(t *testing.T) {
baseServerProxyTestWithBackend(t, func(frontendConn, agentConn *agentmock.MockAgentService_ConnectServer) {
baseServerProxyTestWithBackend(t, func(frontendConn, _ *agentmock.MockAgentService_ConnectServer) {
const connectID = 123456
data := &client.Packet{
Type: client.PacketType_DATA,
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_disconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func createHTTPConnectClient(_ context.Context, proxyAddr, addr string) (*http.C
return nil, fmt.Errorf("unexpected extra buffer")
}

dialer := func(network, addr string) (net.Conn, error) {
dialer := func(_, _ string) (net.Conn, error) {
return conn, nil
}

Expand Down
2 changes: 1 addition & 1 deletion tests/custom_alpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCustomALPN(t *testing.T) {
svr := httptest.NewUnstartedServer(http.DefaultServeMux)
svr.TLS = &tls.Config{NextProtos: []string{proto}, MinVersion: tls.VersionTLS13}
svr.Config.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){
proto: func(svr *http.Server, conn *tls.Conn, handle http.Handler) {
proto: func(*http.Server, *tls.Conn, http.Handler) {
atomic.AddInt32(&protoUsed, 1)
},
}
Expand Down
8 changes: 4 additions & 4 deletions tests/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func TestProxyDial_RequestCancelled_Concurrent_GRPC(t *testing.T) {
waitForConnectedServerCount(t, 1, a)

wg := sync.WaitGroup{}
dialFn := func(id int, cancelDelay time.Duration) {
dialFn := func(_ int, cancelDelay time.Duration) {
defer wg.Done()

// run test client
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestBasicProxy_HTTPCONN(t *testing.T) {
t.Error("unexpected extra buffer")
}

dialer := func(network, addr string) (net.Conn, error) {
dialer := func(_, _ string) (net.Conn, error) {
return conn, nil
}

Expand Down Expand Up @@ -679,7 +679,7 @@ func TestFailedDNSLookupProxy_HTTPCONN(t *testing.T) {
if br.Buffered() > 0 {
t.Error("unexpected extra buffer")
}
dialer := func(network, addr string) (net.Conn, error) {
dialer := func(_, _ string) (net.Conn, error) {
return conn, nil
}

Expand Down Expand Up @@ -753,7 +753,7 @@ func TestFailedDial_HTTPCONN(t *testing.T) {
t.Fatalf("expect 200; got %d", res.StatusCode)
}

dialer := func(network, addr string) (net.Conn, error) {
dialer := func(_, _ string) (net.Conn, error) {
return conn, nil
}

Expand Down

0 comments on commit a46af9a

Please sign in to comment.