@@ -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"
@@ -38,7 +39,12 @@ import (
3839 "k8s.io/kubernetes/pkg/kubelet/metrics"
3940)
4041
41- const PolicyTypeStatic policyType = "Static"
42+ const (
43+ PolicyTypeStatic policyType = "Static"
44+
45+ // ErrorMemoryManagerPodLevelResources represents the type of a MemoryManagerPodLevelResourcesError
46+ ErrorMemoryManagerPodLevelResources = "MemoryManagerPodLevelResourcesError"
47+ )
4248
4349type systemReservedMemory map [int ]map [v1.ResourceName ]uint64
4450type reusableMemory map [string ]map [string ]map [v1.ResourceName ]uint64
@@ -60,6 +66,16 @@ type staticPolicy struct {
6066
6167var _ Policy = & staticPolicy {}
6268
69+ type MemoryManagerPodLevelResourcesError struct {}
70+
71+ func (e MemoryManagerPodLevelResourcesError ) Type () string {
72+ return ErrorMemoryManagerPodLevelResources
73+ }
74+
75+ func (e MemoryManagerPodLevelResourcesError ) Error () string {
76+ return "Memory Manager static policy does not support pod-level resources"
77+ }
78+
6379// NewPolicyStatic returns new static policy instance
6480func NewPolicyStatic (ctx context.Context , machineInfo * cadvisorapi.MachineInfo , reserved systemReservedMemory , affinity topologymanager.Store ) (Policy , error ) {
6581 var totalSystemReserved uint64
@@ -107,6 +123,10 @@ func (p *staticPolicy) Allocate(ctx context.Context, s state.State, pod *v1.Pod,
107123 return nil
108124 }
109125
126+ if p .isPodWithPodLevelResources (ctx , pod ) {
127+ return MemoryManagerPodLevelResourcesError {}
128+ }
129+
110130 podUID := string (pod .UID )
111131 logger .Info ("Allocate" )
112132 // container belongs in an exclusively allocated pool
@@ -406,6 +426,10 @@ func (p *staticPolicy) GetPodTopologyHints(ctx context.Context, s state.State, p
406426 return nil
407427 }
408428
429+ if p .isPodWithPodLevelResources (ctx , pod ) {
430+ return nil
431+ }
432+
409433 reqRsrcs , err := getPodRequestedResources (pod )
410434 if err != nil {
411435 logger .Error (err , "Failed to get pod requested resources" , "podUID" , pod .UID )
@@ -436,6 +460,10 @@ func (p *staticPolicy) GetTopologyHints(ctx context.Context, s state.State, pod
436460 return nil
437461 }
438462
463+ if p .isPodWithPodLevelResources (ctx , pod ) {
464+ return nil
465+ }
466+
439467 requestedResources , err := getRequestedResources (pod , container )
440468 if err != nil {
441469 logger .Error (err , "Failed to get container requested resources" , "podUID" , pod .UID , "containerName" , container .Name )
@@ -1076,3 +1104,16 @@ func isAffinityViolatingNUMAAllocations(machineState state.NUMANodeMap, mask bit
10761104 }
10771105 return false
10781106}
1107+
1108+ func (p * staticPolicy ) isPodWithPodLevelResources (ctx context.Context , pod * v1.Pod ) bool {
1109+ logger := klog .FromContext (ctx )
1110+
1111+ if utilfeature .DefaultFeatureGate .Enabled (features .PodLevelResources ) && resourcehelper .IsPodLevelResourcesSet (pod ) {
1112+ // The Memory manager static policy does not support pod-level resources.
1113+ logger .V (5 ).Info ("Memory manager allocation skipped, pod is using pod-level resources which are not supported by the static Memory manager policy" , "pod" , klog .KObj (pod ))
1114+
1115+ return true
1116+ }
1117+
1118+ return false
1119+ }
0 commit comments