@@ -243,20 +243,12 @@ func onAdd(obj interface{}) {
243
243
if aw .Status .State == arbv1 .AppWrapperStateEnqueued || aw .Status .State == "" && aw .Labels ["orderedinstance" ] != "" {
244
244
//scaledAppwrapper = append(scaledAppwrapper, aw.Name)
245
245
demandPerInstanceType := discoverInstanceTypes (aw )
246
- //TODO: simplify the looping
246
+
247
247
if demandPerInstanceType != nil {
248
- if useMachineSets {
249
- if canScaleMachineset (demandPerInstanceType ) {
250
- scaleUp (aw , demandPerInstanceType )
251
- } else {
252
- klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
253
- }
248
+ if (useMachineSets && canScaleMachineset (demandPerInstanceType )) || (! useMachineSets && canScaleMachinepool (demandPerInstanceType )) {
249
+ scaleUp (aw , demandPerInstanceType )
254
250
} else {
255
- if canScaleMachinepool (demandPerInstanceType ) {
256
- scaleUp (aw , demandPerInstanceType )
257
- } else {
258
- klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
259
- }
251
+ klog .Infof ("Cannot scale up replicas. The maximum allowed replicas is %v" , maxScaleNodesAllowed )
260
252
}
261
253
}
262
254
}
@@ -271,9 +263,11 @@ func onUpdate(old, new interface{}) {
271
263
klog .Info ("Job completed, deleting resources owned" )
272
264
deleteMachineSet (aw )
273
265
}
266
+
274
267
if contains (scaledAppwrapper , aw .Name ) {
275
268
return
276
269
}
270
+
277
271
pending , aw := IsAwPending ()
278
272
if pending {
279
273
demandPerInstanceType := discoverInstanceTypes (aw )
@@ -283,9 +277,7 @@ func onUpdate(old, new interface{}) {
283
277
klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
284
278
}
285
279
}
286
-
287
280
}
288
-
289
281
}
290
282
291
283
func discoverInstanceTypes (aw * arbv1.AppWrapper ) map [string ]int {
@@ -344,11 +336,13 @@ func IsAwPending() (false bool, aw *arbv1.AppWrapper) {
344
336
if err != nil {
345
337
klog .Fatalf ("Error listing: %v" , err )
346
338
}
339
+
347
340
for _ , aw := range queuedJobs {
348
341
//skip
349
342
if contains (scaledAppwrapper , aw .Name ) {
350
343
continue
351
344
}
345
+
352
346
status := aw .Status .State
353
347
allconditions := aw .Status .Conditions
354
348
for _ , condition := range allconditions {
@@ -381,13 +375,9 @@ func findExactMatch(aw *arbv1.AppWrapper) *arbv1.AppWrapper {
381
375
if eachAw .Status .State != "Pending" {
382
376
continue
383
377
}
384
- for k , v := range eachAw .Labels {
385
- if k == "orderedinstance" {
386
- if v == existingAcquiredMachineTypes {
387
- match = eachAw
388
- klog .Infof ("Found exact match, %v appwrapper has acquire machinetypes %v" , eachAw .Name , existingAcquiredMachineTypes )
389
- }
390
- }
378
+ if eachAw .Labels ["orderedinstance" ] == existingAcquiredMachineTypes {
379
+ match = eachAw
380
+ klog .Infof ("Found exact match, %v appwrapper has acquired machinetypes %v" , eachAw .Name , existingAcquiredMachineTypes )
391
381
}
392
382
}
393
383
return match
@@ -405,7 +395,6 @@ func onDelete(obj interface{}) {
405
395
swapNodeLabels (aw , matchedAw )
406
396
} else {
407
397
klog .Infof ("Appwrapper %s deleted, scaling down machines" , aw .Name )
408
-
409
398
scaleDown (aw )
410
399
}
411
400
} else {
0 commit comments