Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoPromotionEnabled with default value of true #99

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 26 additions & 22 deletions controller/bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ func (c *Controller) rolloutBlueGreen(r *v1alpha1.Rollout, rsList []*appsv1.Repl
return c.syncRolloutStatusBlueGreen(oldRSs, newRS, previewSvc, activeSvc, r, false)
}

logCtx.Info("Reconciling pause")
pauseBeforeSwitchActive := c.reconcileBlueGreenPause(activeSvc, previewSvc, r)
if pauseBeforeSwitchActive {
logCtx.Info("Not finished reconciling pause")
return c.syncRolloutStatusBlueGreen(oldRSs, newRS, previewSvc, activeSvc, r, true)
if !defaults.GetAutoPromotionEnabledOrDefault(r) {
logCtx.Info("Reconciling pause")
pauseBeforeSwitchActive := c.reconcileBlueGreenPause(activeSvc, previewSvc, r, newRS)
if pauseBeforeSwitchActive {
logCtx.Info("Not finished reconciling pause")
return c.syncRolloutStatusBlueGreen(oldRSs, newRS, previewSvc, activeSvc, r, true)
}
}

logCtx.Infof("Reconciling active service '%s'", activeSvc.Name)
Expand Down Expand Up @@ -120,20 +122,17 @@ func (c *Controller) scaleDownPreviousActiveRS(rollout *v1alpha1.Rollout) bool {
return now.After(pauseEnd.Time)
}

func (c *Controller) reconcileBlueGreenPause(activeSvc, previewSvc *corev1.Service, rollout *v1alpha1.Rollout) bool {
if rollout.Spec.Strategy.BlueGreenStrategy.PreviewService == "" {
func (c *Controller) reconcileBlueGreenPause(activeSvc, previewSvc *corev1.Service, rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet) bool {
newRSPodHash := newRS.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]

if _, ok := activeSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey]; !ok {
return false
}

// If the rollout is not paused and the preview service is pointing at the currentPodHash, the rollout should enter a paused state
currentPodHash := controller.ComputeHash(&rollout.Spec.Template, rollout.Status.CollisionCount)
if !rollout.Spec.Paused && rollout.Status.PauseStartTime == nil && !rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint && previewSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey] == currentPodHash {
// If the rollout is not paused and the active service is not point at the newRS, we should pause the rollout.
if !rollout.Spec.Paused && rollout.Status.PauseStartTime == nil && !rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint && activeSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey] != newRSPodHash {
return true
}

if _, ok := activeSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey]; !ok {
return false
}
pauseStartTime := rollout.Status.PauseStartTime
autoPromoteActiveServiceDelaySeconds := rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds
if autoPromoteActiveServiceDelaySeconds != nil && pauseStartTime != nil {
Expand Down Expand Up @@ -205,19 +204,24 @@ func (c *Controller) syncRolloutStatusBlueGreen(oldRSs []*appsv1.ReplicaSet, new
}

pauseStartTime, paused := calculatePauseStatus(r, addPause)
newStatus.BlueGreen.ScaleUpPreviewCheckPoint = r.Status.BlueGreen.ScaleUpPreviewCheckPoint
if paused && r.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount != nil {
newStatus.BlueGreen.ScaleUpPreviewCheckPoint = true
} else if reconcileBlueGreenTemplateChange(r) {
newStatus.BlueGreen.ScaleUpPreviewCheckPoint = false
} else if newRS != nil && activeRS != nil && activeRS.Name == newRS.Name {
newStatus.BlueGreen.ScaleUpPreviewCheckPoint = false
}
newStatus.PauseStartTime = pauseStartTime
newStatus.BlueGreen.ScaleUpPreviewCheckPoint = calculateScaleUpPreviewCheckPoint(r, newRS, activeRS)
newStatus = c.calculateRolloutConditions(r, newStatus, allRSs, newRS)
return c.persistRolloutStatus(r, &newStatus, &paused)
}

func calculateScaleUpPreviewCheckPoint(r *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, activeRS *appsv1.ReplicaSet) bool {
newRSAvailableCount := replicasetutil.GetAvailableReplicaCountForReplicaSets([]*appsv1.ReplicaSet{newRS})
if r.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount != nil && newRSAvailableCount == *r.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount {
return true
} else if reconcileBlueGreenTemplateChange(r) {
return false
} else if newRS != nil && activeRS != nil && activeRS.Name == newRS.Name {
return false
}
return r.Status.BlueGreen.ScaleUpPreviewCheckPoint
}

// Should run only on scaling events and not during the normal rollout process.
func (c *Controller) scaleBlueGreen(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, oldRSs []*appsv1.ReplicaSet, previewSvc *corev1.Service, activeSvc *corev1.Service) error {
rolloutReplicas := defaults.GetRolloutReplicasOrDefault(rollout)
Expand Down
52 changes: 51 additions & 1 deletion controller/bluegreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)
rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
rs2 := newReplicaSetWithStatus(r2, "foo-5f79b78d7f", 1, 1)
Expand Down Expand Up @@ -173,6 +174,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)

rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
Expand Down Expand Up @@ -212,6 +214,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)

rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
Expand Down Expand Up @@ -245,6 +248,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)
r2.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds = pointer.Int32Ptr(10)

Expand Down Expand Up @@ -279,6 +283,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)
r2.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds = pointer.Int32Ptr(10)

Expand Down Expand Up @@ -322,7 +327,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
assert.Equal(t, expectedPatch, rolloutPatch)
})

t.Run("SkipWhenNoPreviewSpecified", func(t *testing.T) {
t.Run("NoPauseWhenAutoPromotionEnabledIsNotSet", func(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "")
Expand Down Expand Up @@ -372,10 +377,53 @@ func TestBlueGreenHandlePause(t *testing.T) {
assert.Equal(t, expectedPatch, rolloutPatch)
})

t.Run("PauseWhenAutoPromotionEnabledIsFalse", func(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)

rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
rs2 := newReplicaSetWithStatus(r2, "foo-5f79b78d7f", 1, 1)
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]

r2 = updateBlueGreenRolloutStatus(r2, "", rs1PodHash, 2, 1, 1, false, true)

progressingCondition, _ := newProgressingCondition(conditions.NewReplicaSetReason, rs2)
conditions.SetRolloutCondition(&r2.Status, progressingCondition)
activeSelector := map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs1PodHash}
activeSvc := newService("active", 80, activeSelector)

f.objects = append(f.objects, r2)
f.kubeobjects = append(f.kubeobjects, activeSvc, rs1, rs2)
f.rolloutLister = append(f.rolloutLister, r2)
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)

f.expectGetServiceAction(activeSvc)

now := metav1.Now().UTC().Format(time.RFC3339)
expectedPatchWithoutSubs := `{
"spec": {
"paused": true
},
"status": {
"pauseStartTime": "%s"
}
}`
expectedPatch := calculatePatch(r2, fmt.Sprintf(expectedPatchWithoutSubs, now))
patchIndex := f.expectPatchRolloutActionWithPatch(r2, expectedPatch)
f.run(getKey(r2, t))

rolloutPatch := f.getPatchedRollout(patchIndex)
assert.Equal(t, expectedPatch, rolloutPatch)
})

t.Run("SkipPreviewWhenActiveHasNoSelector", func(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)

rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
Expand Down Expand Up @@ -419,6 +467,7 @@ func TestBlueGreenHandlePause(t *testing.T) {
f := newFixture(t)

r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r1)

rs1 := newReplicaSetWithStatus(r1, "foo-895c6c4f9", 1, 1)
Expand Down Expand Up @@ -621,6 +670,7 @@ func TestBlueGreenRolloutStatusHPAStatusFieldsActiveSelectorSet(t *testing.T) {
f := newFixture(t)

r := newBlueGreenRollout("foo", 1, nil, "active", "preview")
r.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false)
r2 := bumpVersion(r)

rs1 := newReplicaSetWithStatus(r, "foo-867bc46cdc", 1, 1)
Expand Down
4 changes: 4 additions & 0 deletions controller/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/utils/defaults"
logutil "github.com/argoproj/argo-rollouts/utils/log"
)

Expand Down Expand Up @@ -50,6 +51,9 @@ func calculatePauseStatus(rollout *v1alpha1.Rollout, addPause bool) (*metav1.Tim
if !paused {
pauseStartTime = nil
}
if rollout.Spec.Strategy.BlueGreenStrategy != nil && defaults.GetAutoPromotionEnabledOrDefault(rollout) {
return nil, false
}

if addPause {
if pauseStartTime == nil {
Expand Down
6 changes: 6 additions & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ spec:
description: Name of the service that the rollout modifies as
the active service.
type: string
autoPromotionEnabled:
description: AutoPromotionEnabled indicates if the rollout should
automatically promote the new ReplicaSet to the active service
or enter a paused state. If not specified, the default value
is true.
type: boolean
autoPromotionSeconds:
description: AutoPromotionSeconds automatically promotes the
current ReplicaSet to active after the specified pause delay
Expand Down
Loading