func TestForEach(t *testing.T) { testCases := []sets.Int{ sets.NewInt(), sets.NewInt(0), sets.NewInt(0, 2, 5, 9), sets.NewInt(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), } for i, tc := range testCases { m := NewAllocationMap(10, "test") for offset := range tc { if ok, _ := m.Allocate(offset); !ok { t.Errorf("[%d] error allocate offset %v", i, offset) } if !m.Has(offset) { t.Errorf("[%d] expect offset %v allocated", i, offset) } } calls := sets.NewInt() m.ForEach(func(i int) { calls.Insert(i) }) if len(calls) != len(tc) { t.Errorf("[%d] expected %d calls, got %d", i, len(tc), len(calls)) } if !calls.Equal(tc) { t.Errorf("[%d] expected calls to equal testcase: %v vs %v", i, calls.List(), tc.List()) } } }
func TestForEach(t *testing.T) { pr, err := net.ParsePortRange("10000-10200") if err != nil { t.Fatal(err) } testCases := []sets.Int{ sets.NewInt(), sets.NewInt(10000), sets.NewInt(10000, 10200), sets.NewInt(10000, 10099, 10200), } for i, tc := range testCases { r := NewPortAllocator(*pr) for port := range tc { if err := r.Allocate(port); err != nil { t.Errorf("[%d] error allocating port %v: %v", i, port, err) } if !r.Has(port) { t.Errorf("[%d] expected port %v allocated", i, port) } } calls := sets.NewInt() r.ForEach(func(port int) { calls.Insert(port) }) if len(calls) != len(tc) { t.Errorf("[%d] expected %d calls, got %d", i, len(tc), len(calls)) } if !calls.Equal(tc) { t.Errorf("[%d] expected calls to equal testcase: %v vs %v", i, calls.List(), tc.List()) } } }
// Scans through all subsytems to find pids associated with specified cgroup. func (m *cgroupManagerImpl) Pids(name CgroupName) []int { // we need the driver specific name cgroupFsName := m.Name(name) // Get a list of processes that we need to kill pidsToKill := sets.NewInt() var pids []int for _, val := range m.subsystems.MountPoints { dir := path.Join(val, cgroupFsName) _, err := os.Stat(dir) if os.IsNotExist(err) { // The subsystem pod cgroup is already deleted // do nothing, continue continue } // Get a list of pids that are still charged to the pod's cgroup pids, err = getCgroupProcs(dir) if err != nil { continue } pidsToKill.Insert(pids...) // WalkFunc which is called for each file and directory in the pod cgroup dir visitor := func(path string, info os.FileInfo, err error) error { if !info.IsDir() { return nil } pids, err = getCgroupProcs(path) if err != nil { glog.V(5).Infof("cgroup manager encountered error getting procs for cgroup path %v", path) return filepath.SkipDir } pidsToKill.Insert(pids...) return nil } // Walk through the pod cgroup directory to check if // container cgroups haven't been GCed yet. Get attached processes to // all such unwanted containers under the pod cgroup if err = filepath.Walk(dir, visitor); err != nil { glog.V(5).Infof("cgroup manager encountered error scanning pids for directory: %v", dir) } } return pidsToKill.List() }
func (plugin *kubenetNetworkPlugin) Capabilities() utilsets.Int { return utilsets.NewInt(network.NET_PLUGIN_CAPABILITY_SHAPING) }
func (plugin *NoopNetworkPlugin) Capabilities() utilsets.Int { return utilsets.NewInt() }
package restclient import ( "net/url" "time" "github.com/golang/glog" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/pkg/util/flowcontrol" ) // Set of resp. Codes that we backoff for. // In general these should be errors that indicate a server is overloaded. // These shouldn't be configured by any user, we set them based on conventions // described in var serverIsOverloadedSet = sets.NewInt(429) var maxResponseCode = 499 type BackoffManager interface { UpdateBackoff(actualUrl *url.URL, err error, responseCode int) CalculateBackoff(actualUrl *url.URL) time.Duration Sleep(d time.Duration) } // URLBackoff struct implements the semantics on top of Backoff which // we need for URL specific exponential backoff. type URLBackoff struct { // Uses backoff as underlying implementation. Backoff *flowcontrol.Backoff }