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

Commit

Permalink
lint: Update go linter from gometalinter to golangci-lint.
Browse files Browse the repository at this point in the history
gometalinter is deprecated and will be archived April '19. The
suggestion is to switch to golangci-lint which is apparently 5x faster
than gometalinter.

Partially Fixes: #1377

Signed-off-by: Ganesh Maharaj Mahalingam <[email protected]>
  • Loading branch information
Ganesh Maharaj Mahalingam committed Mar 25, 2019
1 parent 814e5de commit f442876
Show file tree
Hide file tree
Showing 35 changed files with 91 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ os:
go_import_path: github.com/kata-containers/runtime

go:
- "1.10.x"
- "1.11.x"

env:
- target_branch=$TRAVIS_BRANCH
Expand Down
2 changes: 1 addition & 1 deletion cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EXAMPLE:
}

args := context.Args()
if args.Present() == false {
if !args.Present() {
return fmt.Errorf("Missing container ID, should at least provide one")
}

Expand Down
1 change: 1 addition & 0 deletions cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func checkKernelModules(modules map[string]kernelModule, handler kernelParamHand

// genericHostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
//nolint: unused,deadcode
func genericHostIsVMContainerCapable(details vmContainerCapableDetails) error {
cpuinfo, err := getCPUInfo(details.cpuInfoFile)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cli/kata-check_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,50 +400,50 @@ func TestArchKernelParamHandler(t *testing.T) {

type testData struct {
onVMM bool
expectIgnore bool
fields logrus.Fields
msg string
expectIgnore bool
}

data := []testData{
{true, logrus.Fields{}, "", false},
{false, logrus.Fields{}, "", false},
{true, false, logrus.Fields{}, ""},
{false, false, logrus.Fields{}, ""},

{
false,
false,
logrus.Fields{
// wrong type
"parameter": 123,
},
"foo",
false,
},

{
false,
false,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
false,
},

{
true,
true,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
true,
},

{
false,
true,
logrus.Fields{
"parameter": "nested",
},
"",
true,
},
}

Expand Down
14 changes: 7 additions & 7 deletions cli/kata-check_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,50 +124,50 @@ func TestArchKernelParamHandler(t *testing.T) {

type testData struct {
onVMM bool
expectIgnore bool
fields logrus.Fields
msg string
expectIgnore bool
}

data := []testData{
{true, logrus.Fields{}, "", false},
{false, logrus.Fields{}, "", false},
{true, false, logrus.Fields{}, ""},
{false, false, logrus.Fields{}, ""},

{
false,
false,
logrus.Fields{
// wrong type
"parameter": 123,
},
"foo",
false,
},

{
false,
false,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
false,
},

{
true,
true,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
true,
},

{
false,
true,
logrus.Fields{
"parameter": "nested",
},
"",
true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EXAMPLE:
}

args := context.Args()
if args.Present() == false {
if !args.Present() {
return fmt.Errorf("Missing container ID")
}

Expand Down
2 changes: 1 addition & 1 deletion cli/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func validCreateParams(ctx context.Context, containerID, bundlePath string) (str
if err != nil {
return "", fmt.Errorf("Invalid bundle path '%s': %s", bundlePath, err)
}
if fileInfo.IsDir() == false {
if !fileInfo.IsDir() {
return "", fmt.Errorf("Invalid bundle path '%s', it should be a directory", bundlePath)
}

Expand Down
2 changes: 1 addition & 1 deletion cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var psCLICommand = cli.Command{
return err
}

if context.Args().Present() == false {
if !context.Args().Present() {
return fmt.Errorf("Missing container ID, should at least provide one")
}

Expand Down
2 changes: 1 addition & 1 deletion cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var startCLICommand = cli.Command{
}

args := context.Args()
if args.Present() == false {
if !args.Present() {
return fmt.Errorf("Missing container ID, should at least provide one")
}

Expand Down
2 changes: 1 addition & 1 deletion cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ other options are ignored.
span, _ := katautils.Trace(ctx, "update")
defer span.Finish()

if context.Args().Present() == false {
if !context.Args().Present() {
return fmt.Errorf("Missing container ID, should at least provide one")
}

Expand Down
4 changes: 1 addition & 3 deletions containerd-shim-v2/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func statsToMetrics(cgStats *vc.CgroupStats) *cgroups.Metrics {
}

var perCPU []uint64
for _, v := range cgStats.CPUStats.CPUUsage.PercpuUsage {
perCPU = append(perCPU, v)
}
perCPU = append(perCPU, cgStats.CPUStats.CPUUsage.PercpuUsage...)

metrics := &cgroups.Metrics{
Hugetlb: hugetlb,
Expand Down
6 changes: 2 additions & 4 deletions containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.E
}

s.send(&eventstypes.TaskPaused{
c.id,
ContainerID: c.id,
})

return empty, err
Expand Down Expand Up @@ -620,7 +620,7 @@ func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*ptypes
}

s.send(&eventstypes.TaskResumed{
c.id,
ContainerID: c.id,
})

return empty, err
Expand Down Expand Up @@ -838,8 +838,6 @@ func (s *service) checkProcesses(e exit) {
ExitStatus: uint32(e.status),
ExitedAt: e.timestamp,
})

return
}

func (s *service) getContainer(id string) (*container, error) {
Expand Down
2 changes: 1 addition & 1 deletion containerd-shim-v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func validBundle(containerID, bundlePath string) (string, error) {
if err != nil {
return "", fmt.Errorf("Invalid bundle path '%s': %s", bundlePath, err)
}
if fileInfo.IsDir() == false {
if !fileInfo.IsDir() {
return "", fmt.Errorf("Invalid bundle path '%s', it should be a directory", bundlePath)
}

Expand Down
32 changes: 16 additions & 16 deletions pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,13 @@ func TestHypervisorDefaults(t *testing.T) {
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")

h.DefaultMaxVCPUs = 2
assert.Equal(h.defaultMaxVCPUs(), uint32(h.DefaultMaxVCPUs), "default max vCPU number is wrong")
assert.Equal(h.defaultMaxVCPUs(), uint32(2), "default max vCPU number is wrong")

h.DefaultMaxVCPUs = uint32(numCPUs) + 1
assert.Equal(h.defaultMaxVCPUs(), uint32(numCPUs), "default max vCPU number is wrong")

maxvcpus := vc.MaxQemuVCPUs()
h.DefaultMaxVCPUs = uint32(maxvcpus) + 1
h.DefaultMaxVCPUs = maxvcpus + 1
assert.Equal(h.defaultMaxVCPUs(), uint32(numCPUs), "default max vCPU number is wrong")

h.MemorySize = 1024
Expand Down Expand Up @@ -1368,7 +1368,7 @@ func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
Hypervisor: map[string]hypervisor{
qemuHypervisorTableType: {
NumVCPUs: int32(vcpus),
MemorySize: uint32(mem),
MemorySize: mem,
Path: "/",
Kernel: "/",
Image: "/",
Expand Down Expand Up @@ -1556,18 +1556,18 @@ func TestCheckFactoryConfig(t *testing.T) {

type testData struct {
factoryEnabled bool
expectError bool
imagePath string
initrdPath string
expectError bool
}

data := []testData{
{false, "", "", false},
{false, "image", "", false},
{false, "", "initrd", false},
{false, false, "", ""},
{false, false, "image", ""},
{false, false, "", "initrd"},

{true, "", "initrd", false},
{true, "image", "", true},
{true, false, "", "initrd"},
{true, true, "image", ""},
}

for i, d := range data {
Expand Down Expand Up @@ -1596,19 +1596,19 @@ func TestCheckNetNsConfigShimTrace(t *testing.T) {
assert := assert.New(t)

type testData struct {
disableNetNs bool
networkModel vc.NetInterworkingModel
disableNetNs bool
shimTrace bool
expectError bool
}

data := []testData{
{false, vc.NetXConnectMacVtapModel, false, false},
{false, vc.NetXConnectMacVtapModel, true, true},
{true, vc.NetXConnectMacVtapModel, true, true},
{true, vc.NetXConnectMacVtapModel, false, true},
{true, vc.NetXConnectNoneModel, false, false},
{true, vc.NetXConnectNoneModel, true, false},
{vc.NetXConnectMacVtapModel, false, false, false},
{vc.NetXConnectMacVtapModel, false, true, true},
{vc.NetXConnectMacVtapModel, true, true, true},
{vc.NetXConnectMacVtapModel, true, false, true},
{vc.NetXConnectNoneModel, true, false, false},
{vc.NetXConnectNoneModel, true, true, false},
}

for i, d := range data {
Expand Down
5 changes: 5 additions & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ externals:
.*/v?([\d\.]+)\.tar\.gz
version: "v2.0.5"

golangci-lint:
description: "utility to run various golang linters"
url: "https://install.goreleaser.com/github.com/golangci/golangci-lint.sh"
version: "v1.15.0"

kubernetes:
description: "Kubernetes project container manager"
url: "https://github.com/kubernetes/kubernetes"
Expand Down
7 changes: 2 additions & 5 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
span, _ := sandbox.trace("newContainer")
defer span.Finish()

if contConfig.valid() == false {
if !contConfig.valid() {
return &Container{}, fmt.Errorf("Invalid container configuration")
}

Expand Down Expand Up @@ -1187,10 +1187,7 @@ func (c *Container) hotplugDrive() error {

// isDriveUsed checks if a drive has been used for container rootfs
func (c *Container) isDriveUsed() bool {
if c.state.Fstype == "" {
return false
}
return true
return !(c.state.Fstype == "")
}

func (c *Container) removeDrive() (err error) {
Expand Down
14 changes: 7 additions & 7 deletions virtcontainers/device/drivers/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (

func TestBumpAttachCount(t *testing.T) {
type testData struct {
attach bool
attachCount uint
expectedAC uint
attach bool
expectSkip bool
expectErr bool
}

data := []testData{
{true, 0, 1, false, false},
{true, 1, 2, true, false},
{true, intMax, intMax, true, true},
{false, 0, 0, true, true},
{false, 1, 0, false, false},
{false, intMax, intMax - 1, true, false},
{0, 1, true, false, false},
{1, 2, true, true, false},
{intMax, intMax, true, true, true},
{0, 0, false, true, true},
{1, 0, false, false, false},
{intMax, intMax - 1, false, true, false},
}

dev := &GenericDevice{}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/device/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (dm *deviceManager) DetachDevice(id string, dr api.DeviceReceiver) error {
if !ok {
return ErrDeviceNotExist
}
if d.GetAttachCount() <= 0 {
if d.GetAttachCount() == 0 {
return ErrDeviceNotAttached
}

Expand Down
6 changes: 1 addition & 5 deletions virtcontainers/device/manager/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,5 @@ func isVFIO(hostPath string) bool {

// isBlock checks if the device is a block device.
func isBlock(devInfo config.DeviceInfo) bool {
if devInfo.DevType == "b" {
return true
}

return false
return devInfo.DevType == "b"
}
2 changes: 0 additions & 2 deletions virtcontainers/example_pod_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,4 @@ func Example_createAndStartSandbox() {
if err != nil {
fmt.Printf("Could not run sandbox: %s", err)
}

return
}
Loading

0 comments on commit f442876

Please sign in to comment.