Skip to content

Commit cbbb466

Browse files
committed
cgroups,cmd,generate,validat{e,ion}: fix golangci-lint issues.
Signed-off-by: Krisztian Litkey <[email protected]>
1 parent c74446f commit cbbb466

File tree

26 files changed

+41
-43
lines changed

26 files changed

+41
-43
lines changed

cgroups/cgroups_v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func (cg *CgroupV1) GetMemoryData(pid int, cgPath string) (*rspec.LinuxMemory, e
539539
return nil, err
540540
}
541541
kernelLimit := res
542-
lm.Kernel = &kernelLimit
542+
lm.Kernel = &kernelLimit //nolint:staticcheck
543543
case 4:
544544
res, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
545545
if err != nil {

cmd/runtimetest/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (c *complianceTester) validateSysctls(spec *rspec.Spec) error {
392392
}
393393

394394
for k, v := range spec.Linux.Sysctl {
395-
keyPath := filepath.Join("/proc/sys", strings.Replace(k, ".", "/", -1))
395+
keyPath := filepath.Join("/proc/sys", strings.ReplaceAll(k, ".", "/"))
396396
vBytes, err := os.ReadFile(keyPath)
397397
if err != nil {
398398
return err
@@ -453,10 +453,10 @@ func testFileReadAccess(path string) (readable bool, err error) {
453453
}
454454
defer f.Close()
455455
b := make([]byte, 1)
456-
_, err = f.Read(b)
457-
if err == nil {
456+
switch _, err = f.Read(b); err {
457+
case nil:
458458
return true, nil
459-
} else if err == io.EOF {
459+
case io.EOF:
460460
// Our validation/ tests only use non-empty files for read-access
461461
// tests. So if we get an EOF on the first read, the runtime did
462462
// successfully block readability.
@@ -1310,10 +1310,11 @@ func run(context *cli.Context) error {
13101310
}
13111311

13121312
validations := defaultValidations
1313-
if platform == "linux" {
1313+
switch platform {
1314+
case "linux":
13141315
validations = append(validations, posixValidations...)
13151316
validations = append(validations, linuxValidations...)
1316-
} else if platform == "solaris" {
1317+
case "solaris":
13171318
validations = append(validations, posixValidations...)
13181319
}
13191320

generate/generate.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func New(os string) (generator Generator, err error) {
9292
}
9393
}
9494

95-
if os == "linux" {
95+
switch os {
96+
case "linux":
9697
config.Process.Capabilities = &rspec.LinuxCapabilities{
9798
Bounding: []string{
9899
"CAP_CHOWN",
@@ -241,7 +242,7 @@ func New(os string) (generator Generator, err error) {
241242
},
242243
Seccomp: seccomp.DefaultProfile(&config),
243244
}
244-
} else if os == "freebsd" {
245+
case "freebsd":
245246
config.Mounts = []rspec.Mount{
246247
{
247248
Destination: "/dev",
@@ -597,7 +598,7 @@ func (g *Generator) ClearProcessAdditionalGids() {
597598
}
598599

599600
// AddProcessAdditionalGid adds an additional gid into g.Config.Process.AdditionalGids.
600-
func (g *Generator) AddProcessAdditionalGid(gid uint32) {
601+
func (g *Generator) AddProcessAdditionalGid(gid uint32) { //nolint:staticcheck
601602
g.initConfigProcess()
602603
for _, group := range g.Config.Process.User.AdditionalGids {
603604
if group == gid {
@@ -915,7 +916,7 @@ func (g *Generator) SetLinuxResourcesMemorySwap(swap int64) {
915916
// SetLinuxResourcesMemoryKernel sets g.Config.Linux.Resources.Memory.Kernel.
916917
func (g *Generator) SetLinuxResourcesMemoryKernel(kernel int64) {
917918
g.initConfigLinuxResourcesMemory()
918-
g.Config.Linux.Resources.Memory.Kernel = &kernel
919+
g.Config.Linux.Resources.Memory.Kernel = &kernel //nolint:staticcheck
919920
}
920921

921922
// SetLinuxResourcesMemoryKernelTCP sets g.Config.Linux.Resources.Memory.KernelTCP.
@@ -1066,13 +1067,13 @@ func (g *Generator) ClearPreStartHooks() {
10661067
if g.Config == nil || g.Config.Hooks == nil {
10671068
return
10681069
}
1069-
g.Config.Hooks.Prestart = []rspec.Hook{}
1070+
g.Config.Hooks.Prestart = []rspec.Hook{} //nolint:staticcheck
10701071
}
10711072

10721073
// AddPreStartHook add a prestart hook into g.Config.Hooks.Prestart.
10731074
func (g *Generator) AddPreStartHook(preStartHook rspec.Hook) {
10741075
g.initConfigHooks()
1075-
g.Config.Hooks.Prestart = append(g.Config.Hooks.Prestart, preStartHook)
1076+
g.Config.Hooks.Prestart = append(g.Config.Hooks.Prestart, preStartHook) //nolint:staticcheck
10761077
}
10771078

10781079
// ClearPostStopHooks clear g.Config.Hooks.Poststop.

generate/seccomp/seccomp_default.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package seccomp
33
import (
44
"runtime"
55

6-
"github.com/opencontainers/runtime-spec/specs-go"
76
rspec "github.com/opencontainers/runtime-spec/specs-go"
87
)
98

@@ -31,7 +30,7 @@ func arches() []rspec.Arch {
3130
}
3231

3332
// DefaultProfile defines the whitelist for the default seccomp profile.
34-
func DefaultProfile(rs *specs.Spec) *rspec.LinuxSeccomp {
33+
func DefaultProfile(rs *rspec.Spec) *rspec.LinuxSeccomp {
3534
syscalls := []rspec.LinuxSyscall{
3635
{
3736
Names: []string{

generate/seccomp/seccomp_default_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package seccomp
54

generate/seccomp/seccomp_default_unsupported.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux
2-
// +build !linux
32

43
package seccomp
54

validate/validate.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (v *Validator) CheckHooks() (errs error) {
274274
}
275275

276276
if v.spec.Hooks != nil {
277-
errs = multierror.Append(errs, v.checkEventHooks("prestart", v.spec.Hooks.Prestart, v.HostSpecific))
277+
errs = multierror.Append(errs, v.checkEventHooks("prestart", v.spec.Hooks.Prestart, v.HostSpecific)) //nolint:staticcheck
278278
errs = multierror.Append(errs, v.checkEventHooks("poststart", v.spec.Hooks.Poststart, v.HostSpecific))
279279
errs = multierror.Append(errs, v.checkEventHooks("poststop", v.spec.Hooks.Poststop, v.HostSpecific))
280280
}
@@ -440,7 +440,7 @@ func (v *Validator) CheckCapabilities() (errs error) {
440440
if effective && !permitted {
441441
errs = multierror.Append(errs, fmt.Errorf("effective capability %q is not allowed, as it's not permitted", capability))
442442
}
443-
if ambient && !(permitted && inheritable) {
443+
if ambient && (!permitted || !inheritable) {
444444
errs = multierror.Append(errs, fmt.Errorf("ambient capability %q is not allowed, as it's not permitted and inheribate", capability))
445445
}
446446
}
@@ -718,21 +718,22 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
718718
errs = multierror.Append(errs, fmt.Errorf("hard limit of rlimit %s should not be less than soft limit", rlimit.Type))
719719
}
720720

721-
if v.platform == "linux" {
721+
switch v.platform {
722+
case "linux":
722723
for _, val := range linuxRlimits {
723724
if val == rlimit.Type {
724725
return
725726
}
726727
}
727728
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
728-
} else if v.platform == "solaris" {
729+
case "solaris":
729730
for _, val := range posixRlimits {
730731
if val == rlimit.Type {
731732
return
732733
}
733734
}
734735
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
735-
} else {
736+
default:
736737
logrus.Warnf("process.rlimits validation not yet implemented for platform %q", v.platform)
737738
}
738739

validate/validate_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package validate
54

validate/validate_unsupported.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux
2-
// +build !linux
32

43
package validate
54

validation/hostname/hostname.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
t.Header(0)
3131
defer t.AutoPlan()
3232

33-
if "linux" != runtime.GOOS {
33+
if runtime.GOOS != "linux" {
3434
t.Skip(1, "linux-specific namespace test")
3535
}
3636

0 commit comments

Comments
 (0)