Skip to content

Commit 8743b4e

Browse files
committed
Review changes, loop issues
1 parent 12e34b8 commit 8743b4e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

controllers/appwrapper_controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,20 @@ func (r *AppWrapperReconciler) findExactMatch(ctx context.Context, aw *arbv1.App
255255
}
256256
var existingAcquiredMachineTypes = ""
257257

258+
for key, value := range aw.Labels {
259+
if key == "orderedinstance" {
260+
existingAcquiredMachineTypes = value
261+
}
262+
}
263+
258264
for _, eachAw := range appwrappers.Items {
259265
if eachAw.Status.State != arbv1.AppWrapperStateEnqueued {
260-
continue
266+
if eachAw.Labels["orderedinstance"] == existingAcquiredMachineTypes {
267+
match = &eachAw
268+
klog.Infof("Found exact match, %v appwrapper has acquired machinetypes %v", eachAw.Name, existingAcquiredMachineTypes)
269+
break
270+
}
261271
}
262-
match = &eachAw
263-
klog.Infof("Found exact match, %v appwrapper has acquired machinetypes %v", eachAw.Name, existingAcquiredMachineTypes)
264272
}
265273
return match
266274

controllers/machinepools.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ func hasAwLabel(machinePool *cmv1.MachinePool, aw *arbv1.AppWrapper) bool {
4444
}
4545

4646
func (r *AppWrapperReconciler) scaleMachinePool(ctx context.Context, aw *arbv1.AppWrapper, demandPerInstanceType map[string]int) (ctrl.Result, error) {
47+
connection, err := r.createOCMConnection()
48+
if err != nil {
49+
fmt.Fprintf(os.Stderr, "Error creating OCM connection: %v", err)
50+
return ctrl.Result{}, err
51+
}
52+
defer connection.Close()
4753
for userRequestedInstanceType := range demandPerInstanceType {
4854
replicas := demandPerInstanceType[userRequestedInstanceType]
49-
connection, err := r.createOCMConnection()
50-
if err != nil {
51-
fmt.Fprintf(os.Stderr, "Error creating OCM connection: %v", err)
52-
return ctrl.Result{}, err
53-
}
54-
defer connection.Close()
5555

5656
clusterMachinePools := connection.ClustersMgmt().V1().Clusters().Cluster(r.ocmClusterID).MachinePools()
5757

5858
response, err := clusterMachinePools.List().SendContext(ctx)
5959
if err != nil {
60-
klog.Errorf("error retrieving machine pools: %v", err)
60+
return ctrl.Result{}, err
6161
}
6262

6363
numberOfMachines := 0

0 commit comments

Comments
 (0)