@@ -30,7 +30,6 @@ import (
30
30
apiconfig "sigs.k8s.io/scheduler-plugins/apis/config"
31
31
32
32
"github.com/go-logr/logr"
33
- topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
34
33
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/logging"
35
34
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig"
36
35
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/stringify"
@@ -70,7 +69,8 @@ func (tm *TopologyMatch) Score(ctx context.Context, state *framework.CycleState,
70
69
71
70
lh .V (6 ).Info ("scoring node" )
72
71
// if it's a non-guaranteed pod, every node is considered to be a good fit
73
- if v1qos .GetPodQOS (pod ) != v1 .PodQOSGuaranteed {
72
+ qos := v1qos .GetPodQOS (pod )
73
+ if qos != v1 .PodQOSGuaranteed {
74
74
return framework .MaxNodeScore , nil
75
75
}
76
76
@@ -87,11 +87,18 @@ func (tm *TopologyMatch) Score(ctx context.Context, state *framework.CycleState,
87
87
88
88
lh .V (6 ).Info ("found object" , "noderesourcetopology" , stringify .NodeResourceTopologyResources (nodeTopology ))
89
89
90
- handler := tm .scoringHandlerFromTopologyManagerConfig (nodeconfig .TopologyManagerFromNodeResourceTopology (lh , nodeTopology ))
90
+ conf := nodeconfig .TopologyManagerFromNodeResourceTopology (lh , nodeTopology )
91
+ handler := tm .scoringHandlerFromTopologyManagerConfig (conf )
91
92
if handler == nil {
92
93
return 0 , nil
93
94
}
94
- return handler (lh , pod , nodeTopology .Zones )
95
+ numaNodes := createNUMANodeList (lh , nodeTopology .Zones )
96
+ si := scoreInfo {
97
+ topologyManager : conf ,
98
+ qos : qos ,
99
+ numaNodes : numaNodes ,
100
+ }
101
+ return handler (lh , pod , & si )
95
102
}
96
103
97
104
func (tm * TopologyMatch ) ScoreExtensions () framework.ScoreExtensions {
@@ -132,27 +139,24 @@ func getScoringStrategyFunction(strategy apiconfig.ScoringStrategyType) (scoreSt
132
139
}
133
140
}
134
141
135
- func podScopeScore (lh logr.Logger , pod * v1.Pod , zones topologyv1alpha2. ZoneList , scorerFn scoreStrategyFn , resourceToWeightMap resourceToWeightMap ) (int64 , * framework.Status ) {
142
+ func podScopeScore (lh logr.Logger , pod * v1.Pod , info * scoreInfo , scorerFn scoreStrategyFn , resourceToWeightMap resourceToWeightMap ) (int64 , * framework.Status ) {
136
143
// This code is in Admit implementation of pod scope
137
144
// https://github.com/kubernetes/kubernetes/blob/9ff3b7e744b34c099c1405d9add192adbef0b6b1/pkg/kubelet/cm/topologymanager/scope_pod.go#L52
138
145
// but it works with HintProviders, takes into account all possible allocations.
139
146
resources := util .GetPodEffectiveRequest (pod )
140
-
141
- allocatablePerNUMA := createNUMANodeList (lh , zones )
142
- finalScore := scoreForEachNUMANode (lh , resources , allocatablePerNUMA , scorerFn , resourceToWeightMap )
147
+ finalScore := scoreForEachNUMANode (lh , resources , info .numaNodes , scorerFn , resourceToWeightMap )
143
148
lh .V (2 ).Info ("pod scope scoring final node score" , "finalScore" , finalScore )
144
149
return finalScore , nil
145
150
}
146
151
147
- func containerScopeScore (lh logr.Logger , pod * v1.Pod , zones topologyv1alpha2. ZoneList , scorerFn scoreStrategyFn , resourceToWeightMap resourceToWeightMap ) (int64 , * framework.Status ) {
152
+ func containerScopeScore (lh logr.Logger , pod * v1.Pod , info * scoreInfo , scorerFn scoreStrategyFn , resourceToWeightMap resourceToWeightMap ) (int64 , * framework.Status ) {
148
153
// This code is in Admit implementation of container scope
149
154
// https://github.com/kubernetes/kubernetes/blob/9ff3b7e744b34c099c1405d9add192adbef0b6b1/pkg/kubelet/cm/topologymanager/scope_container.go#L52
150
155
containers := append (pod .Spec .InitContainers , pod .Spec .Containers ... )
151
156
contScore := make ([]float64 , len (containers ))
152
- allocatablePerNUMA := createNUMANodeList (lh , zones )
153
157
154
158
for i , container := range containers {
155
- contScore [i ] = float64 (scoreForEachNUMANode (lh , container .Resources .Requests , allocatablePerNUMA , scorerFn , resourceToWeightMap ))
159
+ contScore [i ] = float64 (scoreForEachNUMANode (lh , container .Resources .Requests , info . numaNodes , scorerFn , resourceToWeightMap ))
156
160
lh .V (6 ).Info ("container scope scoring" , "container" , container .Name , "score" , contScore [i ])
157
161
}
158
162
finalScore := int64 (stat .Mean (contScore , nil ))
@@ -174,13 +178,13 @@ func (tm *TopologyMatch) scoringHandlerFromTopologyManagerConfig(conf nodeconfig
174
178
return nil
175
179
}
176
180
if conf .Scope == kubeletconfig .PodTopologyManagerScope {
177
- return func (lh logr.Logger , pod * v1.Pod , zones topologyv1alpha2. ZoneList ) (int64 , * framework.Status ) {
178
- return podScopeScore (lh , pod , zones , tm .scoreStrategyFunc , tm .resourceToWeightMap )
181
+ return func (lh logr.Logger , pod * v1.Pod , info * scoreInfo ) (int64 , * framework.Status ) {
182
+ return podScopeScore (lh , pod , info , tm .scoreStrategyFunc , tm .resourceToWeightMap )
179
183
}
180
184
}
181
185
if conf .Scope == kubeletconfig .ContainerTopologyManagerScope {
182
- return func (lh logr.Logger , pod * v1.Pod , zones topologyv1alpha2. ZoneList ) (int64 , * framework.Status ) {
183
- return containerScopeScore (lh , pod , zones , tm .scoreStrategyFunc , tm .resourceToWeightMap )
186
+ return func (lh logr.Logger , pod * v1.Pod , info * scoreInfo ) (int64 , * framework.Status ) {
187
+ return containerScopeScore (lh , pod , info , tm .scoreStrategyFunc , tm .resourceToWeightMap )
184
188
}
185
189
}
186
190
return nil // cannot happen
0 commit comments