From 77d8e4e4d3141334507ecd57e4de0d1a7cb8a921 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Mon, 23 Sep 2019 22:14:44 +0300 Subject: [PATCH] Use the promotion phase in A/B testing and Blue/Green --- pkg/controller/scheduler.go | 83 +++++++++++-------------------------- 1 file changed, 24 insertions(+), 59 deletions(-) diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index f5445898..2c280eb5 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -214,7 +214,27 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh return } - // scale canary to zero if analysis has succeeded + // route all traffic to primary if analysis has succeeded + if cd.Status.Phase == flaggerv1.CanaryPhasePromoting { + if provider != "kubernetes" { + c.recordEventInfof(cd, "Routing all traffic to primary") + if err := meshRouter.SetRoutes(cd, 100, 0); err != nil { + c.recordEventWarningf(cd, "%v", err) + return + } + c.recorder.SetWeight(cd, 100, 0) + } + + // update status phase + if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhaseFinalising); err != nil { + c.recordEventWarningf(cd, "%v", err) + return + } + + return + } + + // scale canary to zero if promotion has finished if cd.Status.Phase == flaggerv1.CanaryPhaseFinalising { if err := c.deployer.Scale(cd, 0); err != nil { c.recordEventWarningf(cd, "%v", err) @@ -336,29 +356,12 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh c.recordEventWarningf(cd, "%v", err) return } - // increment iterations - if err := c.deployer.SetStatusIterations(cd, cd.Status.Iterations+1); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - return - } - - // route all traffic to primary - if cd.Spec.CanaryAnalysis.Iterations < cd.Status.Iterations { - if err := meshRouter.SetRoutes(cd, 100, 0); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - c.recorder.SetWeight(cd, 100, 0) // update status phase - if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhaseFinalising); err != nil { + if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhasePromoting); err != nil { c.recordEventWarningf(cd, "%v", err) return } - - c.recordEventInfof(cd, "Routing all traffic to primary") return } @@ -403,7 +406,7 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh } // promote canary - max iterations reached - if cd.Spec.CanaryAnalysis.Iterations+1 == cd.Status.Iterations { + if cd.Spec.CanaryAnalysis.Iterations < cd.Status.Iterations { c.recordEventInfof(cd, "Copying %s.%s template spec to %s.%s", cd.Spec.TargetRef.Name, cd.Namespace, primaryName, cd.Namespace) if err := c.deployer.Promote(cd); err != nil { @@ -411,31 +414,11 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh return } - // increment iterations - if err := c.deployer.SetStatusIterations(cd, cd.Status.Iterations+1); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - return - } - - // route all traffic to primary - if cd.Spec.CanaryAnalysis.Iterations < cd.Status.Iterations { - if provider != "kubernetes" { - c.recordEventInfof(cd, "Routing all traffic to primary") - if err := meshRouter.SetRoutes(cd, 100, 0); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - c.recorder.SetWeight(cd, 100, 0) - } - // update status phase - if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhaseFinalising); err != nil { + if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhasePromoting); err != nil { c.recordEventWarningf(cd, "%v", err) return } - return } @@ -444,24 +427,6 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh // strategy: Canary progressive traffic increase if cd.Spec.CanaryAnalysis.StepWeight > 0 { - // finalise canary rollout - route all traffic to primary - if cd.Status.Phase == flaggerv1.CanaryPhasePromoting { - c.recordEventInfof(cd, "Routing all traffic to primary") - if err := meshRouter.SetRoutes(cd, 100, 0); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - c.recorder.SetWeight(cd, 100, 0) - - // update status phase - if err := c.deployer.SetStatusPhase(cd, flaggerv1.CanaryPhaseFinalising); err != nil { - c.recordEventWarningf(cd, "%v", err) - return - } - - return - } - // increase traffic weight if canaryWeight < maxWeight { primaryWeight -= cd.Spec.CanaryAnalysis.StepWeight