Skip to content
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
2 changes: 1 addition & 1 deletion devices/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func systemdProperties(r *cgroups.Resources, sdVer int) ([]systemdDbus.Property,
return properties, nil
}

func newProp(name string, units interface{}) systemdDbus.Property {
func newProp(name string, units any) systemdDbus.Property {
return systemdDbus.Property{
Name: name,
Value: dbus.MakeVariant(units),
Expand Down
2 changes: 1 addition & 1 deletion devices/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
}

// Now update the pod a few times.
for i := 0; i < 42; i++ {
for range 42 {
podConfig.Resources.PidsLimit++
podConfig.Resources.Memory += 1024 * 1024
if err := pm.Set(podConfig.Resources); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestWriteCgroupFileHandlesInterrupt(t *testing.T) {
t.Skip(err)
}

for i := 0; i < 100000; i++ {
for i := range 100000 {
limit := 1024*1024 + i
if err := WriteFile(cgroupPath, memoryLimit, strconv.Itoa(limit)); err != nil {
t.Fatalf("Failed to write %d on attempt %d: %+v", limit, i, err)
Expand Down
11 changes: 3 additions & 8 deletions fs/blkio_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fs

import (
"maps"
"strconv"
"testing"

Expand Down Expand Up @@ -465,10 +466,7 @@ func TestBlkioStatsNoFilesBFQDebug(t *testing.T) {
for _, testCase := range testCases {
path := tempDir(t, "cpuset")

tempBlkioTestFiles := map[string]string{}
for i, v := range blkioBFQDebugStatsTestFiles {
tempBlkioTestFiles[i] = v
}
tempBlkioTestFiles := maps.Clone(blkioBFQDebugStatsTestFiles)
delete(tempBlkioTestFiles, testCase.filename)

writeFileContents(t, path, tempBlkioTestFiles)
Expand Down Expand Up @@ -579,10 +577,7 @@ func TestBlkioStatsNoFilesCFQ(t *testing.T) {
for _, testCase := range testCases {
path := tempDir(t, "cpuset")

tempBlkioTestFiles := map[string]string{}
for i, v := range blkioCFQStatsTestFiles {
tempBlkioTestFiles[i] = v
}
tempBlkioTestFiles := maps.Clone(blkioCFQStatsTestFiles)
delete(tempBlkioTestFiles, testCase.filename)

writeFileContents(t, path, tempBlkioTestFiles)
Expand Down
6 changes: 2 additions & 4 deletions fs/cpuset_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fs

import (
"maps"
"reflect"
"testing"

Expand Down Expand Up @@ -211,10 +212,7 @@ func TestCPUSetStatsMissingFiles(t *testing.T) {
t.Run(testCase.desc, func(t *testing.T) {
path := tempDir(t, "cpuset")

tempCpusetTestFiles := map[string]string{}
for i, v := range cpusetTestFiles {
tempCpusetTestFiles[i] = v
}
tempCpusetTestFiles := maps.Clone(cpusetTestFiles)

if testCase.removeFile {
delete(tempCpusetTestFiles, testCase.filename)
Expand Down
2 changes: 1 addition & 1 deletion fs/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *FreezerGroup) Set(path string, r *cgroups.Resources) (Err error) {
// Alas, this is still a game of chances, since the real fix
// belong to the kernel (cgroup v2 do not have this bug).

for i := 0; i < 1000; i++ {
for i := range 1000 {
if i%50 == 49 {
// Occasional thaw and sleep improves
// the chances to succeed in freezing
Expand Down
4 changes: 2 additions & 2 deletions systemd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ExpandSlice(slice string) (string, error) {
return path, nil
}

func newProp(name string, units interface{}) systemdDbus.Property {
func newProp(name string, units any) systemdDbus.Property {
return systemdDbus.Property{
Name: name,
Value: dbus.MakeVariant(units),
Expand Down Expand Up @@ -266,7 +266,7 @@ func systemdVersionAtoi(str string) (int, error) {
// Unconditionally remove the leading prefix ("v).
str = strings.TrimLeft(str, `"v`)
// Match on the first integer we can grab.
for i := 0; i < len(str); i++ {
for i := range len(str) {
if str[i] < '0' || str[i] > '9' {
// First non-digit: cut the tail.
str = str[:i]
Expand Down
2 changes: 1 addition & 1 deletion systemd/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestUnitExistsIgnored(t *testing.T) {
pm := newManager(t, podConfig)

// create twice to make sure "UnitExists" error is ignored.
for i := 0; i < 2; i++ {
for range 2 {
if err := pm.Apply(-1); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func WriteCgroupProc(dir string, pid int) error {
}
defer file.Close()

for i := 0; i < 5; i++ {
for range 5 {
_, err = file.WriteString(strconv.Itoa(pid))
if err == nil {
return nil
Expand Down
10 changes: 2 additions & 8 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"path/filepath"
"reflect"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -273,14 +274,7 @@ func TestGetCgroupMounts(t *testing.T) {
if !strings.HasPrefix(m.Mountpoint, "/sys/fs/cgroup/") && !strings.Contains(m.Mountpoint, ss) {
t.Fatalf("unexpected mountpoint for %s: %s", ss, m.Mountpoint)
}
var ssFound bool
for _, mss := range m.Subsystems {
if mss == ss {
ssFound = true
break
}
}
if !ssFound {
if !slices.Contains(m.Subsystems, ss) {
t.Fatalf("subsystem %s not found in Subsystems field %v", ss, m.Subsystems)
}
}
Expand Down
7 changes: 3 additions & 4 deletions v1_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -144,10 +145,8 @@ func FindCgroupMountpointAndRoot(cgroupPath, subsystem string) (string, string,
func findCgroupMountpointAndRootFromMI(mounts []*mountinfo.Info, cgroupPath, subsystem string) (string, string, error) {
for _, mi := range mounts {
if strings.HasPrefix(mi.Mountpoint, cgroupPath) {
for _, opt := range strings.Split(mi.VFSOptions, ",") {
if opt == subsystem {
return mi.Mountpoint, mi.Root, nil
}
if slices.Contains(strings.Split(mi.VFSOptions, ","), subsystem) {
return mi.Mountpoint, mi.Root, nil
}
}
}
Expand Down