Skip to content

Commit

Permalink
shim: fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Mikko Ylinen <[email protected]>
  • Loading branch information
mythi committed Nov 9, 2023
1 parent 5805dc7 commit 72c1c20
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 1 addition & 2 deletions src/shim/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
linters:
enable:
- structcheck
- varcheck
- unused
- staticcheck
- unconvert
- goerr113
Expand Down
3 changes: 1 addition & 2 deletions src/shim/runtime/v2/rune/agent/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package client

import (
"context"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -42,7 +41,7 @@ type AgentClient struct {
//
// Supported sock address format is:
// - tcp://<ip>:<port>
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
Expand Down
2 changes: 1 addition & 1 deletion src/shim/runtime/v2/rune/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 7 additions & 7 deletions src/shim/runtime/v2/rune/v2/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()

Expand All @@ -114,19 +114,19 @@ 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))
}
}

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))

Expand Down
6 changes: 3 additions & 3 deletions src/shim/runtime/v2/rune/v2/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down
22 changes: 11 additions & 11 deletions src/shim/runtime/v2/rune/v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")

Expand All @@ -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")

Expand All @@ -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()

Expand All @@ -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
Expand Down

0 comments on commit 72c1c20

Please sign in to comment.