Skip to content

Commit

Permalink
update discoverInstanceTypes to persist annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
VanillaSpoon committed Nov 28, 2023
1 parent 3ca7587 commit a0bcc51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions controllers/appWrapper_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"context"
"testing"

"github.com/onsi/gomega"
Expand All @@ -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
Expand Down Expand Up @@ -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))
})
}
Expand Down
7 changes: 5 additions & 2 deletions controllers/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a0bcc51

Please sign in to comment.