@@ -45,8 +45,9 @@ import (
45
45
// AppWrapperReconciler reconciles a AppWrapper object
46
46
type AppWrapperReconciler struct {
47
47
client.Client
48
- Scheme * runtime.Scheme
49
- ConfigsNamespace string
48
+ Scheme * runtime.Scheme
49
+ ConfigsNamespace string
50
+ OcmSecretNamespace string
50
51
}
51
52
52
53
var (
@@ -149,36 +150,49 @@ func (r *AppWrapperReconciler) SetupWithManager(mgr ctrl.Manager) error {
149
150
instascaleConfigmap , err := kubeClient .CoreV1 ().ConfigMaps (r .ConfigsNamespace ).Get (context .Background (), "instascale-config" , metav1.GetOptions {})
150
151
if err != nil {
151
152
klog .Infof ("Config map named instascale-config is not available in namespace %v" , r .ConfigsNamespace )
153
+ return err
152
154
}
153
155
154
- if maxScaleNodesAllowed , err = strconv .Atoi (instascaleConfigmap .Data ["maxScaleoutAllowed" ]); err != nil {
155
- klog .Infof ("Error converting %v to int. Setting maxScaleNodesAllowed to 3" , maxScaleNodesAllowed )
156
+ maxScaleNodesAllowed , err = strconv .Atoi (instascaleConfigmap .Data ["maxScaleoutAllowed" ])
157
+ if err != nil {
158
+ klog .Warningf ("Error converting %v to int. Setting maxScaleNodesAllowed to 3" , maxScaleNodesAllowed )
156
159
maxScaleNodesAllowed = 3
157
160
}
158
- klog .Infof ("Got config map named %v from namespace %v that configures max nodes in cluster to value %v" , instascaleConfigmap .Name , instascaleConfigmap .Namespace , maxScaleNodesAllowed )
161
+ if instascaleConfigmap != nil {
162
+ klog .Errorf ("Got config map named %v from namespace %v that configures max nodes in cluster to value %v" , instascaleConfigmap .Name , instascaleConfigmap .Namespace , maxScaleNodesAllowed )
163
+ }
159
164
160
165
useMachineSets = true
161
- useMachinePools , err := strconv .ParseBool (instascaleConfigmap .Data ["useMachinePools" ])
162
- if err != nil {
163
- klog .Infof ("Error converting %v to bool. Defaulting to using Machine Sets" , useMachineSets )
164
- } else {
165
- useMachineSets = ! useMachinePools
166
- klog .Infof ("Setting useMachineSets to %v" , useMachineSets )
167
- }
166
+ ocmSecretExists := ocmSecretExists (r .OcmSecretNamespace )
167
+ if ocmSecretExists {
168
+ machinePoolsExists := machinePoolExists ()
168
169
169
- if ! useMachineSets {
170
- instascaleOCMSecret , err := kubeClient .CoreV1 ().Secrets (r .ConfigsNamespace ).Get (context .Background (), "instascale-ocm-secret" , metav1.GetOptions {})
171
- if err != nil {
172
- klog .Errorf ("Error getting instascale-ocm-secret from namespace %v - Error : %v" , r .ConfigsNamespace , err )
170
+ if machinePoolsExists {
171
+ useMachineSets = false
172
+ klog .Infof ("Using machine pools %v" , machinePoolsExists )
173
+ } else {
174
+ klog .Infof ("Setting useMachineSets to %v" , useMachineSets )
173
175
}
174
- ocmToken = string (instascaleOCMSecret .Data ["token" ])
175
176
}
176
177
177
178
return ctrl .NewControllerManagedBy (mgr ).
178
179
For (& arbv1.AppWrapper {}).
179
180
Complete (r )
180
181
}
181
182
183
+ func ocmSecretExists (namespace string ) bool {
184
+ instascaleOCMSecret , err := kubeClient .CoreV1 ().Secrets (namespace ).Get (context .Background (), "instascale-ocm-secret" , metav1.GetOptions {})
185
+ if err != nil {
186
+ klog .Errorf ("Error getting instascale-ocm-secret from namespace %v: %v" , namespace , err )
187
+ klog .Infof ("If you are looking to use OCM, ensure that the 'instascale-ocm-secret' secret is available on the cluster within namespace %v" , namespace )
188
+ klog .Infof ("Setting useMachineSets to %v." , useMachineSets )
189
+ return false
190
+ }
191
+
192
+ ocmToken = string (instascaleOCMSecret .Data ["token" ])
193
+ return true
194
+ }
195
+
182
196
func addAppwrappersThatNeedScaling () {
183
197
kubeconfig := os .Getenv ("KUBECONFIG" )
184
198
restConfig , err := getRestConfig (kubeconfig )
@@ -223,28 +237,27 @@ func onAdd(obj interface{}) {
223
237
aw , ok := obj .(* arbv1.AppWrapper )
224
238
if ok {
225
239
klog .Infof ("Found Appwrapper named %s that has status %v" , aw .Name , aw .Status .State )
226
- if aw .Status .State == arbv1 .AppWrapperStateEnqueued || aw .Status .State == "" {
240
+ if aw .Status .State == arbv1 .AppWrapperStateEnqueued || aw .Status .State == "" && aw . Labels [ "orderedinstance" ] != "" {
227
241
//scaledAppwrapper = append(scaledAppwrapper, aw.Name)
228
242
demandPerInstanceType := discoverInstanceTypes (aw )
229
243
//TODO: simplify the looping
230
- if useMachineSets {
231
- if canScaleMachineset (demandPerInstanceType ) {
232
- scaleUp (aw , demandPerInstanceType )
244
+ if demandPerInstanceType != nil {
245
+ if useMachineSets {
246
+ if canScaleMachineset (demandPerInstanceType ) {
247
+ scaleUp (aw , demandPerInstanceType )
248
+ } else {
249
+ klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
250
+ }
233
251
} else {
234
- klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
235
- }
236
- } else {
237
- if canScaleMachinepool (demandPerInstanceType ) {
238
- scaleUp (aw , demandPerInstanceType )
239
- } else {
240
- klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
252
+ if canScaleMachinepool (demandPerInstanceType ) {
253
+ scaleUp (aw , demandPerInstanceType )
254
+ } else {
255
+ klog .Infof ("Cannot scale up replicas max replicas allowed is %v" , maxScaleNodesAllowed )
256
+ }
241
257
}
242
258
}
243
-
244
259
}
245
-
246
260
}
247
-
248
261
}
249
262
250
263
func onUpdate (old , new interface {}) {
0 commit comments