Skip to content

Commit d4e2eaf

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

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

controller/stack_resources.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ func isOwned(ownerReferences []metav1.OwnerReference) (bool, types.UID) {
4444
func (c *StackSetController) ReconcileStackDeployment(ctx context.Context, stack *zv1.Stack, existing *apps.Deployment, generateUpdated func() *apps.Deployment) error {
4545
deployment := generateUpdated()
4646

47+
// no deployment
48+
if deployment == nil {
49+
if existing != nil {
50+
err := c.client.AppsV1().Deployments(existing.Namespace).Delete(ctx, existing.Name, metav1.DeleteOptions{})
51+
if err != nil {
52+
return err
53+
}
54+
c.recorder.Eventf(
55+
stack,
56+
apiv1.EventTypeNormal,
57+
"DeletedDeployment",
58+
"Deleted Deployment %s",
59+
existing.Name)
60+
}
61+
return nil
62+
}
63+
4764
// Create new deployment
4865
if existing == nil {
4966
_, err := c.client.AppsV1().Deployments(deployment.Namespace).Create(ctx, deployment, metav1.CreateOptions{})
@@ -88,7 +105,7 @@ func (c *StackSetController) ReconcileStackHPA(ctx context.Context, stack *zv1.S
88105
return err
89106
}
90107

91-
// HPA removed
108+
// no HPA
92109
if hpa == nil {
93110
if existing != nil {
94111
err := c.client.AutoscalingV2().HorizontalPodAutoscalers(existing.Namespace).Delete(ctx, existing.Name, metav1.DeleteOptions{})
@@ -100,7 +117,7 @@ func (c *StackSetController) ReconcileStackHPA(ctx context.Context, stack *zv1.S
100117
apiv1.EventTypeNormal,
101118
"DeletedHPA",
102119
"Deleted HPA %s",
103-
existing.Namespace)
120+
existing.Name)
104121
}
105122
return nil
106123
}

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)