Skip to content

Commit 1a7c8ac

Browse files
committed
cgroup,cmd,generate,validate,validation: fix golangci-lint issues.
Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 6cb0329 commit 1a7c8ac

File tree

46 files changed

+121
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+121
-122
lines changed

cgroups/cgroups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func FindCgroup() (Cgroup, error) {
4848

4949
// This is an error as we can't detect if the mount is for "cgroup"
5050
if numPostFields == 0 {
51-
return nil, fmt.Errorf("Found no fields post '-' in %q", text)
51+
return nil, fmt.Errorf("found no fields post '-' in %q", text)
5252
}
5353

5454
if postSeparatorFields[0] == "cgroup" {

cgroups/cgroups_v1.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (cg *CgroupV1) GetBlockIOData(pid int, cgPath string) (*rspec.LinuxBlockIO,
4141
path := filepath.Join(cg.MountPath, "blkio", cgPath)
4242
if _, err := os.Stat(path); err != nil {
4343
if os.IsNotExist(err) {
44-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
44+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
4545
}
4646
return nil, err
4747
}
@@ -64,7 +64,7 @@ func (cg *CgroupV1) GetBlockIOData(pid int, cgPath string) (*rspec.LinuxBlockIO,
6464
contents, err := os.ReadFile(filePath)
6565
if err != nil {
6666
if os.IsNotExist(err) {
67-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
67+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
6868
}
6969

7070
return nil, err
@@ -216,7 +216,7 @@ func (cg *CgroupV1) GetCPUData(pid int, cgPath string) (*rspec.LinuxCPU, error)
216216
path := filepath.Join(cg.MountPath, "cpu", cgPath)
217217
if _, err := os.Stat(path); err != nil {
218218
if os.IsNotExist(err) {
219-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
219+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
220220
}
221221
return nil, err
222222
}
@@ -239,7 +239,7 @@ func (cg *CgroupV1) GetCPUData(pid int, cgPath string) (*rspec.LinuxCPU, error)
239239
contents, err := os.ReadFile(filePath)
240240
if err != nil {
241241
if os.IsNotExist(err) {
242-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
242+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
243243
}
244244

245245
return nil, err
@@ -433,7 +433,7 @@ func (cg *CgroupV1) GetHugepageLimitData(pid int, cgPath string) ([]rspec.LinuxH
433433
path := filepath.Join(cg.MountPath, "hugetlb", cgPath)
434434
if _, err := os.Stat(path); err != nil {
435435
if os.IsNotExist(err) {
436-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
436+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
437437
}
438438
return nil, err
439439
}
@@ -459,7 +459,7 @@ func (cg *CgroupV1) GetHugepageLimitData(pid int, cgPath string) ([]rspec.LinuxH
459459
contents, err := os.ReadFile(filePath)
460460
if err != nil {
461461
if os.IsNotExist(err) {
462-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
462+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
463463
}
464464

465465
return lh, err
@@ -483,7 +483,7 @@ func (cg *CgroupV1) GetMemoryData(pid int, cgPath string) (*rspec.LinuxMemory, e
483483
path := filepath.Join(cg.MountPath, "memory", cgPath)
484484
if _, err := os.Stat(path); err != nil {
485485
if os.IsNotExist(err) {
486-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
486+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
487487
}
488488
return nil, err
489489
}
@@ -506,7 +506,7 @@ func (cg *CgroupV1) GetMemoryData(pid int, cgPath string) (*rspec.LinuxMemory, e
506506
contents, err := os.ReadFile(filePath)
507507
if err != nil {
508508
if os.IsNotExist(err) {
509-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
509+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
510510
}
511511

512512
return nil, err
@@ -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 {
@@ -578,7 +578,7 @@ func (cg *CgroupV1) GetNetworkData(pid int, cgPath string) (*rspec.LinuxNetwork,
578578
path := filepath.Join(cg.MountPath, "net_cls", cgPath)
579579
if _, err := os.Stat(path); err != nil {
580580
if os.IsNotExist(err) {
581-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
581+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
582582
}
583583
return nil, err
584584
}
@@ -599,7 +599,7 @@ func (cg *CgroupV1) GetNetworkData(pid int, cgPath string) (*rspec.LinuxNetwork,
599599
contents, err := os.ReadFile(filePath)
600600
if err != nil {
601601
if os.IsNotExist(err) {
602-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
602+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
603603
}
604604

605605
return nil, err
@@ -649,7 +649,7 @@ func (cg *CgroupV1) GetPidsData(pid int, cgPath string) (*rspec.LinuxPids, error
649649
path := filepath.Join(cg.MountPath, "pids", cgPath)
650650
if _, err := os.Stat(path); err != nil {
651651
if os.IsNotExist(err) {
652-
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
652+
return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("in the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
653653
}
654654
return nil, err
655655
}
@@ -674,7 +674,7 @@ func (cg *CgroupV1) GetPidsData(pid int, cgPath string) (*rspec.LinuxPids, error
674674
res, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
675675
if err != nil {
676676
if os.IsNotExist(err) {
677-
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
677+
return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
678678
}
679679

680680
return nil, err

cmd/oci-runtime-tool/generate.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,15 @@ func parseDevice(device string, g *generate.Generator) (rspec.LinuxDevice, error
11531153
// The required part and optional part are separated by ":"
11541154
argsParts := strings.Split(device, ":")
11551155
if len(argsParts) < 4 {
1156-
return dev, fmt.Errorf("Incomplete device arguments: %s", device)
1156+
return dev, fmt.Errorf("incomplete device arguments: %s", device)
11571157
}
11581158
requiredPart := argsParts[0:4]
11591159
optionalPart := argsParts[4:]
11601160

11611161
// The required part must contain type, major, minor, and path
11621162
dev.Type = requiredPart[0]
11631163
if !deviceType[dev.Type] {
1164-
return dev, fmt.Errorf("Invalid device type: %s", dev.Type)
1164+
return dev, fmt.Errorf("invalid device type: %s", dev.Type)
11651165
}
11661166

11671167
i, err := strconv.ParseInt(requiredPart[1], 10, 64)
@@ -1182,7 +1182,7 @@ func parseDevice(device string, g *generate.Generator) (rspec.LinuxDevice, error
11821182
parts := strings.SplitN(s, "=", 2)
11831183

11841184
if len(parts) != 2 {
1185-
return dev, fmt.Errorf("Incomplete device arguments: %s", s)
1185+
return dev, fmt.Errorf("incomplete device arguments: %s", s)
11861186
}
11871187

11881188
name, value := parts[0], parts[1]
@@ -1245,7 +1245,7 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
12451245
allow = false
12461246
default:
12471247
return rspec.LinuxDeviceCgroup{},
1248-
fmt.Errorf("Only 'allow' and 'deny' are allowed in the first field of device-access-add: %s", device)
1248+
fmt.Errorf("only 'allow' and 'deny' are allowed in the first field of device-access-add: %s", device)
12491249
}
12501250

12511251
for _, s := range argsParts[1:] {
@@ -1255,14 +1255,14 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
12551255
}
12561256
parts := strings.SplitN(s, "=", 2)
12571257
if len(parts) != 2 {
1258-
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Incomplete device-access-add arguments: %s", s)
1258+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("incomplete device-access-add arguments: %s", s)
12591259
}
12601260
name, value := parts[0], parts[1]
12611261

12621262
switch name {
12631263
case "type":
12641264
if !cgroupDeviceType[value] {
1265-
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Invalid device type in device-access-add: %s", value)
1265+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("invalid device type in device-access-add: %s", value)
12661266
}
12671267
devType = value
12681268
case "major":
@@ -1280,7 +1280,7 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
12801280
case "access":
12811281
for _, c := range strings.Split(value, "") {
12821282
if !cgroupDeviceAccess[c] {
1283-
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Invalid device access in device-access-add: %s", c)
1283+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("invalid device access in device-access-add: %s", c)
12841284
}
12851285
}
12861286
access = value

cmd/runtimetest/main.go

Lines changed: 10 additions & 8 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,16 +453,17 @@ 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.
463463
return false, nil
464+
default:
465+
return false, err
464466
}
465-
return false, err
466467
}
467468

468469
func testWriteAccess(path string) (writable bool, err error) {
@@ -1233,7 +1234,7 @@ func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
12331234
}
12341235
fileLabel, err := label.FileLabel(mount.Destination)
12351236
if err != nil {
1236-
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)
1237+
return fmt.Errorf("failed to get mountLabel of %v", mount.Destination)
12371238
}
12381239
c.harness.Ok(spec.Linux.MountLabel == fileLabel, "has expected mountlabel")
12391240
_ = c.harness.YAML(map[string]string{
@@ -1310,10 +1311,11 @@ func run(context *cli.Context) error {
13101311
}
13111312

13121313
validations := defaultValidations
1313-
if platform == "linux" {
1314+
switch platform {
1315+
case "linux":
13141316
validations = append(validations, posixValidations...)
13151317
validations = append(validations, linuxValidations...)
1316-
} else if platform == "solaris" {
1318+
case "solaris":
13171319
validations = append(validations, posixValidations...)
13181320
}
13191321

cmd/runtimetest/rlimit_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var rlimitMap = map[string]int{
4444
func strToRlimit(key string) (int, error) {
4545
rl, ok := rlimitMap[key]
4646
if !ok {
47-
return 0, fmt.Errorf("Wrong rlimit value: %s", key)
47+
return 0, fmt.Errorf("wrong rlimit value: %s", key)
4848
}
4949
return rl, nil
5050
}

generate/generate.go

Lines changed: 8 additions & 7 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",
@@ -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.
@@ -1792,7 +1793,7 @@ func (g *Generator) SetVMImageFormat(format string) error {
17921793
case "vmdk":
17931794
case "vhd":
17941795
default:
1795-
return fmt.Errorf("Commonly supported formats are: raw, qcow2, vdi, vmdk, vhd")
1796+
return fmt.Errorf("commonly supported formats are: raw, qcow2, vdi, vmdk, vhd")
17961797
}
17971798
g.initConfigVM()
17981799
g.Config.VM.Image.Format = format
@@ -1820,7 +1821,7 @@ func (g *Generator) AddWindowsLayerFolders(folder string) {
18201821
// AddWindowsDevices adds or sets g.Config.Windwos.Devices
18211822
func (g *Generator) AddWindowsDevices(id, idType string) error {
18221823
if idType != "class" {
1823-
return fmt.Errorf("Invalid idType value: %s. Windows only supports a value of class", idType)
1824+
return fmt.Errorf("invalid idType value: %s. Windows only supports a value of class", idType)
18241825
}
18251826
device := rspec.WindowsDevice{
18261827
ID: id,

generate/seccomp/parse_remove.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// parses it, and updates the Seccomp config accordingly
1313
func RemoveAction(arguments string, config *rspec.LinuxSeccomp) error {
1414
if config == nil {
15-
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
15+
return fmt.Errorf("cannot remove action from nil Seccomp pointer")
1616
}
1717

1818
syscallsToRemove := strings.Split(arguments, ",")
@@ -29,7 +29,7 @@ func RemoveAction(arguments string, config *rspec.LinuxSeccomp) error {
2929
// RemoveAllSeccompRules removes all seccomp syscall rules
3030
func RemoveAllSeccompRules(config *rspec.LinuxSeccomp) error {
3131
if config == nil {
32-
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
32+
return fmt.Errorf("cannot remove action from nil Seccomp pointer")
3333
}
3434
newSyscallSlice := []rspec.LinuxSyscall{}
3535
config.Syscalls = newSyscallSlice
@@ -39,7 +39,7 @@ func RemoveAllSeccompRules(config *rspec.LinuxSeccomp) error {
3939
// RemoveAllMatchingRules will remove any syscall rules that match the specified action
4040
func RemoveAllMatchingRules(config *rspec.LinuxSeccomp, seccompAction rspec.LinuxSeccompAction) error {
4141
if config == nil {
42-
return fmt.Errorf("Cannot remove action from nil Seccomp pointer")
42+
return fmt.Errorf("cannot remove action from nil Seccomp pointer")
4343
}
4444

4545
for _, syscall := range config.Syscalls {

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

0 commit comments

Comments
 (0)