diff --git a/pkg/core/test_helpers.go b/pkg/core/test_helpers.go index be1c1754..a51a432f 100644 --- a/pkg/core/test_helpers.go +++ b/pkg/core/test_helpers.go @@ -99,6 +99,14 @@ func (f *testStackFactory) pendingRemoval() *testStackFactory { return f } +func (f *testStackFactory) trafficForward() *testStackFactory { + if f.container.Stack.Annotations == nil { + f.container.Stack.Annotations = map[string]string{} + } + f.container.Stack.Annotations[forwardBackendAnnotation] = forwardBackendName + return f +} + func (f *testStackFactory) prescaling(replicas int32, desiredTrafficWeight float64, lastTrafficIncrease time.Time) *testStackFactory { f.container.prescalingActive = true f.container.prescalingReplicas = replicas diff --git a/pkg/core/traffic_prescaling.go b/pkg/core/traffic_prescaling.go index d4a37e24..6608eedb 100644 --- a/pkg/core/traffic_prescaling.go +++ b/pkg/core/traffic_prescaling.go @@ -41,6 +41,13 @@ func (r PrescalingTrafficReconciler) Reconcile(stacks map[string]*StackContainer // Prescale stacks if needed for _, stack := range stacks { + // Stacks configured to forward traffic to another cluster don't + // have a deployment of their own, so prescaling doesn't apply + // to them. + if stack.TrafficForward() { + continue + } + // If traffic needs to be increased if stack.desiredTrafficWeight > stack.actualTrafficWeight { // If prescaling is not active, or desired weight changed since the last prescaling attempt, update @@ -86,7 +93,11 @@ func (r PrescalingTrafficReconciler) Reconcile(stacks map[string]*StackContainer actualWeights := make(map[string]float64, len(stacks)) for stackName, stack := range stacks { // Check if we're increasing traffic but the stack is not ready - if stack.desiredTrafficWeight > stack.actualTrafficWeight { + if stack.desiredTrafficWeight > stack.actualTrafficWeight && !stack.TrafficForward() { + // Stacks configured to forward traffic to another cluster + // don't have a deployment of their own here, so replica + // based readiness/prescaling checks don't apply to them + // (see stack.IsReady() for the same exception). var desiredReplicas = stack.deploymentReplicas if stack.prescalingActive { desiredReplicas = stack.prescalingReplicas diff --git a/pkg/core/traffic_test.go b/pkg/core/traffic_test.go index 4e908a72..3a6eeabe 100644 --- a/pkg/core/traffic_test.go +++ b/pkg/core/traffic_test.go @@ -874,6 +874,21 @@ func TestTrafficSwitchPrescaling(t *testing.T) { }, expectedError: "stacks not ready: foo-v1, foo-v3", }, + { + name: "forwarded stacks are not subject to prescaling readiness checks", + stacks: map[types.UID]*StackContainer{ + "foo-v1": testStack("foo-v1").traffic(0, 100).ready(3).stack(), + "foo-v2": testStack("foo-v2").traffic(100, 0).trafficForward().stack(), + }, + expectedDesiredWeights: map[string]float64{ + "foo-v1": 0, + "foo-v2": 100, + }, + expectedActualWeights: map[string]float64{ + "foo-v1": 0, + "foo-v2": 100, + }, + }, } { t.Run(tc.name, func(t *testing.T) { c := StackSetContainer{