Skip to content

Commit

Permalink
add: appwrapper condition check for scale-up
Browse files Browse the repository at this point in the history
  • Loading branch information
VanillaSpoon authored and openshift-merge-bot[bot] committed Dec 12, 2023
1 parent fafee56 commit 97b3a2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 14 additions & 9 deletions controllers/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,22 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, nil
}

demandPerInstanceType := r.discoverInstanceTypes(ctx, &appwrapper)
if ocmSecretRef := r.Config.OCMSecretRef; ocmSecretRef != nil {
return r.scaleMachinePool(ctx, &appwrapper, demandPerInstanceType)
} else {
switch strings.ToLower(r.Config.MachineSetsStrategy) {
case "reuse":
return r.reconcileReuseMachineSet(ctx, &appwrapper, demandPerInstanceType)
case "duplicate":
return r.reconcileCreateMachineSet(ctx, &appwrapper, demandPerInstanceType)
status := appwrapper.Status.State
allconditions := appwrapper.Status.Conditions
if status == "Pending" && containsInsufficientCondition(allconditions) {
demandPerInstanceType := r.discoverInstanceTypes(ctx, &appwrapper)
if ocmSecretRef := r.Config.OCMSecretRef; ocmSecretRef != nil {
return r.scaleMachinePool(ctx, &appwrapper, demandPerInstanceType)
} else {
switch strings.ToLower(r.Config.MachineSetsStrategy) {
case "reuse":
return r.reconcileReuseMachineSet(ctx, &appwrapper, demandPerInstanceType)
case "duplicate":
return r.reconcileCreateMachineSet(ctx, &appwrapper, demandPerInstanceType)
}
}
}

return ctrl.Result{}, nil
}

Expand Down
11 changes: 11 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"time"

machinev1 "github.com/openshift/api/machine/v1beta1"
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
)
Expand All @@ -19,6 +21,15 @@ func resyncPeriod() func() time.Duration {
}
}

func containsInsufficientCondition(allconditions []arbv1.AppWrapperCondition) bool {
for _, condition := range allconditions {
if strings.Contains(condition.Message, "Insufficient") {
return true
}
}
return false
}

// ProviderSpecFromRawExtension unmarshals the JSON-encoded spec
func ProviderSpecFromRawExtension(ctx context.Context, rawExtension *runtime.RawExtension) (*machinev1.AWSMachineProviderConfig, error) {
logger := ctrl.LoggerFrom(ctx)
Expand Down

0 comments on commit 97b3a2f

Please sign in to comment.