
This is to check if runc 1.0.0 (to be released shortly) works with k8s. The commands used were (roughly): hack/pin-dependency.sh github.com/opencontainers/runc v1.0.0 hack/lint-dependencies.sh # Follow its recommendations. hack/pin-dependency.sh github.com/cilium/ebpf v0.6.1 hack/pin-dependency.sh github.com/opencontainers/selinux v1.8.2 hack/pin-dependency.sh github.com/sirupsen/logrus v1.8.1 # Recheck. hack/lint-dependencies.sh GO111MODULE=on go mod edit -dropreplace github.com/willf/bitset hack/update-vendor.sh # Recheck. hack/lint-dependencies.sh hack/update-internal-modules.sh # Recheck. hack/lint-dependencies.sh [v2: rebased, updated runc 3a0234e1fe2e82 -> 2f8e8e9d977500] [v3: testing master + runc pr 3019] [v4: updated to 93a01cd4d0b7a0f08a] [v5: updated to f093cca13d3cf8a484] [v6: rebased] [v7: updated to runc v1.0.0] [v8: rebased] Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package systemd
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/bits-and-blooms/bitset"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// RangeToBits converts a text representation of a CPU mask (as written to
|
|
// or read from cgroups' cpuset.* files, e.g. "1,3-5") to a slice of bytes
|
|
// with the corresponding bits set (as consumed by systemd over dbus as
|
|
// AllowedCPUs/AllowedMemoryNodes unit property value).
|
|
func RangeToBits(str string) ([]byte, error) {
|
|
bits := &bitset.BitSet{}
|
|
|
|
for _, r := range strings.Split(str, ",") {
|
|
// allow extra spaces around
|
|
r = strings.TrimSpace(r)
|
|
// allow empty elements (extra commas)
|
|
if r == "" {
|
|
continue
|
|
}
|
|
ranges := strings.SplitN(r, "-", 2)
|
|
if len(ranges) > 1 {
|
|
start, err := strconv.ParseUint(ranges[0], 10, 32)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
end, err := strconv.ParseUint(ranges[1], 10, 32)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if start > end {
|
|
return nil, errors.New("invalid range: " + r)
|
|
}
|
|
for i := uint(start); i <= uint(end); i++ {
|
|
bits.Set(i)
|
|
}
|
|
} else {
|
|
val, err := strconv.ParseUint(ranges[0], 10, 32)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bits.Set(uint(val))
|
|
}
|
|
}
|
|
|
|
val := bits.Bytes()
|
|
if len(val) == 0 {
|
|
// do not allow empty values
|
|
return nil, errors.New("empty value")
|
|
}
|
|
ret := make([]byte, len(val)*8)
|
|
for i := range val {
|
|
// bitset uses BigEndian internally
|
|
binary.BigEndian.PutUint64(ret[i*8:], val[len(val)-1-i])
|
|
}
|
|
// remove upper all-zero bytes
|
|
for ret[0] == 0 {
|
|
ret = ret[1:]
|
|
}
|
|
|
|
return ret, nil
|
|
}
|