Skip to content

Commit ea5942d

Browse files
VanillaSpoonopenshift-merge-robot
authored andcommitted
refactor: appwrapper_controller.go
1 parent c686b6f commit ea5942d

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

controllers/appwrapper_controller.go

+11-22
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,12 @@ func onAdd(obj interface{}) {
243243
if aw.Status.State == arbv1.AppWrapperStateEnqueued || aw.Status.State == "" && aw.Labels["orderedinstance"] != "" {
244244
//scaledAppwrapper = append(scaledAppwrapper, aw.Name)
245245
demandPerInstanceType := discoverInstanceTypes(aw)
246-
//TODO: simplify the looping
246+
247247
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)
254250
} 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)
260252
}
261253
}
262254
}
@@ -271,9 +263,11 @@ func onUpdate(old, new interface{}) {
271263
klog.Info("Job completed, deleting resources owned")
272264
deleteMachineSet(aw)
273265
}
266+
274267
if contains(scaledAppwrapper, aw.Name) {
275268
return
276269
}
270+
277271
pending, aw := IsAwPending()
278272
if pending {
279273
demandPerInstanceType := discoverInstanceTypes(aw)
@@ -283,9 +277,7 @@ func onUpdate(old, new interface{}) {
283277
klog.Infof("Cannot scale up replicas max replicas allowed is %v", maxScaleNodesAllowed)
284278
}
285279
}
286-
287280
}
288-
289281
}
290282

291283
func discoverInstanceTypes(aw *arbv1.AppWrapper) map[string]int {
@@ -344,11 +336,13 @@ func IsAwPending() (false bool, aw *arbv1.AppWrapper) {
344336
if err != nil {
345337
klog.Fatalf("Error listing: %v", err)
346338
}
339+
347340
for _, aw := range queuedJobs {
348341
//skip
349342
if contains(scaledAppwrapper, aw.Name) {
350343
continue
351344
}
345+
352346
status := aw.Status.State
353347
allconditions := aw.Status.Conditions
354348
for _, condition := range allconditions {
@@ -381,13 +375,9 @@ func findExactMatch(aw *arbv1.AppWrapper) *arbv1.AppWrapper {
381375
if eachAw.Status.State != "Pending" {
382376
continue
383377
}
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)
391381
}
392382
}
393383
return match
@@ -405,7 +395,6 @@ func onDelete(obj interface{}) {
405395
swapNodeLabels(aw, matchedAw)
406396
} else {
407397
klog.Infof("Appwrapper %s deleted, scaling down machines", aw.Name)
408-
409398
scaleDown(aw)
410399
}
411400
} else {

0 commit comments

Comments
 (0)