Skip to content

Commit e44a748

Browse files
committed
Improve forward feature
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
1 parent 55467ba commit e44a748

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

pkg/core/stack_resources.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func (sc *StackContainer) selector() map[string]string {
196196
// "zalando.org/forward-backend", the deployment will be set to
197197
// replicas 1.
198198
func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
199+
if sc.TrafficForward() {
200+
// during traffic forwarding we do not need a deployment
201+
return nil
202+
}
199203

200204
stack := sc.Stack
201205

@@ -234,12 +238,6 @@ func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
234238
Labels: embeddedCopy.Labels,
235239
}
236240

237-
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration && *updatedReplicas != 0 {
238-
updatedReplicas = wrapReplicas(1)
239-
sc.deploymentReplicas = 1
240-
sc.stackReplicas = 1
241-
}
242-
243241
deployment := &appsv1.Deployment{
244242
ObjectMeta: sc.resourceMeta(),
245243
Spec: appsv1.DeploymentSpec{
@@ -270,7 +268,7 @@ func (sc *StackContainer) GenerateHPA() (
270268
*autoscaling.HorizontalPodAutoscaler,
271269
error,
272270
) {
273-
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
271+
if sc.TrafficForward() {
274272
return nil, nil
275273
}
276274

@@ -477,7 +475,7 @@ func (sc *StackContainer) generateIngress(segment bool) (
477475
Rules: rules,
478476
},
479477
}
480-
if _, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]; clusterMigration {
478+
if sc.TrafficForward() {
481479
// see https://opensource.zalando.com/skipper/kubernetes/ingress-usage/#skipper-ingress-annotations
482480
result.Annotations["zalando.org/skipper-backend"] = "forward"
483481
}

pkg/core/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func (sc *StackContainer) HasTraffic() bool {
159159
}
160160

161161
func (sc *StackContainer) IsReady() bool {
162+
if sc.TrafficForward() {
163+
// if stack is configured to forward traffic, consider it
164+
// ready.
165+
return true
166+
}
167+
162168
// Calculate minimum required replicas for the Deployment to be considered ready
163169
minRequiredReplicas := int32(math.Ceil(float64(sc.deploymentReplicas) * sc.minReadyPercent))
164170

@@ -187,6 +193,11 @@ func (sc *StackContainer) ScaledDown() bool {
187193
return !sc.noTrafficSince.IsZero() && time.Since(sc.noTrafficSince) > sc.scaledownTTL
188194
}
189195

196+
func (sc *StackContainer) TrafficForward() bool {
197+
_, clusterMigration := sc.Stack.Annotations[forwardBackendAnnotation]
198+
return clusterMigration
199+
}
200+
190201
func (sc *StackContainer) Name() string {
191202
return sc.Stack.Name
192203
}

0 commit comments

Comments
 (0)