Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/core/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion pkg/core/traffic_prescaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/core/traffic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down