Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

lint: Switch golang linter to golangci-lint #491

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (s *sandbox) deleteContainer(id string) {
}

func (s *sandbox) getProcess(cid, execID string) (*process, *container, error) {
if s.running == false {
if !s.running {
return nil, nil, grpcStatus.Error(codes.FailedPrecondition, "Sandbox not started")
}

Expand Down Expand Up @@ -951,7 +951,7 @@ func makeUnaryInterceptor() grpc.UnaryServerInterceptor {

if !tracing {
// Just log call details
elapsed = time.Now().Sub(start)
elapsed = time.Since(start)
message = resp.(proto.Message)

logger := agentLog.WithFields(logrus.Fields{
Expand Down
4 changes: 2 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *serialChannel) wait() error {
var events [1]unix.EpollEvent

fd := c.serialConn.Fd()
if fd <= 0 {
if fd == 0 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change needed? 😟

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe since https://golang.org/pkg/os/#File.Fd returns a uintptr. Don't need to worry about negative values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. that was the complaint by the linter.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return fmt.Errorf("serial port IO closed")
}

Expand Down Expand Up @@ -271,7 +271,7 @@ func findVirtualSerialPath(serialName string) (string, error) {
return "", err
}

if strings.Contains(string(content), serialName) == true {
if strings.Contains(string(content), serialName) {
return filepath.Join(devRootPath, port), nil
}
}
Expand Down
12 changes: 6 additions & 6 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func updateCpusetPath(cgroupPath string, newCpuset string, cookies cookie) error
cgroupParentPath = filepath.Join(cgroupParentPath, path)

// check if the cgroup was already updated.
if cookies[cgroupParentPath] == true {
if cookies[cgroupParentPath] {
agentLog.WithField("path", cgroupParentPath).Debug("cpuset cgroup already updated")
continue
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func (a *agentGRPC) Version(ctx context.Context, req *pb.CheckRequest) (*pb.Vers
}

func (a *agentGRPC) getContainer(cid string) (*container, error) {
if a.sandbox.running == false {
if !a.sandbox.running {
return nil, grpcStatus.Error(codes.FailedPrecondition, "Sandbox not started")
}

Expand Down Expand Up @@ -793,7 +793,7 @@ func posixRlimitsToRlimits(posixRlimits []specs.POSIXRlimit) []configs.Rlimit {
}

func (a *agentGRPC) createContainerChecks(req *pb.CreateContainerRequest) (err error) {
if a.sandbox.running == false {
if !a.sandbox.running {
return grpcStatus.Error(codes.FailedPrecondition, "Sandbox not started, impossible to run a new container")
}

Expand Down Expand Up @@ -887,7 +887,7 @@ func (a *agentGRPC) ExecProcess(ctx context.Context, req *pb.ExecProcessRequest)
}

func (a *agentGRPC) SignalProcess(ctx context.Context, req *pb.SignalProcessRequest) (*gpb.Empty, error) {
if a.sandbox.running == false {
if !a.sandbox.running {
return emptyResp, grpcStatus.Error(codes.FailedPrecondition, "Sandbox not started, impossible to signal the container")
}

Expand Down Expand Up @@ -1343,7 +1343,7 @@ func (a *agentGRPC) TtyWinResize(ctx context.Context, req *pb.TtyWinResizeReques
}

func (a *agentGRPC) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequest) (*gpb.Empty, error) {
if a.sandbox.running == true {
if a.sandbox.running {
return emptyResp, grpcStatus.Error(codes.AlreadyExists, "Sandbox already started, impossible to start again")
}

Expand Down Expand Up @@ -1392,7 +1392,7 @@ func (a *agentGRPC) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequ
}

func (a *agentGRPC) DestroySandbox(ctx context.Context, req *pb.DestroySandboxRequest) (*gpb.Empty, error) {
if a.sandbox.running == false {
if !a.sandbox.running {
agentLog.Info("Sandbox not started, this is a no-op")
return emptyResp, nil
}
Expand Down
8 changes: 4 additions & 4 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ func testAgentDetails(assert *assert.Assertions, details *pb.AgentDetails, haveS
storages = append(storages, handler)
}

sort.Sort(sort.StringSlice(details.DeviceHandlers))
sort.Sort(sort.StringSlice(details.StorageHandlers))
sort.Strings(details.DeviceHandlers)
sort.Strings(details.StorageHandlers)

sort.Sort(sort.StringSlice(devices))
sort.Sort(sort.StringSlice(storages))
sort.Strings(devices)
sort.Strings(storages)

assert.Equal(details.DeviceHandlers, devices)
assert.Equal(details.StorageHandlers, storages)
Expand Down
4 changes: 2 additions & 2 deletions protocols/grpc/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func assertIsEqual(t *testing.T, ociSpec *specs.Spec, grpcSpec *Spec) {
assert.Equal(len(grpcSpec.Linux.Namespaces), 5)

for i := range grpcSpec.Linux.Namespaces {
assert.Equal(grpcSpec.Linux.Namespaces[i].Type, (string)(ociSpec.Linux.Namespaces[i].Type))
assert.Equal(grpcSpec.Linux.Namespaces[i].Path, (string)(ociSpec.Linux.Namespaces[i].Path))
assert.Equal(grpcSpec.Linux.Namespaces[i].Type, (string)(ociSpec.Linux.Namespaces[i].Type)) //nolint:unconvert
assert.Equal(grpcSpec.Linux.Namespaces[i].Path, (string)(ociSpec.Linux.Namespaces[i].Path)) //nolint:unconvert
}
}

Expand Down