@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/client-go/kubernetes"
32
32
"k8s.io/klog"
33
33
34
+ "k8s.io/apimachinery/pkg/labels"
34
35
ctrl "sigs.k8s.io/controller-runtime"
35
36
"sigs.k8s.io/controller-runtime/pkg/client"
36
37
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -88,7 +89,7 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
88
89
// Only reason we are calling it here is that the client is not able to make
89
90
// calls until it is started, so SetupWithManager is not working.
90
91
if ! useMachineSets && ocmClusterID == "" {
91
- getOCMClusterID (r )
92
+ r . getOCMClusterID (ctx )
92
93
}
93
94
var appwrapper arbv1.AppWrapper
94
95
@@ -128,20 +129,20 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
128
129
if err != nil {
129
130
klog .Infof ("Error reconciling MachineSet: %s" , err )
130
131
}
131
- return res , nil
132
+ return res , err
132
133
} else {
133
134
res , err := r .reconcileCreateMachineSet (ctx , & appwrapper , demandPerInstanceType )
134
135
if err != nil {
135
136
klog .Infof ("Error reconciling MachineSet: %s" , err )
136
137
}
137
- return res , nil
138
+ return res , err
138
139
}
139
140
} else {
140
141
res , err := r .scaleMachinePool (ctx , & appwrapper , demandPerInstanceType )
141
142
if err != nil {
142
143
klog .Infof ("Error reconciling MachinePool: %s" , err )
143
144
}
144
- return res , nil
145
+ return res , err
145
146
}
146
147
}
147
148
@@ -155,11 +156,11 @@ func (r *AppWrapperReconciler) finalizeScalingDownMachines(ctx context.Context,
155
156
} else {
156
157
klog .Infof ("Appwrapper %s deleted, scaling down machines" , appwrapper .Name )
157
158
158
- r .scaleDown (ctx , appwrapper )
159
+ r .annotateToDeleteMachine (ctx , appwrapper )
159
160
}
160
161
} else {
161
162
klog .Infof ("Appwrapper deleted scale-down machineset: %s " , appwrapper .Name )
162
- r .scaleDown (ctx , appwrapper )
163
+ r .deleteMachineSet (ctx , appwrapper )
163
164
}
164
165
} else {
165
166
r .deleteMachinePool (ctx , appwrapper )
@@ -249,35 +250,31 @@ func canScaleMachinepool(demandPerInstanceType map[string]int) bool {
249
250
return true
250
251
}
251
252
252
- // add logic to check for matching pending AppWrappers
253
253
func (r * AppWrapperReconciler ) findExactMatch (ctx context.Context , aw * arbv1.AppWrapper ) * arbv1.AppWrapper {
254
254
var match * arbv1.AppWrapper = nil
255
255
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 )
257
266
if err != nil {
258
267
klog .Error ("Cannot list queued appwrappers, associated machines will be deleted" )
259
268
return match
260
269
}
261
270
var existingAcquiredMachineTypes = ""
262
271
263
- for key , value := range aw .Labels {
264
- if key == "orderedinstance" {
265
- existingAcquiredMachineTypes = value
266
- }
267
- }
268
-
269
272
for _ , eachAw := range appwrappers .Items {
270
273
if eachAw .Status .State != "Pending" {
271
274
continue
272
275
}
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 )
281
278
}
282
279
return match
283
280
0 commit comments