@@ -18,6 +18,7 @@ package nodeorder
18
18
19
19
import (
20
20
"fmt"
21
+ "strconv"
21
22
22
23
"github.com/golang/glog"
23
24
@@ -155,9 +156,92 @@ func (pp *nodeOrderPlugin) Name() string {
155
156
return "nodeorder"
156
157
}
157
158
159
+ type priorityWeight struct {
160
+ leastReqWeight int
161
+ nodeAffinityWeight int
162
+ podAffinityWeight int
163
+ balancedRescourceWeight int
164
+ }
165
+
166
+ func calculateWeight (args map [string ]string ) priorityWeight {
167
+ /*
168
+ User Should give priorityWeight in this format(nodeaffinity.weight, podaffinity.weight, leastrequested.weight, balancedresource.weight).
169
+ Currently supported only for nodeaffinity, podaffinity, leastrequested, balancedresouce priorities.
170
+
171
+ actions: "reclaim, allocate, backfill, preempt"
172
+ tiers:
173
+ - plugins:
174
+ - name: priority
175
+ - name: gang
176
+ - name: conformance
177
+ - plugins:
178
+ - name: drf
179
+ - name: predicates
180
+ - name: proportion
181
+ - name: nodeorder
182
+ arguments:
183
+ nodeaffinity.weight: 2
184
+ podaffinity.weight: 2
185
+ leastrequested.weight: 2
186
+ balancedresource.weight: 2
187
+ */
188
+
189
+ // Values are initialized to 1.
190
+ weight := priorityWeight {
191
+ leastReqWeight : 1 ,
192
+ nodeAffinityWeight : 1 ,
193
+ podAffinityWeight : 1 ,
194
+ balancedRescourceWeight : 1 ,
195
+ }
196
+
197
+ // Checks whether nodeaffinity.weight is provided or not, if given, modifies the value in weight struct.
198
+ if args ["nodeaffinity.weight" ] != "" {
199
+ val , err := strconv .Atoi (args ["nodeaffinity.weight" ])
200
+ if err != nil {
201
+ glog .Warningf ("Not able to Parse Weight for %v because of error: %v" , args ["nodeaffinity.weight" ], err )
202
+ } else {
203
+ weight .nodeAffinityWeight = val
204
+ }
205
+ }
206
+
207
+ // Checks whether podaffinity.weight is provided or not, if given, modifies the value in weight struct.
208
+ if args ["podaffinity.weight" ] != "" {
209
+ val , err := strconv .Atoi (args ["podaffinity.weight" ])
210
+ if err != nil {
211
+ glog .Warningf ("Not able to Parse Weight for %v because of error: %v" , args ["podaffinity.weight" ], err )
212
+ } else {
213
+ weight .podAffinityWeight = val
214
+ }
215
+ }
216
+
217
+ // Checks whether leastrequested.weight is provided or not, if given, modifies the value in weight struct.
218
+ if args ["leastrequested.weight" ] != "" {
219
+ val , err := strconv .Atoi (args ["leastrequested.weight" ])
220
+ if err != nil {
221
+ glog .Warningf ("Not able to Parse Weight for %v because of error: %v" , args ["leastrequested.weight" ], err )
222
+ } else {
223
+ weight .leastReqWeight = val
224
+ }
225
+ }
226
+
227
+ // Checks whether balancedresource.weight is provided or not, if given, modifies the value in weight struct.
228
+ if args ["balancedresource.weight" ] != "" {
229
+ val , err := strconv .Atoi (args ["balancedresource.weight" ])
230
+ if err != nil {
231
+ glog .Warningf ("Not able to Parse Weight for %v because of error: %v" , args ["balancedresource.weight" ], err )
232
+ } else {
233
+ weight .balancedRescourceWeight = val
234
+ }
235
+ }
236
+
237
+ return weight
238
+ }
239
+
158
240
func (pp * nodeOrderPlugin ) OnSessionOpen (ssn * framework.Session ) {
159
241
nodeOrderFn := func (task * api.TaskInfo , node * api.NodeInfo ) (int , error ) {
160
242
243
+ weight := calculateWeight (pp .pluginArguments )
244
+
161
245
pl := & podLister {
162
246
session : ssn ,
163
247
}
@@ -188,21 +272,24 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
188
272
glog .Warningf ("Least Requested Priority Failed because of Error: %v" , err )
189
273
return 0 , err
190
274
}
191
- score = score + host .Score
275
+ // If leastReqWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
276
+ score = score + (host .Score * weight .leastReqWeight )
192
277
193
278
host , err = priorities .BalancedResourceAllocationMap (task .Pod , nil , nodeInfo )
194
279
if err != nil {
195
280
glog .Warningf ("Balanced Resource Allocation Priority Failed because of Error: %v" , err )
196
281
return 0 , err
197
282
}
198
- score = score + host .Score
283
+ // If balancedRescourceWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
284
+ score = score + (host .Score * weight .balancedRescourceWeight )
199
285
200
286
host , err = priorities .CalculateNodeAffinityPriorityMap (task .Pod , nil , nodeInfo )
201
287
if err != nil {
202
288
glog .Warningf ("Calculate Node Affinity Priority Failed because of Error: %v" , err )
203
289
return 0 , err
204
290
}
205
- score = score + host .Score
291
+ // If nodeAffinityWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
292
+ score = score + (host .Score * weight .nodeAffinityWeight )
206
293
207
294
mapFn := priorities .NewInterPodAffinityPriority (cn , nl , pl , v1 .DefaultHardPodAffinitySymmetricWeight )
208
295
interPodAffinityScore , err = mapFn (task .Pod , nodeMap , nodeSlice )
@@ -211,7 +298,8 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
211
298
return 0 , err
212
299
}
213
300
hostScore := getInterPodAffinityScore (node .Name , interPodAffinityScore )
214
- score = score + hostScore
301
+ // If podAffinityWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
302
+ score = score + (hostScore * weight .podAffinityWeight )
215
303
216
304
glog .V (4 ).Infof ("Total Score for that node is: %d" , score )
217
305
return score , nil
0 commit comments