@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
22
22
v1 "k8s.io/api/core/v1"
23
- "k8s.io/apimachinery/pkg/api/resource"
24
23
"k8s.io/klog/v2"
25
24
v1qos "k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
26
25
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
@@ -55,32 +54,38 @@ func singleNUMAContainerLevelHandler(lh logr.Logger, pod *v1.Pod, zones topology
55
54
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#understanding-init-containers
56
55
// therefore, we don't need to accumulate their resources together
57
56
for _ , initContainer := range pod .Spec .InitContainers {
58
- lh .V (6 ).Info ("init container desired resources" , stringify .ResourceListToLoggable (initContainer .Resources .Requests )... )
57
+ // TODO: handle sidecar explicitely (new kind)
58
+ clh := lh .WithValues (logging .KeyContainer , initContainer .Name , logging .KeyContainerKind , logging .KindContainerInit )
59
+ clh .V (6 ).Info ("desired resources" , stringify .ResourceListToLoggable (initContainer .Resources .Requests )... )
59
60
60
- _ , match := resourcesAvailableInAnyNUMANodes (lh , nodes , initContainer .Resources .Requests , qos , nodeInfo )
61
+ _ , match := resourcesAvailableInAnyNUMANodes (clh , nodes , initContainer .Resources .Requests , qos , nodeInfo )
61
62
if ! match {
62
63
// we can't align init container, so definitely we can't align a pod
63
- lh .V (2 ).Info ("cannot align container" , "name" , initContainer . Name , "kind" , "init " )
64
+ clh .V (2 ).Info ("cannot align container" )
64
65
return framework .NewStatus (framework .Unschedulable , "cannot align init container" )
65
66
}
66
67
}
67
68
68
69
for _ , container := range pod .Spec .Containers {
69
- // TODO: add containerName
70
- lh .V (6 ).Info ("app container resources " , stringify .ResourceListToLoggable (container .Resources .Requests )... )
70
+ clh := lh . WithValues ( logging . KeyContainer , container . Name , logging . KeyContainerKind , logging . KindContainerApp )
71
+ clh .V (6 ).Info ("container requests " , stringify .ResourceListToLoggable (container .Resources .Requests )... )
71
72
72
- numaID , match := resourcesAvailableInAnyNUMANodes (lh , nodes , container .Resources .Requests , qos , nodeInfo )
73
+ numaID , match := resourcesAvailableInAnyNUMANodes (clh , nodes , container .Resources .Requests , qos , nodeInfo )
73
74
if ! match {
74
75
// we can't align container, so definitely we can't align a pod
75
- lh .V (2 ).Info ("cannot align container" , "name" , container . Name , "kind" , "app " )
76
+ clh .V (2 ).Info ("cannot align container" )
76
77
return framework .NewStatus (framework .Unschedulable , "cannot align container" )
77
78
}
78
79
79
80
// subtract the resources requested by the container from the given NUMA.
80
81
// this is necessary, so we won't allocate the same resources for the upcoming containers
81
- subtractFromNUMA (lh , nodes , numaID , container )
82
+ err := subtractResourcesFromNUMANodeList (clh , nodes , numaID , qos , container .Resources .Requests )
83
+ if err != nil {
84
+ // this is an internal error which should never happen
85
+ return framework .NewStatus (framework .Error , "inconsistent resource accounting" , err .Error ())
86
+ }
87
+ clh .V (4 ).Info ("container aligned" , "numaCell" , numaID )
82
88
}
83
- lh .V (2 ).Info ("can align all containers" )
84
89
return nil
85
90
}
86
91
@@ -150,17 +155,10 @@ func resourcesAvailableInAnyNUMANodes(lh logr.Logger, numaNodes NUMANodeList, re
150
155
151
156
// at least one NUMA node is available
152
157
ret := ! bitmask .IsEmpty ()
153
- lh .V (2 ).Info ("final verdict" , "suitable" , ret )
158
+ lh .V (2 ).Info ("final verdict" , "suitable" , ret , "numaCell" , numaID )
154
159
return numaID , ret
155
160
}
156
161
157
- func isResourceSetSuitable (qos v1.PodQOSClass , resource v1.ResourceName , quantity , numaQuantity resource.Quantity ) bool {
158
- if qos != v1 .PodQOSGuaranteed && isNUMAAffineResource (resource ) {
159
- return true
160
- }
161
- return numaQuantity .Cmp (quantity ) >= 0
162
- }
163
-
164
162
func singleNUMAPodLevelHandler (lh logr.Logger , pod * v1.Pod , zones topologyv1alpha2.ZoneList , nodeInfo * framework.NodeInfo ) * framework.Status {
165
163
lh .V (5 ).Info ("pod level single NUMA node handler" )
166
164
@@ -172,11 +170,12 @@ func singleNUMAPodLevelHandler(lh logr.Logger, pod *v1.Pod, zones topologyv1alph
172
170
logNumaNodes (lh , "pod handler NUMA resources" , nodeInfo .Node ().Name , nodes )
173
171
lh .V (6 ).Info ("pod desired resources" , stringify .ResourceListToLoggable (resources )... )
174
172
175
- if _ , match := resourcesAvailableInAnyNUMANodes (lh , createNUMANodeList (lh , zones ), resources , v1qos .GetPodQOS (pod ), nodeInfo ); ! match {
173
+ numaID , match := resourcesAvailableInAnyNUMANodes (lh , createNUMANodeList (lh , zones ), resources , v1qos .GetPodQOS (pod ), nodeInfo )
174
+ if ! match {
176
175
lh .V (2 ).Info ("cannot align pod" , "name" , pod .Name )
177
176
return framework .NewStatus (framework .Unschedulable , "cannot align pod" )
178
177
}
179
- lh .V (2 ).Info ("can align pod" )
178
+ lh .V (4 ).Info ("all container placed" , "numaCell" , numaID )
180
179
return nil
181
180
}
182
181
@@ -218,28 +217,6 @@ func (tm *TopologyMatch) Filter(ctx context.Context, cycleState *framework.Cycle
218
217
return status
219
218
}
220
219
221
- // subtractFromNUMA finds the correct NUMA ID's resources and subtract them from `nodes`.
222
- func subtractFromNUMA (lh logr.Logger , nodes NUMANodeList , numaID int , container v1.Container ) {
223
- for i := 0 ; i < len (nodes ); i ++ {
224
- if nodes [i ].NUMAID != numaID {
225
- continue
226
- }
227
-
228
- nRes := nodes [i ].Resources
229
- for resName , quan := range container .Resources .Requests {
230
- nodeResQuan := nRes [resName ]
231
- nodeResQuan .Sub (quan )
232
- // we do not expect a negative value here, since this function only called
233
- // when resourcesAvailableInAnyNUMANodes function is passed
234
- // but let's log here if such unlikely case will occur
235
- if nodeResQuan .Sign () == - 1 {
236
- lh .V (4 ).Info ("resource quantity should not be a negative value" , "resource" , resName , "quantity" , nodeResQuan .String ())
237
- }
238
- nRes [resName ] = nodeResQuan
239
- }
240
- }
241
- }
242
-
243
220
func filterHandlerFromTopologyManagerConfig (conf TopologyManagerConfig ) filterFn {
244
221
if conf .Policy != kubeletconfig .SingleNumaNodeTopologyManagerPolicy {
245
222
return nil
0 commit comments