diff --git a/pkg/apis/flagger/v1alpha3/status.go b/pkg/apis/flagger/v1alpha3/status.go index 99afb980..5c43b0fd 100644 --- a/pkg/apis/flagger/v1alpha3/status.go +++ b/pkg/apis/flagger/v1alpha3/status.go @@ -64,6 +64,8 @@ type CanaryStatus struct { // +optional LastAppliedSpec string `json:"lastAppliedSpec,omitempty"` // +optional + LastPromotedSpec string `json:"lastPromotedSpec,omitempty"` + // +optional LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` // +optional Conditions []CanaryCondition `json:"conditions,omitempty"` diff --git a/pkg/canary/deployer.go b/pkg/canary/deployer.go index 41ceed50..1c5a47b5 100644 --- a/pkg/canary/deployer.go +++ b/pkg/canary/deployer.go @@ -113,12 +113,21 @@ func (c *Deployer) Promote(cd *flaggerv1.Canary) error { primaryCopy.Spec.Template.Labels = makePrimaryLabels(canary.Spec.Template.Labels, primaryName, label) + // apply update _, err = c.KubeClient.AppsV1().Deployments(cd.Namespace).Update(primaryCopy) if err != nil { return fmt.Errorf("updating deployment %s.%s template spec failed: %v", primaryCopy.GetName(), primaryCopy.Namespace, err) } + // update primary spec hash + cdClone := cd.DeepCopy() + cdClone.Status.LastPromotedSpec = cd.Status.LastAppliedSpec + _, err = c.FlaggerClient.FlaggerV1alpha3().Canaries(cd.Namespace).UpdateStatus(cdClone) + if err != nil { + return fmt.Errorf("updating canary status LastAppliedSpec failed: %v", err) + } + // update HPA if cd.Spec.AutoscalerRef != nil && cd.Spec.AutoscalerRef.Kind == "HorizontalPodAutoscaler" { if err := c.reconcilePrimaryHpa(cd, false); err != nil { @@ -149,6 +158,11 @@ func (c *Deployer) HasDeploymentChanged(cd *flaggerv1.Canary) (bool, error) { return false, fmt.Errorf("hash error %v", err) } + // do not trigger a canary deployment on manual rollback + if cd.Status.LastPromotedSpec == fmt.Sprintf("%d", newHash) { + return false, nil + } + if cd.Status.LastAppliedSpec != fmt.Sprintf("%d", newHash) { return true, nil }