From 9872e6bc16e3c8bfab9bb91f27354ec23dfaaba9 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Wed, 16 Jan 2019 13:18:53 +0200 Subject: [PATCH] Skip readiness checks if canary analysis finished --- pkg/controller/deployer.go | 10 +++++++++- pkg/controller/scheduler.go | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/controller/deployer.go b/pkg/controller/deployer.go index 62e2ff32..db6e866d 100644 --- a/pkg/controller/deployer.go +++ b/pkg/controller/deployer.go @@ -140,7 +140,7 @@ func (c *CanaryDeployer) IsNewSpec(cd *flaggerv1.Canary) (bool, error) { newSpec := &canary.Spec.Template.Spec oldSpecJson, err := base64.StdEncoding.DecodeString(cd.Status.CanaryRevision) if err != nil { - return false, err + return false, fmt.Errorf("%s.%s decode error %v", cd.Name, cd.Namespace, err) } oldSpec := &corev1.PodSpec{} err = json.Unmarshal(oldSpecJson, oldSpec) @@ -156,6 +156,14 @@ func (c *CanaryDeployer) IsNewSpec(cd *flaggerv1.Canary) (bool, error) { return false, nil } +// ShouldAdvance determines if the canary analysis can proceed +func (c *CanaryDeployer) ShouldAdvance(cd *flaggerv1.Canary) (bool, error) { + if cd.Status.CanaryRevision == "" || cd.Status.State == flaggerv1.CanaryRunning { + return true, nil + } + return c.IsNewSpec(cd) +} + // SetFailedChecks updates the canary failed checks counter func (c *CanaryDeployer) SetFailedChecks(cd *flaggerv1.Canary, val int) error { cdCopy := cd.DeepCopy() diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index 25a95892..e2e3672a 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -91,6 +91,13 @@ func (c *Controller) advanceCanary(name string, namespace string) { return } + if ok, err := c.deployer.ShouldAdvance(cd); !ok { + if err != nil { + c.recordEventWarningf(cd, "%v", err) + } + return + } + // set max weight default value to 100% maxWeight := 100 if cd.Spec.CanaryAnalysis.MaxWeight > 0 { @@ -249,7 +256,7 @@ func (c *Controller) advanceCanary(name string, namespace string) { func (c *Controller) checkCanaryStatus(cd *flaggerv1.Canary, deployer CanaryDeployer) bool { c.recorder.SetStatus(cd) - if cd.Status.State == "running" { + if cd.Status.State == flaggerv1.CanaryRunning { return true }