Skip to content

Commit 4ca4725

Browse files
committed
node: disable resource managers when pod-level resources are enabled
When pod-level resources are detected, the cpu and memory manages cannot engage because the feature is not yet compatible, one of the main reasons being the managers only work at container level. So, the managers has to detect if pod level resources are in use, and turn themselves to no-operation skipping resource allocation should that be the case. We add an intentional loud log to inform the user, because pods with pod-level resources landing on a node which cannot actuate the desired spec is likely to be undesirable. Signed-off-by: Francesco Romani <[email protected]>
1 parent 15b1a7f commit 4ca4725

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

pkg/kubelet/cm/cpumanager/policy_static.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
v1 "k8s.io/api/core/v1"
2424
utilfeature "k8s.io/apiserver/pkg/util/feature"
25+
resourcehelper "k8s.io/component-helpers/resource"
2526
"k8s.io/klog/v2"
2627
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
2728
v1qos "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
@@ -320,6 +321,11 @@ func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Contai
320321
return nil
321322
}
322323

324+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
325+
klog.V(2).InfoS("CPU Manager allocation skipped, pod is using pod-level resources which are not supported by the static CPU manager policy", "pod", klog.KObj(pod), "podUID", pod.UID)
326+
return nil
327+
}
328+
323329
klog.InfoS("Static policy: Allocate", "pod", klog.KObj(pod), "containerName", container.Name)
324330
// container belongs in an exclusively allocated pool
325331
metrics.CPUManagerPinningRequestsTotal.Inc()
@@ -557,6 +563,11 @@ func (p *staticPolicy) GetTopologyHints(s state.State, pod *v1.Pod, container *v
557563
return nil
558564
}
559565

566+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
567+
klog.V(3).InfoS("CPU Manager hint generation skipped, pod is using pod-level resources which are not supported by the static CPU manager policy", "pod", klog.KObj(pod), "podUID", pod.UID)
568+
return nil
569+
}
570+
560571
// Short circuit to regenerate the same hints if there are already
561572
// guaranteed CPUs allocated to the Container. This might happen after a
562573
// kubelet restart, for example.
@@ -604,6 +615,11 @@ func (p *staticPolicy) GetPodTopologyHints(s state.State, pod *v1.Pod) map[strin
604615
return nil
605616
}
606617

618+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
619+
klog.V(3).InfoS("CPU Manager pod hint generation skipped, pod is using pod-level resources which are not supported by the static CPU manager policy", "pod", klog.KObj(pod), "podUID", pod.UID)
620+
return nil
621+
}
622+
607623
assignedCPUs := cpuset.New()
608624
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
609625
requestedByContainer := p.guaranteedCPUs(pod, &container)

pkg/kubelet/cm/memorymanager/policy_static.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
v1 "k8s.io/api/core/v1"
2828
"k8s.io/apimachinery/pkg/api/resource"
2929
utilfeature "k8s.io/apiserver/pkg/util/feature"
30+
resourcehelper "k8s.io/component-helpers/resource"
3031
"k8s.io/klog/v2"
3132
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3233
corehelper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
@@ -108,6 +109,11 @@ func (p *staticPolicy) Allocate(ctx context.Context, s state.State, pod *v1.Pod,
108109
}
109110

110111
podUID := string(pod.UID)
112+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
113+
logger.V(2).Info("Allocation skipped, pod is using pod-level resources which are not supported by the static Memory manager policy", "podUID", podUID)
114+
return nil
115+
}
116+
111117
logger.Info("Allocate")
112118
// container belongs in an exclusively allocated pool
113119
metrics.MemoryManagerPinningRequestTotal.Inc()
@@ -412,6 +418,11 @@ func (p *staticPolicy) GetPodTopologyHints(ctx context.Context, s state.State, p
412418
return nil
413419
}
414420

421+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
422+
logger.V(3).Info("Topology hints generation skipped, pod is using pod-level resources which are not supported by the static Memory manager policy", "podUID", pod.UID)
423+
return nil
424+
}
425+
415426
for _, ctn := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
416427
containerBlocks := s.GetMemoryBlocks(string(pod.UID), ctn.Name)
417428
// Short circuit to regenerate the same hints if there are already
@@ -442,6 +453,11 @@ func (p *staticPolicy) GetTopologyHints(ctx context.Context, s state.State, pod
442453
return nil
443454
}
444455

456+
if utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && resourcehelper.IsPodLevelResourcesSet(pod) {
457+
logger.V(3).Info("Topology hints generation skipped, pod is using pod-level resources which are not supported by the static Memory manager policy", "podUID", pod.UID)
458+
return nil
459+
}
460+
445461
containerBlocks := s.GetMemoryBlocks(string(pod.UID), container.Name)
446462
// Short circuit to regenerate the same hints if there are already
447463
// memory allocated for the container. This might happen after a

pkg/kubelet/cm/memorymanager/policy_static_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
20742074
pod: getPodWithPodLevelResources("pod1", podLevelRequirementsGuaranteed, "container1", requirementsGuaranteed),
20752075
expectedTopologyHints: nil,
20762076
topologyHint: &topologymanager.TopologyHint{},
2077-
expectedError: fmt.Errorf("Memory Manager static policy does not support pod-level resources"),
2077+
expectedError: nil,
20782078
podLevelResourcesEnabled: true,
20792079
},
20802080
}

0 commit comments

Comments
 (0)