mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 04:52:08 +00:00
kubelet/userns: Remove alpha maxPods limitation
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
parent
4180284dc9
commit
39c6815676
@ -58,7 +58,6 @@ type UsernsManager struct {
|
|||||||
used *allocator.AllocationBitmap
|
used *allocator.AllocationBitmap
|
||||||
usedBy map[types.UID]uint32 // Map pod.UID to range used
|
usedBy map[types.UID]uint32 // Map pod.UID to range used
|
||||||
removed int
|
removed int
|
||||||
numAllocated int
|
|
||||||
|
|
||||||
off int
|
off int
|
||||||
len int
|
len int
|
||||||
@ -216,16 +215,6 @@ func (m *UsernsManager) isSet(v uint32) bool {
|
|||||||
// The first return value is the first ID in the user namespace, the second returns
|
// The first return value is the first ID in the user namespace, the second returns
|
||||||
// the length for the user namespace range.
|
// the length for the user namespace range.
|
||||||
func (m *UsernsManager) allocateOne(pod types.UID) (firstID uint32, length uint32, err error) {
|
func (m *UsernsManager) allocateOne(pod types.UID) (firstID uint32, length uint32, err error) {
|
||||||
if m.numAllocated >= maxPods {
|
|
||||||
return 0, 0, fmt.Errorf("limit on count of pods with user namespaces exceeded (limit is %v, current pods with userns: %v)", maxPods, m.numAllocated)
|
|
||||||
}
|
|
||||||
m.numAllocated++
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
m.numAllocated--
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
firstZero, found, err := m.used.AllocateNext()
|
firstZero, found, err := m.used.AllocateNext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
@ -265,15 +254,6 @@ func (m *UsernsManager) record(pod types.UID, from, length uint32) (err error) {
|
|||||||
if found && prevFrom == from {
|
if found && prevFrom == from {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if m.numAllocated >= maxPods {
|
|
||||||
return fmt.Errorf("limit on count of pods with user namespaces exceeded (limit is %v, current pods with userns: %v)", maxPods, m.numAllocated)
|
|
||||||
}
|
|
||||||
m.numAllocated++
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
m.numAllocated--
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
klog.V(5).InfoS("new pod user namespace allocation", "podUID", pod)
|
klog.V(5).InfoS("new pod user namespace allocation", "podUID", pod)
|
||||||
|
|
||||||
@ -318,7 +298,6 @@ func (m *UsernsManager) releaseWithLock(pod types.UID) {
|
|||||||
delete(m.usedBy, pod)
|
delete(m.usedBy, pod)
|
||||||
|
|
||||||
klog.V(5).InfoS("releasing pod user namespace allocation", "podUID", pod)
|
klog.V(5).InfoS("releasing pod user namespace allocation", "podUID", pod)
|
||||||
m.numAllocated--
|
|
||||||
m.removed++
|
m.removed++
|
||||||
|
|
||||||
_ = os.Remove(filepath.Join(m.kl.GetPodDir(pod), mappingsFile))
|
_ = os.Remove(filepath.Join(m.kl.GetPodDir(pod), mappingsFile))
|
||||||
|
@ -378,42 +378,6 @@ func TestCleanupOrphanedPodUsernsAllocations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocateMaxPods(t *testing.T) {
|
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
|
||||||
|
|
||||||
testUserNsPodsManager := &testUserNsPodsManager{}
|
|
||||||
m, err := MakeUserNsManager(testUserNsPodsManager)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// The first maxPods allocations should succeed.
|
|
||||||
for i := 0; i < maxPods; i++ {
|
|
||||||
_, _, err = m.allocateOne(types.UID(fmt.Sprintf("%d", i)))
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The next allocation should fail, hitting maxPods.
|
|
||||||
_, _, err = m.allocateOne(types.UID(fmt.Sprintf("%d", maxPods+1)))
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRecordMaxPods(t *testing.T) {
|
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
|
||||||
|
|
||||||
testUserNsPodsManager := &testUserNsPodsManager{}
|
|
||||||
m, err := MakeUserNsManager(testUserNsPodsManager)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// The first maxPods allocations should succeed.
|
|
||||||
for i := 0; i < maxPods; i++ {
|
|
||||||
err = m.record(types.UID(fmt.Sprintf("%d", i)), uint32((i+1)*65536), 65536)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The next allocation should fail, hitting maxPods.
|
|
||||||
err = m.record(types.UID(fmt.Sprintf("%d", maxPods+1)), uint32((maxPods+1)*65536), 65536)
|
|
||||||
assert.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
type failingUserNsPodsManager struct {
|
type failingUserNsPodsManager struct {
|
||||||
testUserNsPodsManager
|
testUserNsPodsManager
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user