Do not trigger a canary deployment on manual rollback

Save the primary spec hash and check if it matches the canary spec. If the canary hash is identical with the primary one skip promotion.
This commit is contained in:
stefanprodan
2019-07-10 09:08:33 +03:00
parent afa2d079f6
commit b26542f38d
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -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"`
+14
View File
@@ -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
}