@@ -31,6 +31,7 @@ import (
3131 "k8s.io/client-go/kubernetes"
3232 "k8s.io/klog"
3333
34+ "k8s.io/apimachinery/pkg/labels"
3435 ctrl "sigs.k8s.io/controller-runtime"
3536 "sigs.k8s.io/controller-runtime/pkg/client"
3637 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -88,7 +89,7 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8889 // Only reason we are calling it here is that the client is not able to make
8990 // calls until it is started, so SetupWithManager is not working.
9091 if ! useMachineSets && ocmClusterID == "" {
91- getOCMClusterID (r )
92+ r . getOCMClusterID (ctx )
9293 }
9394 var appwrapper arbv1.AppWrapper
9495
@@ -128,20 +129,20 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
128129 if err != nil {
129130 klog .Infof ("Error reconciling MachineSet: %s" , err )
130131 }
131- return res , nil
132+ return res , err
132133 } else {
133134 res , err := r .reconcileCreateMachineSet (ctx , & appwrapper , demandPerInstanceType )
134135 if err != nil {
135136 klog .Infof ("Error reconciling MachineSet: %s" , err )
136137 }
137- return res , nil
138+ return res , err
138139 }
139140 } else {
140141 res , err := r .scaleMachinePool (ctx , & appwrapper , demandPerInstanceType )
141142 if err != nil {
142143 klog .Infof ("Error reconciling MachinePool: %s" , err )
143144 }
144- return res , nil
145+ return res , err
145146 }
146147}
147148
@@ -155,11 +156,11 @@ func (r *AppWrapperReconciler) finalizeScalingDownMachines(ctx context.Context,
155156 } else {
156157 klog .Infof ("Appwrapper %s deleted, scaling down machines" , appwrapper .Name )
157158
158- r .scaleDown (ctx , appwrapper )
159+ r .annotateToDeleteMachine (ctx , appwrapper )
159160 }
160161 } else {
161162 klog .Infof ("Appwrapper deleted scale-down machineset: %s " , appwrapper .Name )
162- r .scaleDown (ctx , appwrapper )
163+ r .deleteMachineSet (ctx , appwrapper )
163164 }
164165 } else {
165166 r .deleteMachinePool (ctx , appwrapper )
@@ -249,35 +250,31 @@ func canScaleMachinepool(demandPerInstanceType map[string]int) bool {
249250 return true
250251}
251252
252- // add logic to check for matching pending AppWrappers
253253func (r * AppWrapperReconciler ) findExactMatch (ctx context.Context , aw * arbv1.AppWrapper ) * arbv1.AppWrapper {
254254 var match * arbv1.AppWrapper = nil
255255 appwrappers := arbv1.AppWrapperList {}
256- err := r .List (ctx , & appwrappers )
256+
257+ labelSelector := labels .SelectorFromSet (labels .Set (map [string ]string {
258+ "orderedinstance" : "" ,
259+ }))
260+
261+ listOptions := & client.ListOptions {
262+ LabelSelector : labelSelector ,
263+ }
264+
265+ err := r .List (ctx , & appwrappers , listOptions )
257266 if err != nil {
258267 klog .Error ("Cannot list queued appwrappers, associated machines will be deleted" )
259268 return match
260269 }
261270 var existingAcquiredMachineTypes = ""
262271
263- for key , value := range aw .Labels {
264- if key == "orderedinstance" {
265- existingAcquiredMachineTypes = value
266- }
267- }
268-
269272 for _ , eachAw := range appwrappers .Items {
270273 if eachAw .Status .State != "Pending" {
271274 continue
272275 }
273- for k , v := range eachAw .Labels {
274- if k == "orderedinstance" {
275- if v == existingAcquiredMachineTypes {
276- match = & eachAw
277- klog .Infof ("Found exact match, %v appwrapper has acquire machinetypes %v" , eachAw .Name , existingAcquiredMachineTypes )
278- }
279- }
280- }
276+ match = & eachAw
277+ klog .Infof ("Found exact match, %v appwrapper has acquired machinetypes %v" , eachAw .Name , existingAcquiredMachineTypes )
281278 }
282279 return match
283280
0 commit comments