From 2a0473fc9bc092a8bb2187c33f23a4e9cdb5c0d8 Mon Sep 17 00:00:00 2001 From: Robert Kwolek Date: Tue, 17 Nov 2020 09:00:21 +0100 Subject: [PATCH] fix: fullWeight removed, fullWeight => totalWeight --- artifacts/examples/linkerd-canary-steps.yaml | 5 +-- artifacts/flagger/crd.yaml | 7 ---- charts/flagger/crds/crd.yaml | 7 ---- docs/gitbook/tutorials/rollout-weights.md | 12 +++--- kustomize/base/flagger/crd.yaml | 7 ---- pkg/apis/flagger/v1beta1/canary.go | 6 +-- pkg/controller/scheduler.go | 41 +++++++++----------- test/e2e-linkerd-steps-tests.sh | 10 ++--- 8 files changed, 31 insertions(+), 64 deletions(-) diff --git a/artifacts/examples/linkerd-canary-steps.yaml b/artifacts/examples/linkerd-canary-steps.yaml index 0e1e81b9..4a8b7694 100644 --- a/artifacts/examples/linkerd-canary-steps.yaml +++ b/artifacts/examples/linkerd-canary-steps.yaml @@ -24,9 +24,8 @@ spec: analysis: interval: 15s threshold: 10 - fullWeight: 1000 - maxWeight: 500 - stepWeights: [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550] + maxWeight: 50 + stepWeights: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55] metrics: - name: request-success-rate thresholdRange: diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index ffe6d9fa..1eebd4be 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -48,10 +48,6 @@ spec: type: boolean JSONPath: .spec.analysis.mirror priority: 1 - - name: FullWeight - type: string - JSONPath: .spec.analysis.fullWeight - priority: 1 - name: StepWeight type: string JSONPath: .spec.analysis.stepWeight @@ -570,9 +566,6 @@ spec: threshold: description: Max number of failed checks before rollback type: number - fullWeight: - description: Sum of traffic step weights for canary and primary - type: number maxWeight: description: Max traffic weight routed to canary type: number diff --git a/charts/flagger/crds/crd.yaml b/charts/flagger/crds/crd.yaml index ffe6d9fa..1eebd4be 100644 --- a/charts/flagger/crds/crd.yaml +++ b/charts/flagger/crds/crd.yaml @@ -48,10 +48,6 @@ spec: type: boolean JSONPath: .spec.analysis.mirror priority: 1 - - name: FullWeight - type: string - JSONPath: .spec.analysis.fullWeight - priority: 1 - name: StepWeight type: string JSONPath: .spec.analysis.stepWeight @@ -570,9 +566,6 @@ spec: threshold: description: Max number of failed checks before rollback type: number - fullWeight: - description: Sum of traffic step weights for canary and primary - type: number maxWeight: description: Max traffic weight routed to canary type: number diff --git a/docs/gitbook/tutorials/rollout-weights.md b/docs/gitbook/tutorials/rollout-weights.md index 54d5a389..fd38876c 100644 --- a/docs/gitbook/tutorials/rollout-weights.md +++ b/docs/gitbook/tutorials/rollout-weights.md @@ -20,7 +20,6 @@ We would have steps (canary weight : primary weight): * promotion In order to enable non-linear promotion a new parameters were introduced: -* `fullWeight` - determines the sum of canary and primary weights, i.e. the maximum possible weight which can be set to the split * `stepWeights` - determines the ordered array of weights, which shall be used during canary promotion. Example: @@ -28,13 +27,12 @@ Example: canary: analysis: promotion: - fullWeight: 1000 - stepWeights: [1, 10, 100, 800] + stepWeights: [1, 2, 10, 80] ``` This configuration performs analysis starting from 1, going through `stepWeights` values till 800. We would have steps (canary weight : primary weight): -* 1 (1 : 999) -* 10 (10 : 990) -* 100 (100 : 900) -* 800 (800 : 200) +* 1 (1 : 99) +* 2 (2 : 98) +* 10 (10 : 90) +* 80 (80 : 20) * promotion diff --git a/kustomize/base/flagger/crd.yaml b/kustomize/base/flagger/crd.yaml index ffe6d9fa..1eebd4be 100644 --- a/kustomize/base/flagger/crd.yaml +++ b/kustomize/base/flagger/crd.yaml @@ -48,10 +48,6 @@ spec: type: boolean JSONPath: .spec.analysis.mirror priority: 1 - - name: FullWeight - type: string - JSONPath: .spec.analysis.fullWeight - priority: 1 - name: StepWeight type: string JSONPath: .spec.analysis.stepWeight @@ -570,9 +566,6 @@ spec: threshold: description: Max number of failed checks before rollback type: number - fullWeight: - description: Sum of traffic step weights for canary and primary - type: number maxWeight: description: Max traffic weight routed to canary type: number diff --git a/pkg/apis/flagger/v1beta1/canary.go b/pkg/apis/flagger/v1beta1/canary.go index 56e45ad2..38b90761 100644 --- a/pkg/apis/flagger/v1beta1/canary.go +++ b/pkg/apis/flagger/v1beta1/canary.go @@ -201,11 +201,7 @@ type CanaryAnalysis struct { // +optional Mirror bool `json:"mirror,omitempty"` - // Sum of weights of canary and primary. If not set default 100 is used. - // +optional - FullWeight int `json:"fullWeight,omitempty"` - - // Weight of the traffic to be mirrored in the range of [0, FullWeight]. + // Weight of the traffic to be mirrored in the range of [0, 100]. // +optional MirrorWeight int `json:"mirrorWeight,omitempty"` diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index fb2d1ac6..059a92fc 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -26,10 +26,7 @@ func (c *Controller) maxWeight(canary *flaggerv1.Canary) int { return 100 } -func (c *Controller) fullWeight(canary *flaggerv1.Canary) int { - if canary.GetAnalysis().FullWeight > 0 { - return canary.GetAnalysis().FullWeight - } +func (c *Controller) totalWeight(canary *flaggerv1.Canary) int { // set max weight default value to 100% return 100 } @@ -50,7 +47,7 @@ func (c *Controller) nextStepWeight(canary *flaggerv1.Canary, canaryWeight int) } } - return c.fullWeight(canary) - canaryWeight + return c.totalWeight(canary) - canaryWeight } // scheduleCanaries synchronises the canary map with the jobs map, @@ -242,7 +239,7 @@ func (c *Controller) advanceCanary(name string, namespace string) { cd.Spec.TargetRef.Name, cd.Namespace) // route all traffic back to primary - primaryWeight = c.fullWeight(cd) + primaryWeight = c.totalWeight(cd) canaryWeight = 0 if err := meshRouter.SetRoutes(cd, primaryWeight, canaryWeight, false); err != nil { c.recordEventWarningf(cd, "%v", err) @@ -397,11 +394,11 @@ func (c *Controller) runPromotionTrafficShift(canary *flaggerv1.Canary, canaryCo // route all traffic to primary in one go when promotion step wight is not set if canary.Spec.Analysis.StepWeightPromotion == 0 { c.recordEventInfof(canary, "Routing all traffic to primary") - if err := meshRouter.SetRoutes(canary, c.fullWeight(canary), 0, false); err != nil { + if err := meshRouter.SetRoutes(canary, c.totalWeight(canary), 0, false); err != nil { c.recordEventWarningf(canary, "%v", err) return } - c.recorder.SetWeight(canary, c.fullWeight(canary), 0) + c.recorder.SetWeight(canary, c.totalWeight(canary), 0) if err := canaryController.SetStatusPhase(canary, flaggerv1.CanaryPhaseFinalising); err != nil { c.recordEventWarningf(canary, "%v", err) } @@ -411,8 +408,8 @@ func (c *Controller) runPromotionTrafficShift(canary *flaggerv1.Canary, canaryCo // increment the primary traffic weight until it reaches 100%/full weight if canaryWeight > 0 { primaryWeight += canary.GetAnalysis().StepWeightPromotion - if primaryWeight > c.fullWeight(canary) { - primaryWeight = c.fullWeight(canary) + if primaryWeight > c.totalWeight(canary) { + primaryWeight = c.totalWeight(canary) } canaryWeight -= canary.GetAnalysis().StepWeightPromotion if canaryWeight < 0 { @@ -426,7 +423,7 @@ func (c *Controller) runPromotionTrafficShift(canary *flaggerv1.Canary, canaryCo c.recordEventInfof(canary, "Advance %s.%s primary weight %v", canary.Name, canary.Namespace, primaryWeight) // finalize promotion - if primaryWeight == c.fullWeight(canary) { + if primaryWeight == c.totalWeight(canary) { if err := canaryController.SetStatusPhase(canary, flaggerv1.CanaryPhaseFinalising); err != nil { c.recordEventWarningf(canary, "%v", err) } @@ -456,11 +453,11 @@ func (c *Controller) runCanary(canary *flaggerv1.Canary, canaryController canary if canary.GetAnalysis().Mirror && canaryWeight == 0 { if !mirrored { mirrored = true - primaryWeight = c.fullWeight(canary) + primaryWeight = c.totalWeight(canary) canaryWeight = 0 } else { mirrored = false - primaryWeight = c.fullWeight(canary) - nextStepWeight + primaryWeight = c.totalWeight(canary) - nextStepWeight canaryWeight = nextStepWeight } c.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). @@ -472,8 +469,8 @@ func (c *Controller) runCanary(canary *flaggerv1.Canary, canaryController canary primaryWeight = 0 } canaryWeight += nextStepWeight - if canaryWeight > c.fullWeight(canary) { - canaryWeight = c.fullWeight(canary) + if canaryWeight > c.totalWeight(canary) { + canaryWeight = c.totalWeight(canary) } } @@ -521,11 +518,11 @@ func (c *Controller) runAB(canary *flaggerv1.Canary, canaryController canary.Con // route traffic to canary and increment iterations if canary.GetAnalysis().Iterations > canary.Status.Iterations { - if err := meshRouter.SetRoutes(canary, 0, c.fullWeight(canary), false); err != nil { + if err := meshRouter.SetRoutes(canary, 0, c.totalWeight(canary), false); err != nil { c.recordEventWarningf(canary, "%v", err) return } - c.recorder.SetWeight(canary, 0, c.fullWeight(canary)) + c.recorder.SetWeight(canary, 0, c.totalWeight(canary)) if err := canaryController.SetStatusIterations(canary, canary.Status.Iterations+1); err != nil { c.recordEventWarningf(canary, "%v", err) @@ -567,7 +564,7 @@ func (c *Controller) runBlueGreen(canary *flaggerv1.Canary, canaryController can // If in "mirror" mode, mirror requests during the entire B/G canary test if provider != "kubernetes" && canary.GetAnalysis().Mirror && !mirrored { - if err := meshRouter.SetRoutes(canary, c.fullWeight(canary), 0, true); err != nil { + if err := meshRouter.SetRoutes(canary, c.totalWeight(canary), 0, true); err != nil { c.recordEventWarningf(canary, "%v", err) } c.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). @@ -595,11 +592,11 @@ func (c *Controller) runBlueGreen(canary *flaggerv1.Canary, canaryController can } else { c.recordEventInfof(canary, "Routing all traffic to canary") } - if err := meshRouter.SetRoutes(canary, 0, c.fullWeight(canary), false); err != nil { + if err := meshRouter.SetRoutes(canary, 0, c.totalWeight(canary), false); err != nil { c.recordEventWarningf(canary, "%v", err) return } - c.recorder.SetWeight(canary, 0, c.fullWeight(canary)) + c.recorder.SetWeight(canary, 0, c.totalWeight(canary)) } // increment iterations @@ -669,7 +666,7 @@ func (c *Controller) shouldSkipAnalysis(canary *flaggerv1.Canary, canaryControll } // route all traffic to primary - primaryWeight := c.fullWeight(canary) + primaryWeight := c.totalWeight(canary) canaryWeight := 0 if err := meshRouter.SetRoutes(canary, primaryWeight, canaryWeight, false); err != nil { c.recordEventWarningf(canary, "%v", err) @@ -803,7 +800,7 @@ func (c *Controller) rollback(canary *flaggerv1.Canary, canaryController canary. } // route all traffic back to primary - primaryWeight := c.fullWeight(canary) + primaryWeight := c.totalWeight(canary) canaryWeight := 0 if err := meshRouter.SetRoutes(canary, primaryWeight, canaryWeight, false); err != nil { c.recordEventWarningf(canary, "%v", err) diff --git a/test/e2e-linkerd-steps-tests.sh b/test/e2e-linkerd-steps-tests.sh index 4837cdc8..b8f6c53a 100644 --- a/test/e2e-linkerd-steps-tests.sh +++ b/test/e2e-linkerd-steps-tests.sh @@ -61,9 +61,8 @@ spec: analysis: interval: 15s threshold: 15 - fullWeight: 1000 - maxWeight: 500 - stepWeights: [100, 200, 300, 400, 500, 600] + maxWeight: 50 + stepWeights: [10, 20, 30, 40, 50, 60] metrics: - name: request-success-rate threshold: 99 @@ -172,9 +171,8 @@ spec: analysis: interval: 15s threshold: 3 - fullWeight: 1000 - maxWeight: 500 - stepWeights: [100, 200, 300, 400, 500, 600] + maxWeight: 50 + stepWeights: [10, 20, 30, 40, 50, 60] metrics: - name: request-success-rate threshold: 99