Skip to content

Commit 97b3a2f

Browse files
add: appwrapper condition check for scale-up
1 parent fafee56 commit 97b3a2f

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

controllers/appwrapper_controller.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,22 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
120120
return ctrl.Result{}, nil
121121
}
122122

123-
demandPerInstanceType := r.discoverInstanceTypes(ctx, &appwrapper)
124-
if ocmSecretRef := r.Config.OCMSecretRef; ocmSecretRef != nil {
125-
return r.scaleMachinePool(ctx, &appwrapper, demandPerInstanceType)
126-
} else {
127-
switch strings.ToLower(r.Config.MachineSetsStrategy) {
128-
case "reuse":
129-
return r.reconcileReuseMachineSet(ctx, &appwrapper, demandPerInstanceType)
130-
case "duplicate":
131-
return r.reconcileCreateMachineSet(ctx, &appwrapper, demandPerInstanceType)
123+
status := appwrapper.Status.State
124+
allconditions := appwrapper.Status.Conditions
125+
if status == "Pending" && containsInsufficientCondition(allconditions) {
126+
demandPerInstanceType := r.discoverInstanceTypes(ctx, &appwrapper)
127+
if ocmSecretRef := r.Config.OCMSecretRef; ocmSecretRef != nil {
128+
return r.scaleMachinePool(ctx, &appwrapper, demandPerInstanceType)
129+
} else {
130+
switch strings.ToLower(r.Config.MachineSetsStrategy) {
131+
case "reuse":
132+
return r.reconcileReuseMachineSet(ctx, &appwrapper, demandPerInstanceType)
133+
case "duplicate":
134+
return r.reconcileCreateMachineSet(ctx, &appwrapper, demandPerInstanceType)
135+
}
132136
}
133137
}
138+
134139
return ctrl.Result{}, nil
135140
}
136141

controllers/utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"encoding/json"
66
"fmt"
77
"math/rand"
8+
"strings"
89
"time"
910

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

24+
func containsInsufficientCondition(allconditions []arbv1.AppWrapperCondition) bool {
25+
for _, condition := range allconditions {
26+
if strings.Contains(condition.Message, "Insufficient") {
27+
return true
28+
}
29+
}
30+
return false
31+
}
32+
2233
// ProviderSpecFromRawExtension unmarshals the JSON-encoded spec
2334
func ProviderSpecFromRawExtension(ctx context.Context, rawExtension *runtime.RawExtension) (*machinev1.AWSMachineProviderConfig, error) {
2435
logger := ctrl.LoggerFrom(ctx)

0 commit comments

Comments
 (0)