Skip to content

Commit

Permalink
Enable more golangci-lint linters
Browse files Browse the repository at this point in the history
Cleanup the golangci.yml file and enable more linters.

`pkg/spec` and `iopodman.io` is history. The vendor directory
is excluded by default. The dependencies dir was listed twice.

Fix the reported problems in `pkg/specgen` because that was also
excluded by `pkg/spec`.

Enable the structcheck, typecheck, varcheck, deadcode and depguard
linters.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger committed Feb 12, 2021
1 parent 78c8a87 commit 78b4199
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 23 deletions.
9 changes: 0 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ run:
deadline: 5m
skip-dirs-use-default: true
skip-dirs:
- dependencies
- contrib
- dependencies
- test
- pkg/spec
- vendor
skip-files:
- iopodman.go
- swagger.go
modules-download-mode: readonly
linters:
Expand Down Expand Up @@ -51,12 +47,7 @@ linters:
- goconst
- gocyclo
- lll
- structcheck
- typecheck
- unconvert
- varcheck
- deadcode
- depguard
- errcheck
- gocritic
- gosec
Expand Down
1 change: 0 additions & 1 deletion pkg/specgen/container_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func exclusiveOptions(opt1, opt2 string) error {
// Validate verifies that the given SpecGenerator is valid and satisfies required
// input for creating a container.
func (s *SpecGenerator) Validate() error {

if rootless.IsRootless() && len(s.CNINetworks) == 0 {
if s.StaticIP != nil || s.StaticIPv6 != nil {
return ErrNoStaticIPRootless
Expand Down
1 change: 0 additions & 1 deletion pkg/specgen/generate/config_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func DevicesFromPath(g *generate.Generator, devicePath string) error {

// mount the internal devices recursively
if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error {

if f.Mode()&os.ModeDevice == os.ModeDevice {
found = true
device := fmt.Sprintf("%s:%s", dpath, filepath.Join(dest, strings.TrimPrefix(dpath, src)))
Expand Down
1 change: 0 additions & 1 deletion pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ func getPodPorts(containers []v1.Container) []specgen.PortMapping {
if p.HostPort != 0 {
infraPorts = append(infraPorts, portBinding)
}

}
}
return infraPorts
Expand Down
1 change: 1 addition & 0 deletions pkg/specgen/generate/kube/seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

// KubeSeccompPaths holds information about a pod YAML's seccomp configuration
// it holds both container and pod seccomp paths
// nolint:golint
type KubeSeccompPaths struct {
containerPaths map[string]string
podPath string
Expand Down
2 changes: 2 additions & 0 deletions pkg/specgen/generate/kube/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const (
kubeFilePermission = 0644
)

// nolint:golint
type KubeVolumeType int

const (
KubeVolumeTypeBindMount KubeVolumeType = iota
KubeVolumeTypeNamed KubeVolumeType = iota
)

// nolint:golint
type KubeVolume struct {
// Type of volume to create
Type KubeVolumeType
Expand Down
1 change: 0 additions & 1 deletion pkg/specgen/generate/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
if !mappingFound {
gid5Available = false
}

}
if !gid5Available {
// If we have no GID mappings, the gid=5 default option would fail, so drop it.
Expand Down
14 changes: 5 additions & 9 deletions pkg/specgen/generate/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
}
}
if !s.Privileged && len(capsRequiredRequested) > 0 {

// Pass capRequiredRequested in CapAdd field to normalize capabilities names
capsRequired, err := capabilities.MergeCapabilities(nil, capsRequiredRequested, nil)
if err != nil {
return errors.Wrapf(err, "capabilities requested by user or image are not valid: %q", strings.Join(capsRequired, ","))
} else {
// Verify all capRequired are in the capList
for _, cap := range capsRequired {
if !util.StringInSlice(cap, caplist) {
privCapsRequired = append(privCapsRequired, cap)
}
}
// Verify all capRequired are in the capList
for _, cap := range capsRequired {
if !util.StringInSlice(cap, caplist) {
privCapsRequired = append(privCapsRequired, cap)
}
}
if len(privCapsRequired) == 0 {
Expand Down Expand Up @@ -189,7 +187,6 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
return err
}
for sysctlKey, sysctlVal := range defaultSysctls {

// Ignore mqueue sysctls if --ipc=host
if noUseIPC && strings.HasPrefix(sysctlKey, "fs.mqueue.") {
logrus.Infof("Sysctl %s=%s ignored in containers.conf, since IPC Namespace set to host", sysctlKey, sysctlVal)
Expand All @@ -213,7 +210,6 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
}

for sysctlKey, sysctlVal := range s.Sysctl {

if s.IpcNS.IsHost() && strings.HasPrefix(sysctlKey, "fs.mqueue.") {
return errors.Wrapf(define.ErrInvalidArg, "sysctl %s=%s can't be set since IPC Namespace set to host", sysctlKey, sysctlVal)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/specgen/pod_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func exclusivePodOptions(opt1, opt2 string) error {

// Validate verifies the input is valid
func (p *PodSpecGenerator) Validate() error {

if rootless.IsRootless() && len(p.CNINetworks) == 0 {
if p.StaticIP != nil {
return ErrNoStaticIPRootless
Expand Down

0 comments on commit 78b4199

Please sign in to comment.