mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
kubelet/userns: Use kubelet maxPods
We don't have the alpha limitation anymore, let's just use the kubelet maxPods instead of our hardcoded 1024 max. Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
parent
39c6815676
commit
0b69c2bc81
@ -128,6 +128,10 @@ func (kl *Kubelet) GetKubeletMappings() (uint32, uint32, error) {
|
|||||||
return kl.getKubeletMappings()
|
return kl.getKubeletMappings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kl *Kubelet) GetMaxPods() int {
|
||||||
|
return kl.maxPods
|
||||||
|
}
|
||||||
|
|
||||||
// getPodDir returns the full path to the per-pod directory for the pod with
|
// getPodDir returns the full path to the per-pod directory for the pod with
|
||||||
// the given UID.
|
// the given UID.
|
||||||
func (kl *Kubelet) getPodDir(podUID types.UID) string {
|
func (kl *Kubelet) getPodDir(podUID types.UID) string {
|
||||||
|
@ -39,10 +39,6 @@ import (
|
|||||||
// length for the user namespace to create (65536).
|
// length for the user namespace to create (65536).
|
||||||
const userNsLength = (1 << 16)
|
const userNsLength = (1 << 16)
|
||||||
|
|
||||||
// Limit the total number of pods using userns in this node to this value.
|
|
||||||
// This is an alpha limitation that will probably be lifted later.
|
|
||||||
const maxPods = 1024
|
|
||||||
|
|
||||||
// Create a new map when we removed enough pods to avoid memory leaks
|
// Create a new map when we removed enough pods to avoid memory leaks
|
||||||
// since Go maps never free memory.
|
// since Go maps never free memory.
|
||||||
const mapReInitializeThreshold = 1000
|
const mapReInitializeThreshold = 1000
|
||||||
@ -52,6 +48,7 @@ type userNsPodsManager interface {
|
|||||||
GetPodDir(podUID types.UID) string
|
GetPodDir(podUID types.UID) string
|
||||||
ListPodsFromDisk() ([]types.UID, error)
|
ListPodsFromDisk() ([]types.UID, error)
|
||||||
GetKubeletMappings() (uint32, uint32, error)
|
GetKubeletMappings() (uint32, uint32, error)
|
||||||
|
GetMaxPods() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type UsernsManager struct {
|
type UsernsManager struct {
|
||||||
@ -148,8 +145,8 @@ func MakeUserNsManager(kl userNsPodsManager) (*UsernsManager, error) {
|
|||||||
if kubeletMappingLen%userNsLength != 0 {
|
if kubeletMappingLen%userNsLength != 0 {
|
||||||
return nil, fmt.Errorf("kubelet user assigned IDs length %v is not a multiple of %v", kubeletMappingLen, userNsLength)
|
return nil, fmt.Errorf("kubelet user assigned IDs length %v is not a multiple of %v", kubeletMappingLen, userNsLength)
|
||||||
}
|
}
|
||||||
if kubeletMappingLen/userNsLength < maxPods {
|
if kubeletMappingLen/userNsLength < uint32(kl.GetMaxPods()) {
|
||||||
return nil, fmt.Errorf("kubelet user assigned IDs are not enough to support %v pods", maxPods)
|
return nil, fmt.Errorf("kubelet user assigned IDs are not enough to support %v pods", kl.GetMaxPods())
|
||||||
}
|
}
|
||||||
off := int(kubeletMappingID / userNsLength)
|
off := int(kubeletMappingID / userNsLength)
|
||||||
len := int(kubeletMappingLen / userNsLength)
|
len := int(kubeletMappingLen / userNsLength)
|
||||||
|
@ -39,12 +39,14 @@ const (
|
|||||||
minimumMappingUID = userNsLength
|
minimumMappingUID = userNsLength
|
||||||
// allocate enough space for 2000 user namespaces
|
// allocate enough space for 2000 user namespaces
|
||||||
mappingLen = userNsLength * 2000
|
mappingLen = userNsLength * 2000
|
||||||
|
testMaxPods = 110
|
||||||
)
|
)
|
||||||
|
|
||||||
type testUserNsPodsManager struct {
|
type testUserNsPodsManager struct {
|
||||||
podDir string
|
podDir string
|
||||||
podList []types.UID
|
podList []types.UID
|
||||||
userns bool
|
userns bool
|
||||||
|
maxPods int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testUserNsPodsManager) GetPodDir(podUID types.UID) string {
|
func (m *testUserNsPodsManager) GetPodDir(podUID types.UID) string {
|
||||||
@ -72,6 +74,14 @@ func (m *testUserNsPodsManager) GetKubeletMappings() (uint32, uint32, error) {
|
|||||||
return minimumMappingUID, mappingLen, nil
|
return minimumMappingUID, mappingLen, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *testUserNsPodsManager) GetMaxPods() int {
|
||||||
|
if m.maxPods != 0 {
|
||||||
|
return m.maxPods
|
||||||
|
}
|
||||||
|
|
||||||
|
return testMaxPods
|
||||||
|
}
|
||||||
|
|
||||||
func TestUserNsManagerAllocate(t *testing.T) {
|
func TestUserNsManagerAllocate(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user