@@ -45,8 +45,9 @@ import (
4545// AppWrapperReconciler reconciles a AppWrapper object
4646type AppWrapperReconciler struct {
4747 client.Client
48- Scheme * runtime.Scheme
49- ConfigsNamespace string
48+ Scheme * runtime.Scheme
49+ ConfigsNamespace string
50+ OcmSecretNamespace string
5051}
5152
5253var (
@@ -149,36 +150,49 @@ func (r *AppWrapperReconciler) SetupWithManager(mgr ctrl.Manager) error {
149150 instascaleConfigmap , err := kubeClient .CoreV1 ().ConfigMaps (r .ConfigsNamespace ).Get (context .Background (), "instascale-config" , metav1.GetOptions {})
150151 if err != nil {
151152 klog .Infof ("Config map named instascale-config is not available in namespace %v" , r .ConfigsNamespace )
153+ return err
152154 }
153155
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 )
156159 maxScaleNodesAllowed = 3
157160 }
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+ }
159164
160165 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 ()
168169
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 )
173175 }
174- ocmToken = string (instascaleOCMSecret .Data ["token" ])
175176 }
176177
177178 return ctrl .NewControllerManagedBy (mgr ).
178179 For (& arbv1.AppWrapper {}).
179180 Complete (r )
180181}
181182
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+
182196func addAppwrappersThatNeedScaling () {
183197 kubeconfig := os .Getenv ("KUBECONFIG" )
184198 restConfig , err := getRestConfig (kubeconfig )
@@ -223,28 +237,27 @@ func onAdd(obj interface{}) {
223237 aw , ok := obj .(* arbv1.AppWrapper )
224238 if ok {
225239 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" ] != "" {
227241 //scaledAppwrapper = append(scaledAppwrapper, aw.Name)
228242 demandPerInstanceType := discoverInstanceTypes (aw )
229243 //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+ }
233251 } 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+ }
241257 }
242258 }
243-
244259 }
245-
246260 }
247-
248261}
249262
250263func onUpdate (old , new interface {}) {
0 commit comments