Skip to content

Commit 1d7afaf

Browse files
committed
fix: we do not need a deployment nor hpa if we migrate
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
1 parent dc42acc commit 1d7afaf

3 files changed

Lines changed: 28 additions & 28 deletions

File tree

pkg/core/stack_resources.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ func (sc *StackContainer) selector() map[string]string {
191191
// "zalando.org/forward-backend", the deployment will be set to
192192
// replicas 1.
193193
func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
194+
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
195+
return nil
196+
}
197+
194198
stack := sc.Stack
195199

196200
desiredReplicas := sc.stackReplicas
@@ -246,11 +250,6 @@ func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
246250
deployment.Spec.Strategy = *strategy
247251
}
248252

249-
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
250-
i := int32(1)
251-
deployment.Spec.Replicas = &i
252-
}
253-
254253
return deployment
255254
}
256255

@@ -262,6 +261,10 @@ func (sc *StackContainer) GenerateHPA() (
262261
*autoscaling.HorizontalPodAutoscaler,
263262
error,
264263
) {
264+
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
265+
return nil, nil
266+
}
267+
265268
autoscalerSpec := sc.Stack.Spec.StackSpec.Autoscaler
266269
trafficWeight := sc.actualTrafficWeight
267270

@@ -312,12 +315,6 @@ func (sc *StackContainer) GenerateHPA() (
312315
result.Spec.MinReplicas = &pr
313316
}
314317

315-
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
316-
i := int32(1)
317-
result.Spec.MinReplicas = &i
318-
result.Spec.MaxReplicas = i
319-
}
320-
321318
return result, nil
322319
}
323320

pkg/core/stack_resources_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,18 +1161,19 @@ func TestStackGenerateService(t *testing.T) {
11611161

11621162
func TestStackGenerateDeployment(t *testing.T) {
11631163
for _, tc := range []struct {
1164-
name string
1165-
hpaEnabled bool
1166-
stackReplicas int32
1167-
minReadySeconds int32
1168-
prescalingActive bool
1169-
prescalingReplicas int32
1170-
deploymentReplicas int32
1171-
noTrafficSince time.Time
1172-
expectedReplicas int32
1173-
maxUnavailable int
1174-
maxSurge int
1175-
stackAnnotations map[string]string
1164+
name string
1165+
hpaEnabled bool
1166+
stackReplicas int32
1167+
minReadySeconds int32
1168+
prescalingActive bool
1169+
prescalingReplicas int32
1170+
deploymentReplicas int32
1171+
noTrafficSince time.Time
1172+
expectedReplicas int32
1173+
maxUnavailable int
1174+
maxSurge int
1175+
stackAnnotations map[string]string
1176+
expectedDeploymentNil bool
11761177
}{
11771178
{
11781179
name: "stack scaled down to zero, deployment still running",
@@ -1310,10 +1311,10 @@ func TestStackGenerateDeployment(t *testing.T) {
13101311
name: "cluster migration should scale down deployment",
13111312
stackReplicas: 3,
13121313
deploymentReplicas: 3,
1313-
expectedReplicas: 1,
13141314
stackAnnotations: map[string]string{
13151315
forwardBackendAnnotation: "fwd-deployment",
13161316
},
1317+
expectedDeploymentNil: true,
13171318
},
13181319
} {
13191320
t.Run(tc.name, func(t *testing.T) {
@@ -1375,6 +1376,10 @@ func TestStackGenerateDeployment(t *testing.T) {
13751376
}
13761377
}
13771378
deployment := c.GenerateDeployment()
1379+
if tc.expectedDeploymentNil {
1380+
require.Nil(t, deployment, "Failed to generate nil deployment")
1381+
return
1382+
}
13781383
expected := &apps.Deployment{
13791384
ObjectMeta: testResourceMeta,
13801385
Spec: apps.DeploymentSpec{
@@ -1517,9 +1522,7 @@ func TestGenerateHPA(t *testing.T) {
15171522
},
15181523
},
15191524
},
1520-
expectedBehavior: exampleBehavior,
1521-
expectedMinReplicas: &min,
1522-
expectedMaxReplicas: 1,
1525+
expectedBehavior: nil,
15231526
},
15241527
} {
15251528
t.Run(tc.name, func(t *testing.T) {

pkg/core/stackset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (ssc *StackSetContainer) NewStack() (*StackContainer, string) {
8383
spec.RouteGroup = ssc.StackSet.Spec.RouteGroup.DeepCopy()
8484
}
8585

86-
stackAnnotations := make(map[string]string)
86+
var stackAnnotations map[string]string
8787
if a := ssc.StackSet.Spec.StackTemplate.Annotations; a != nil {
8888
stackAnnotations = a
8989
}

0 commit comments

Comments
 (0)