mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-04 07:49:35 +00:00 
			
		
		
		
	This updates vendored runc/libcontainer to 1.1.0, and google/cadvisor to a version updated to runc 1.1.0 (google/cadvisor#3048). Changes in vendor are generated by (roughly): ./hack/pin-dependency.sh github.com/google/cadvisor v0.44.0 ./hack/pin-dependency.sh github.com/opencontainers/runc v1.1.0 ./hack/update-vendor.sh ./hack/lint-dependencies.sh # And follow all its recommendations. ./hack/update-vendor.sh ./hack/update-internal-modules.sh ./hack/lint-dependencies.sh # Re-check everything again. Co-Authored-By: Kir Kolyshkin <kolyshkin@gmail.com>
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package systemd
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
	"math/big"
 | 
						|
	"strconv"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
// 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 := new(big.Int)
 | 
						|
 | 
						|
	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 := start; i <= end; i++ {
 | 
						|
				bits.SetBit(bits, int(i), 1)
 | 
						|
			}
 | 
						|
		} else {
 | 
						|
			val, err := strconv.ParseUint(ranges[0], 10, 32)
 | 
						|
			if err != nil {
 | 
						|
				return nil, err
 | 
						|
			}
 | 
						|
			bits.SetBit(bits, int(val), 1)
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	ret := bits.Bytes()
 | 
						|
	if len(ret) == 0 {
 | 
						|
		// do not allow empty values
 | 
						|
		return nil, errors.New("empty value")
 | 
						|
	}
 | 
						|
	return ret, nil
 | 
						|
}
 |