Skip to content

Commit c63b6c1

Browse files
committed
fix: Promote full did not work against BlueGreen with previewReplicaCount (argoproj#1384)
Signed-off-by: Jesse Suen <[email protected]>
1 parent 4622ae4 commit c63b6c1

File tree

5 files changed

+123
-55
lines changed

5 files changed

+123
-55
lines changed

test/e2e/bluegreen_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,103 @@ spec:
278278
Then().
279279
ExpectActiveRevision("2")
280280
}
281+
282+
// TestBlueGreenPreviewReplicaCount verifies the previewReplicaCount feature
283+
func (s *BlueGreenSuite) TestBlueGreenPreviewReplicaCount() {
284+
s.Given().
285+
RolloutObjects(newService("bluegreen-preview-replicas-active")).
286+
RolloutObjects(newService("bluegreen-preview-replicas-preview")).
287+
RolloutObjects(`
288+
apiVersion: argoproj.io/v1alpha1
289+
kind: Rollout
290+
metadata:
291+
name: bluegreen-preview-replicas
292+
spec:
293+
replicas: 2
294+
strategy:
295+
blueGreen:
296+
activeService: bluegreen-preview-replicas-active
297+
previewService: bluegreen-preview-replicas-preview
298+
previewReplicaCount: 1
299+
scaleDownDelaySeconds: 5
300+
autoPromotionEnabled: false
301+
selector:
302+
matchLabels:
303+
app: bluegreen-preview-replicas
304+
template:
305+
metadata:
306+
labels:
307+
app: bluegreen-preview-replicas
308+
spec:
309+
containers:
310+
- name: bluegreen-preview-replicas
311+
image: nginx:1.19-alpine
312+
resources:
313+
requests:
314+
memory: 16Mi
315+
cpu: 1m
316+
`).
317+
When().
318+
ApplyManifests().
319+
WaitForRolloutStatus("Healthy").
320+
UpdateSpec().
321+
WaitForRolloutStatus("Paused").
322+
Then().
323+
ExpectRevisionPodCount("2", 1).
324+
ExpectRevisionPodCount("1", 2).
325+
ExpectReplicaCounts(2, 3, 1, 2, 2). // desired, current, updated, ready, available
326+
When().
327+
PromoteRollout().
328+
WaitForRolloutStatus("Healthy").
329+
Then().
330+
ExpectReplicaCounts(2, 4, 2, 2, 2)
331+
}
332+
333+
// TestBlueGreenPreviewReplicaCountPromoteFull verifies promote full works with previewReplicaCount
334+
func (s *FunctionalSuite) TestBlueGreenPreviewReplicaCountPromoteFull() {
335+
s.Given().
336+
RolloutObjects(newService("bluegreen-preview-replicas-active")).
337+
RolloutObjects(`
338+
apiVersion: argoproj.io/v1alpha1
339+
kind: Rollout
340+
metadata:
341+
name: bluegreen-preview-replicas-promote-full
342+
spec:
343+
replicas: 2
344+
progressDeadlineSeconds: 1 # use a very short value to cause Degraded condition frequently
345+
strategy:
346+
blueGreen:
347+
activeService: bluegreen-preview-replicas-active
348+
previewReplicaCount: 1
349+
autoPromotionEnabled: false
350+
selector:
351+
matchLabels:
352+
app: bluegreen-preview-replicas-promote-full
353+
template:
354+
metadata:
355+
labels:
356+
app: bluegreen-preview-replicas-promote-full
357+
spec:
358+
containers:
359+
- name: bluegreen-preview-replicas-promote-full
360+
image: nginx:1.19-alpine
361+
resources:
362+
requests:
363+
memory: 16Mi
364+
cpu: 1m
365+
`).
366+
When().
367+
ApplyManifests().
368+
WaitForRolloutStatus("Healthy").
369+
UpdateSpec().
370+
WaitForRolloutStatus("Paused").
371+
Sleep(2*time.Second). // sleep for longer than progressDeadlineSeconds
372+
Then().
373+
ExpectRolloutStatus("Paused"). // the fact that we are paused for longer than progressDeadlineSeconds, should not cause Degraded
374+
ExpectReplicaCounts(2, 3, 1, 2, 2). // desired, current, updated, ready, available
375+
When().
376+
PromoteRolloutFull().
377+
WaitForRolloutStatus("Healthy").
378+
Then().
379+
ExpectReplicaCounts(2, 4, 2, 2, 2)
380+
}

test/e2e/functional_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -706,57 +706,6 @@ func (s *FunctionalSuite) TestBlueGreenUpdate() {
706706
})
707707
}
708708

709-
// TestBlueGreenPreviewReplicaCount verifies the previewReplicaCount feature
710-
func (s *FunctionalSuite) TestBlueGreenPreviewReplicaCount() {
711-
s.Given().
712-
RolloutObjects(newService("bluegreen-preview-replicas-active")).
713-
RolloutObjects(newService("bluegreen-preview-replicas-preview")).
714-
RolloutObjects(`
715-
apiVersion: argoproj.io/v1alpha1
716-
kind: Rollout
717-
metadata:
718-
name: bluegreen-preview-replicas
719-
spec:
720-
replicas: 2
721-
strategy:
722-
blueGreen:
723-
activeService: bluegreen-preview-replicas-active
724-
previewService: bluegreen-preview-replicas-preview
725-
previewReplicaCount: 1
726-
scaleDownDelaySeconds: 5
727-
autoPromotionEnabled: false
728-
selector:
729-
matchLabels:
730-
app: bluegreen-preview-replicas
731-
template:
732-
metadata:
733-
labels:
734-
app: bluegreen-preview-replicas
735-
spec:
736-
containers:
737-
- name: bluegreen-preview-replicas
738-
image: nginx:1.19-alpine
739-
resources:
740-
requests:
741-
memory: 16Mi
742-
cpu: 1m
743-
`).
744-
When().
745-
ApplyManifests().
746-
WaitForRolloutStatus("Healthy").
747-
UpdateSpec().
748-
WaitForRolloutStatus("Paused").
749-
Then().
750-
ExpectRevisionPodCount("2", 1).
751-
ExpectRevisionPodCount("1", 2).
752-
ExpectReplicaCounts(2, 3, 1, 2, 2). // desired, current, updated, ready, available
753-
When().
754-
PromoteRollout().
755-
WaitForRolloutStatus("Healthy").
756-
Then().
757-
ExpectReplicaCounts(2, 4, 2, 2, 2)
758-
}
759-
760709
// TestBlueGreenToCanary tests behavior when migrating from bluegreen to canary
761710
func (s *FunctionalSuite) TestBlueGreenToCanary() {
762711
s.Given().

test/fixtures/when.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (w *When) ScaleRollout(scale int) *When {
189189
}
190190

191191
func (w *When) Sleep(d time.Duration) *When {
192+
w.log.Infof("Sleeping %s", d)
192193
time.Sleep(d)
193194
return w
194195
}

utils/replicaset/replicaset.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,32 @@ func FindOldReplicaSets(rollout *v1alpha1.Rollout, rsList []*appsv1.ReplicaSet)
233233
// 2) Max number of pods allowed is reached: deployment's replicas + maxSurge == all RSs' replicas
234234
func NewRSNewReplicas(rollout *v1alpha1.Rollout, allRSs []*appsv1.ReplicaSet, newRS *appsv1.ReplicaSet) (int32, error) {
235235
if rollout.Spec.Strategy.BlueGreen != nil {
236+
desiredReplicas := defaults.GetReplicasOrDefault(rollout.Spec.Replicas)
236237
if rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil {
237238
activeRS, _ := GetReplicaSetByTemplateHash(allRSs, rollout.Status.BlueGreen.ActiveSelector)
238239
if activeRS == nil || activeRS.Name == newRS.Name {
239-
return defaults.GetReplicasOrDefault(rollout.Spec.Replicas), nil
240+
// the active RS is our desired RS. we are already past the blue-green promote step
241+
return desiredReplicas, nil
242+
}
243+
if rollout.Status.PromoteFull {
244+
// we are doing a full promotion. ignore previewReplicaCount
245+
return desiredReplicas, nil
240246
}
241247
if newRS.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] != rollout.Status.CurrentPodHash {
248+
// the desired RS is not equal to our previously recorded current RS.
249+
// This must be a new update, so return previewReplicaCount
242250
return *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount, nil
243251
}
244252
isNotPaused := !rollout.Spec.Paused && len(rollout.Status.PauseConditions) == 0
245253
if isNotPaused && rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint {
246-
return defaults.GetReplicasOrDefault(rollout.Spec.Replicas), nil
254+
// We are not paused, but we are already past our preview scale up checkpoint.
255+
// If we get here, we were resumed after the pause, but haven't yet flipped the
256+
// active service switch to the desired RS.
257+
return desiredReplicas, nil
247258
}
248259
return *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount, nil
249260
}
250-
251-
return defaults.GetReplicasOrDefault(rollout.Spec.Replicas), nil
261+
return desiredReplicas, nil
252262
}
253263
if rollout.Spec.Strategy.Canary != nil {
254264
stableRS := GetStableRS(rollout, newRS, allRSs)

utils/replicaset/replicaset_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func TestNewRSNewReplicasWitPreviewReplicaCount(t *testing.T) {
225225
overrideCurrentPodHash string
226226
scaleUpPreviewCheckpoint bool
227227
expectReplicaCount int32
228+
promoteFull bool
228229
}{
229230
{
230231
name: "No active rs is set",
@@ -253,6 +254,12 @@ func TestNewRSNewReplicasWitPreviewReplicaCount(t *testing.T) {
253254
activeSelector: "bar",
254255
expectReplicaCount: previewReplicaCount,
255256
},
257+
{
258+
name: "Ignore preview replica count during promote full",
259+
activeSelector: "bar",
260+
expectReplicaCount: replicaCount,
261+
promoteFull: true,
262+
},
256263
}
257264
for i := range tests {
258265
test := tests[i]
@@ -272,6 +279,7 @@ func TestNewRSNewReplicasWitPreviewReplicaCount(t *testing.T) {
272279
ActiveSelector: test.activeSelector,
273280
},
274281
CurrentPodHash: "foo",
282+
PromoteFull: test.promoteFull,
275283
},
276284
}
277285
if test.overrideCurrentPodHash != "" {

0 commit comments

Comments
 (0)