diff --git a/controllers/appWrapper_controller_test.go b/controllers/appWrapper_controller_test.go index b3445d9..d589ec2 100644 --- a/controllers/appWrapper_controller_test.go +++ b/controllers/appWrapper_controller_test.go @@ -1,6 +1,7 @@ package controllers import ( + "context" "testing" "github.com/onsi/gomega" @@ -10,7 +11,7 @@ import ( func (r *AppWrapperReconciler) TestDiscoverInstanceTypes(t *testing.T) { g := gomega.NewGomegaWithT(t) - + ctx := context.Background() tests := []struct { name string input *arbv1.AppWrapper @@ -99,7 +100,7 @@ func (r *AppWrapperReconciler) TestDiscoverInstanceTypes(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - result := r.discoverInstanceTypes(test.input) + result := r.discoverInstanceTypes(ctx, test.input) g.Expect(result).To(gomega.Equal(test.expected)) }) } diff --git a/controllers/appwrapper_controller.go b/controllers/appwrapper_controller.go index 369b140..cf89f58 100644 --- a/controllers/appwrapper_controller.go +++ b/controllers/appwrapper_controller.go @@ -132,7 +132,7 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, nil } - demandPerInstanceType := r.discoverInstanceTypes(&appwrapper) + demandPerInstanceType := r.discoverInstanceTypes(ctx, &appwrapper) if ocmSecretRef := r.Config.OCMSecretRef; ocmSecretRef != nil { switch r.MachineType { case MachineTypeNodePool: @@ -252,13 +252,16 @@ func (r *AppWrapperReconciler) getOCMSecret(ctx context.Context, secretRef *core return r.kubeClient.CoreV1().Secrets(secretRef.Namespace).Get(ctx, secretRef.Name, metav1.GetOptions{}) } -func (r *AppWrapperReconciler) discoverInstanceTypes(aw *arbv1.AppWrapper) map[string]int { +func (r *AppWrapperReconciler) discoverInstanceTypes(ctx context.Context, aw *arbv1.AppWrapper) map[string]int { demandMapPerInstanceType := make(map[string]int) instanceRequired := getInstanceRequired(aw.Labels) if len(instanceRequired) < 1 { if _, exists := aw.Annotations["loggedNoInstances"]; !exists { klog.Infof("Found AW %s that cannot be scaled due to missing orderedinstance label", aw.ObjectMeta.Name) r.setAnnotation(aw, "loggedNoInstances", "true") + if err := r.Update(ctx, aw); err != nil { + return nil + } } return demandMapPerInstanceType }