From 72c1c201f9c0edf79008ed75676a464d8af2a778 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Wed, 1 Nov 2023 16:08:05 +0200 Subject: [PATCH] shim: fix linter errors Signed-off-by: Mikko Ylinen --- .github/workflows/basic.yaml | 2 +- src/shim/.golangci.yml | 3 +-- .../runtime/v2/rune/agent/client/client.go | 3 +-- src/shim/runtime/v2/rune/mock/mock.go | 2 +- src/shim/runtime/v2/rune/v2/agent.go | 14 ++++++------ src/shim/runtime/v2/rune/v2/agent_test.go | 6 ++--- src/shim/runtime/v2/rune/v2/service.go | 22 +++++++++---------- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.github/workflows/basic.yaml b/.github/workflows/basic.yaml index 93587c6c..11061923 100644 --- a/.github/workflows/basic.yaml +++ b/.github/workflows/basic.yaml @@ -41,7 +41,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.51.2 + version: v1.55.1 args: -v --timeout 5m working-directory: 'src/shim' diff --git a/src/shim/.golangci.yml b/src/shim/.golangci.yml index f7398421..3026a526 100644 --- a/src/shim/.golangci.yml +++ b/src/shim/.golangci.yml @@ -1,7 +1,6 @@ linters: enable: - - structcheck - - varcheck + - unused - staticcheck - unconvert - goerr113 diff --git a/src/shim/runtime/v2/rune/agent/client/client.go b/src/shim/runtime/v2/rune/agent/client/client.go index 5f40f71b..b7c08c00 100644 --- a/src/shim/runtime/v2/rune/agent/client/client.go +++ b/src/shim/runtime/v2/rune/agent/client/client.go @@ -3,7 +3,6 @@ package client import ( - "context" "net" "net/url" "os" @@ -42,7 +41,7 @@ type AgentClient struct { // // Supported sock address format is: // - tcp://: -func NewAgentClient(ctx context.Context, sock string, timeout uint32) (*AgentClient, error) { +func NewAgentClient(sock string, timeout uint32) (*AgentClient, error) { addr, err := url.Parse(sock) if err != nil { return nil, err diff --git a/src/shim/runtime/v2/rune/mock/mock.go b/src/shim/runtime/v2/rune/mock/mock.go index e8073c6d..08fc4337 100644 --- a/src/shim/runtime/v2/rune/mock/mock.go +++ b/src/shim/runtime/v2/rune/mock/mock.go @@ -75,6 +75,6 @@ func (st *SockTTRPCMock) Stop() error { type SockTTRPCMockImp struct{} -func (p *SockTTRPCMockImp) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.PullImageResponse, error) { +func (p *SockTTRPCMockImp) PullImage(_ context.Context, _ *pb.PullImageRequest) (*pb.PullImageResponse, error) { return &pb.PullImageResponse{}, nil } diff --git a/src/shim/runtime/v2/rune/v2/agent.go b/src/shim/runtime/v2/rune/v2/agent.go index 3035aa3f..39611995 100644 --- a/src/shim/runtime/v2/rune/v2/agent.go +++ b/src/shim/runtime/v2/rune/v2/agent.go @@ -65,7 +65,7 @@ func (c *agent) Logger() *logrus.Entry { return logrus.WithField("source", "agent_enclave_container") } -func (c *agent) connect(ctx context.Context) error { +func (c *agent) connect() error { if c.dead { return fmt.Errorf("%w: Dead agent", errAgent) } @@ -82,19 +82,19 @@ func (c *agent) connect(ctx context.Context) error { } c.Logger().WithField("url", c.URL).Info("New client") - client, err := agentClient.NewAgentClient(ctx, c.URL, c.dialTimout) + client, err := agentClient.NewAgentClient(c.URL, c.dialTimout) if err != nil { c.dead = true return err } - c.installReqFunc(client) c.client = client + c.installReqFunc() return nil } -func (c *agent) disconnect(ctx context.Context) error { +func (c *agent) disconnect() error { c.Lock() defer c.Unlock() @@ -114,7 +114,7 @@ func (c *agent) disconnect(ctx context.Context) error { type reqFunc func(context.Context, interface{}) (interface{}, error) -func (c *agent) installReqFunc(client *agentClient.AgentClient) { +func (c *agent) installReqFunc() { c.reqHandlers = make(map[string]reqFunc) c.reqHandlers[grpcPullImageRequest] = func(ctx context.Context, req interface{}) (interface{}, error) { return c.client.ImageServiceClient.PullImage(ctx, req.(*grpc.PullImageRequest)) @@ -122,11 +122,11 @@ func (c *agent) installReqFunc(client *agentClient.AgentClient) { } func (c *agent) sendReq(spanCtx context.Context, request interface{}) (interface{}, error) { - if err := c.connect(spanCtx); err != nil { + if err := c.connect(); err != nil { return nil, err } - defer c.disconnect(spanCtx) + defer c.disconnect() msgName := proto.MessageName(request.(proto.Message)) diff --git a/src/shim/runtime/v2/rune/v2/agent_test.go b/src/shim/runtime/v2/rune/v2/agent_test.go index f1681746..02857945 100644 --- a/src/shim/runtime/v2/rune/v2/agent_test.go +++ b/src/shim/runtime/v2/rune/v2/agent_test.go @@ -28,7 +28,7 @@ func TestAgentConnect(t *testing.T) { URL: url, } - err = k.connect(context.Background()) + err = k.connect() assert.NoError(err) assert.NotNil(k.client) } @@ -48,8 +48,8 @@ func TestAgentDisconnect(t *testing.T) { URL: url, } - assert.NoError(k.connect(context.Background())) - assert.NoError(k.disconnect(context.Background())) + assert.NoError(k.connect()) + assert.NoError(k.disconnect()) assert.Nil(k.client) } diff --git a/src/shim/runtime/v2/rune/v2/service.go b/src/shim/runtime/v2/rune/v2/service.go index dcd4c631..7f091958 100644 --- a/src/shim/runtime/v2/rune/v2/service.go +++ b/src/shim/runtime/v2/rune/v2/service.go @@ -130,7 +130,7 @@ type service struct { cancel func() } -func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (*exec.Cmd, error) { +func newCommand(ctx context.Context, id, containerdAddress string) (*exec.Cmd, error) { ns, err := namespaces.NamespaceRequired(ctx) if err != nil { return nil, err @@ -171,7 +171,7 @@ func readSpec() (*spec, error) { } func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) { - cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress) + cmd, err := newCommand(ctx, opts.ID, opts.Address) if err != nil { return "", err } @@ -245,11 +245,11 @@ func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, go cmd.Wait() if data, err := io.ReadAll(os.Stdin); err == nil { if len(data) > 0 { - var any ptypes.Any - if err := proto.Unmarshal(data, &any); err != nil { + var anyv ptypes.Any + if err := proto.Unmarshal(data, &anyv); err != nil { return "", err } - v, err := typeurl.UnmarshalAny(&any) + v, err := typeurl.UnmarshalAny(&anyv) if err != nil { return "", err } @@ -370,7 +370,7 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error) }, nil } -func setOCIRuntime(ctx context.Context, r *taskAPI.CreateTaskRequest) (err error) { +func setOCIRuntime(r *taskAPI.CreateTaskRequest) (err error) { var opts options.Options // read options to get OCI Runtime if r.Options != nil { @@ -398,7 +398,7 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ * s.mu.Lock() defer s.mu.Unlock() - err = setOCIRuntime(ctx, r) + err = setOCIRuntime(r) if err != nil { return nil, err } @@ -809,7 +809,7 @@ func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*pt } // Wait for a process to exit -func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) { +func (s *service) Wait(_ context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) { logrus.WithField("container", r.ID).Debug("Wait() start") defer logrus.WithField("container", r.ID).Debug("Wait() end") @@ -830,7 +830,7 @@ func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.Wa } // Connect returns shim information such as the shim's pid -func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) { +func (s *service) Connect(_ context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) { logrus.WithField("container", r.ID).Debug("Connect() start") defer logrus.WithField("container", r.ID).Debug("Connect() end") @@ -844,7 +844,7 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*task }, nil } -func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) { +func (s *service) Shutdown(_ context.Context, _ *taskAPI.ShutdownRequest) (*ptypes.Empty, error) { s.mu.Lock() defer s.mu.Unlock() @@ -868,7 +868,7 @@ func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*pt return empty, nil } -func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) { +func (s *service) Stats(_ context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) { container, err := s.getContainer(r.ID) if err != nil { return nil, err