Merge pull request #27454 from Luap99/cgroup-bump

update github.com/opencontainers/cgroups to v0.0.6
This commit is contained in:
openshift-merge-bot[bot]
2025-11-06 15:16:36 +00:00
committed by GitHub
10 changed files with 64 additions and 32 deletions

2
go.mod
View File

@@ -49,7 +49,7 @@ require (
github.com/nxadm/tail v1.4.11
github.com/onsi/ginkgo/v2 v2.27.2
github.com/onsi/gomega v1.38.2
github.com/opencontainers/cgroups v0.0.5
github.com/opencontainers/cgroups v0.0.6
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.1
github.com/opencontainers/runtime-spec v1.2.1

4
go.sum
View File

@@ -300,8 +300,8 @@ github.com/onsi/ginkgo/v2 v2.27.2 h1:LzwLj0b89qtIy6SSASkzlNvX6WktqurSHwkk2ipF/Ns
github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
github.com/opencontainers/cgroups v0.0.5 h1:DRITAqcOnY0uSBzIpt1RYWLjh5DPDiqUs4fY6Y0ktls=
github.com/opencontainers/cgroups v0.0.5/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
github.com/opencontainers/cgroups v0.0.6 h1:tfZFWTIIGaUUFImTyuTg+Mr5x8XRiSdZESgEBW7UxuI=
github.com/opencontainers/cgroups v0.0.6/go.mod h1:oWVzJsKK0gG9SCRBfTpnn16WcGEqDI8PAcpMGbqWxcs=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=

View File

@@ -375,7 +375,7 @@ func GetLimits(resource *spec.LinuxResources) (runcconfig.Resources, error) {
// Pids
if resource.Pids != nil {
final.PidsLimit = resource.Pids.Limit
final.PidsLimit = &resource.Pids.Limit
}
// Networking

View File

@@ -90,8 +90,8 @@ type Resources struct {
// Cgroup's SCHED_IDLE value.
CPUIdle *int64 `json:"cpu_idle,omitempty"`
// Process limit; set <= `0' to disable limit.
PidsLimit int64 `json:"pids_limit,omitempty"`
// Process limit; set < `0' to disable limit. `nil` means "keep current limit".
PidsLimit *int64 `json:"pids_limit,omitempty"`
// Specifies per cgroup weight, range is from 10 to 1000.
BlkioWeight uint16 `json:"blkio_weight,omitempty"`

View File

@@ -129,12 +129,16 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) {
defer fd.Close()
scanner := bufio.NewScanner(fd)
scanner.Scan() // skipping header line
scanner.Scan() // Read header line.
const want = "cpu user system"
if hdr := scanner.Text(); !strings.HasPrefix(hdr, want) {
return nil, nil, malformedLine(path, file, hdr)
}
for scanner.Scan() {
// Each line is: cpu user system
fields := strings.SplitN(scanner.Text(), " ", 3)
if len(fields) != 3 {
// Each line is: cpu user system. Keep N at 4 to ignore extra fields.
fields := strings.SplitN(scanner.Text(), " ", 4)
if len(fields) < 3 {
continue
}

View File

@@ -19,19 +19,24 @@ func (s *PidsGroup) Apply(path string, _ *cgroups.Resources, pid int) error {
}
func (s *PidsGroup) Set(path string, r *cgroups.Resources) error {
if r.PidsLimit != 0 {
// "max" is the fallback value.
limit := "max"
if r.PidsLimit > 0 {
limit = strconv.FormatInt(r.PidsLimit, 10)
}
if err := cgroups.WriteFile(path, "pids.max", limit); err != nil {
return err
}
if r.PidsLimit == nil {
return nil
}
// "max" is the fallback value.
val := "max"
if limit := *r.PidsLimit; limit > 0 {
val = strconv.FormatInt(limit, 10)
} else if limit == 0 {
// systemd doesn't support setting pids.max to "0", so when setting
// TasksMax we need to remap it to "1". We do the same thing here to
// avoid flip-flop behaviour between the fs and systemd drivers. In
// practice, the pids cgroup behaviour is basically identical.
val = "1"
}
if err := cgroups.WriteFile(path, "pids.max", val); err != nil {
return err
}
return nil
}

View File

@@ -165,11 +165,22 @@ func statIo(dirPath string, stats *cgroups.Stats) error {
case "wios":
op = "Write"
targetTable = &parsedStats.IoServicedRecursive
case "cost.usage":
op = "Count"
targetTable = &parsedStats.IoCostUsage
case "cost.wait":
op = "Count"
targetTable = &parsedStats.IoCostWait
case "cost.indebt":
op = "Count"
targetTable = &parsedStats.IoCostIndebt
case "cost.indelay":
op = "Count"
targetTable = &parsedStats.IoCostIndelay
default:
// Skip over entries we cannot map to cgroupv1 stats for now.
// In the future we should expand the stats struct to include
// them.
logrus.Debugf("cgroupv2 io stats: skipping over unmappable %s entry", item)
logrus.Debugf("cgroupv2 io stats: unknown entry %s", item)
continue
}

View File

@@ -4,6 +4,7 @@ import (
"errors"
"math"
"os"
"strconv"
"strings"
"golang.org/x/sys/unix"
@@ -13,19 +14,26 @@ import (
)
func isPidsSet(r *cgroups.Resources) bool {
return r.PidsLimit != 0
return r.PidsLimit != nil
}
func setPids(dirPath string, r *cgroups.Resources) error {
if !isPidsSet(r) {
return nil
}
if val := numToStr(r.PidsLimit); val != "" {
if err := cgroups.WriteFile(dirPath, "pids.max", val); err != nil {
return err
}
val := "max"
if limit := *r.PidsLimit; limit > 0 {
val = strconv.FormatInt(limit, 10)
} else if limit == 0 {
// systemd doesn't support setting pids.max to "0", so when setting
// TasksMax we need to remap it to "1". We do the same thing here to
// avoid flip-flop behaviour between the fs and systemd drivers. In
// practice, the pids cgroup behaviour is basically identical.
val = "1"
}
if err := cgroups.WriteFile(dirPath, "pids.max", val); err != nil {
return err
}
return nil
}

View File

@@ -159,6 +159,10 @@ type BlkioStats struct {
IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive,omitempty"`
SectorsRecursive []BlkioStatEntry `json:"sectors_recursive,omitempty"`
PSI *PSIStats `json:"psi,omitempty"`
IoCostUsage []BlkioStatEntry `json:"io_cost_usage,omitempty"`
IoCostWait []BlkioStatEntry `json:"io_cost_wait,omitempty"`
IoCostIndebt []BlkioStatEntry `json:"io_cost_indebt,omitempty"`
IoCostIndelay []BlkioStatEntry `json:"io_cost_indelay,omitempty"`
}
type HugetlbStats struct {

2
vendor/modules.txt vendored
View File

@@ -519,7 +519,7 @@ github.com/onsi/gomega/matchers/support/goraph/edge
github.com/onsi/gomega/matchers/support/goraph/node
github.com/onsi/gomega/matchers/support/goraph/util
github.com/onsi/gomega/types
# github.com/opencontainers/cgroups v0.0.5
# github.com/opencontainers/cgroups v0.0.6
## explicit; go 1.23.0
github.com/opencontainers/cgroups
github.com/opencontainers/cgroups/devices/config