From 10eaca7d5f4cde39dada8015b7801afa76aefcdb Mon Sep 17 00:00:00 2001 From: Joseph Anttila Hall Date: Thu, 3 Oct 2024 20:28:21 -0700 Subject: [PATCH] Fix lint errors found on linter upgrade. --- cmd/agent/app/server.go | 4 ++-- cmd/server/app/server.go | 6 +++--- cmd/test-client/main.go | 6 +++--- cmd/test-server/main.go | 2 +- pkg/agent/client.go | 16 ++++++++-------- pkg/agent/client_test.go | 4 ++-- pkg/server/backend_manager.go | 2 +- pkg/server/server.go | 3 +-- pkg/server/server_test.go | 4 ++-- tests/agent_disconnect_test.go | 2 +- tests/custom_alpn_test.go | 2 +- tests/proxy_test.go | 8 ++++---- 12 files changed, 29 insertions(+), 30 deletions(-) diff --git a/cmd/agent/app/server.go b/cmd/agent/app/server.go index ce0c6d355..ec8232cc6 100644 --- a/cmd/agent/app/server.go +++ b/cmd/agent/app/server.go @@ -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) }, @@ -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") }) diff --git a/cmd/server/app/server.go b/cmd/server/app/server.go index 2e9129f20..4f2cff432 100644 --- a/cmd/server/app/server.go +++ b/cmd/server/app/server.go @@ -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) }, @@ -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) diff --git a/cmd/test-client/main.go b/cmd/test-client/main.go index e90e1dc63..10f5d382c 100644 --- a/cmd/test-client/main.go +++ b/cmd/test-client/main.go @@ -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) }, @@ -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 } @@ -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 } diff --git a/cmd/test-server/main.go b/cmd/test-server/main.go index 13bc238df..203c8209e 100644 --- a/cmd/test-server/main.go +++ b/cmd/test-server/main.go @@ -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) }, } diff --git a/pkg/agent/client.go b/pkg/agent/client.go index 53e538008..5a19ec9ee 100644 --- a/pkg/agent/client.go +++ b/pkg/agent/client.go @@ -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) } } } diff --git a/pkg/agent/client_test.go b/pkg/agent/client_test.go index 6e69ebbcd..3cd2bf253 100644 --- a/pkg/agent/client_test.go +++ b/pkg/agent/client_test.go @@ -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() @@ -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() diff --git a/pkg/server/backend_manager.go b/pkg/server/backend_manager.go index 12dd229e4..cd3c60984 100644 --- a/pkg/server/backend_manager.go +++ b/pkg/server/backend_manager.go @@ -399,7 +399,7 @@ func (s *DefaultBackendStorage) GetRandomBackend() (*Backend, error) { if len(s.backends) == 0 { return nil, &ErrNotFound{} } - agentID := s.agentIDs[s.random.Intn(len(s.agentIDs))] + agentID := s.agentIDs[s.random.Intn(len(s.agentIDs))] /* #nosec G404 */ klog.V(5).InfoS("Pick agent as backend", "agentID", agentID) // always return the first connection to an agent, because the agent // will close later connections if there are multiple. diff --git a/pkg/server/server.go b/pkg/server/server.go index 20098251e..9122c48f8 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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) } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index f5c548b3d..558166520 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -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, @@ -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, diff --git a/tests/agent_disconnect_test.go b/tests/agent_disconnect_test.go index f829a0ad2..3c5861312 100644 --- a/tests/agent_disconnect_test.go +++ b/tests/agent_disconnect_test.go @@ -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 } diff --git a/tests/custom_alpn_test.go b/tests/custom_alpn_test.go index 1d63deb1b..4a4ad820f 100644 --- a/tests/custom_alpn_test.go +++ b/tests/custom_alpn_test.go @@ -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) }, } diff --git a/tests/proxy_test.go b/tests/proxy_test.go index ff62ab9d1..b19b67e51 100644 --- a/tests/proxy_test.go +++ b/tests/proxy_test.go @@ -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 @@ -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 } @@ -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 } @@ -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 }