Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
39b19521f0 | |
|
2ef795e161 | |
|
47934143d3 | |
|
6e129af273 | |
|
c74d7ed330 | |
|
1dd86d705c | |
|
baccc9d412 | |
|
9e59603362 |
|
@ -5,7 +5,7 @@ jobs:
|
|||
docker:
|
||||
# CircleCI Go images available at: https://hub.docker.com/r/circleci/golang/
|
||||
- image: circleci/golang:1.13.1
|
||||
resource_class: large
|
||||
resource_class: xlarge
|
||||
environment:
|
||||
TEST_RESULTS: /tmp/test-results
|
||||
steps:
|
||||
|
|
17
CHANGELOG.md
17
CHANGELOG.md
|
@ -1,4 +1,19 @@
|
|||
# Changelog
|
||||
|
||||
# v0.6.1
|
||||
## Quick Start
|
||||
kubectl create namespace argo-rollouts
|
||||
kubectl apply -n argo-rollouts -f https://raw.githubusercontent.com/argoproj/argo-rollouts/v0.6.1/manifests/install.yaml
|
||||
|
||||
# Changes since v0.6.0
|
||||
## Bug Fixes
|
||||
|
||||
- Create one background analysis per revision (#309)
|
||||
- Fix Infinite loop with PreviewReplicaCount set (#308)
|
||||
- Fix a delete by zero in get command (#310)
|
||||
- Set StableRS hash to current if replicaset does not actually exist (#320)
|
||||
- Bluegreen: allow preview service/replica sets to be replaced and fix sg fault in syncReplicasOnly (#314)
|
||||
|
||||
# v0.6.0
|
||||
## Quick Start
|
||||
```
|
||||
|
@ -263,4 +278,4 @@ Changes the following clusterroles to prevent name collision with Argo Workflows
|
|||
|
||||
# v0.1.0
|
||||
* Creates a controller that manages a rollout object that mimics a deployment object
|
||||
* Declaratively offers a Blue Green Strategy by creating the replicaset from the spec and managing an active and preview service to point to the new replicaset
|
||||
* Declaratively offers a Blue Green Strategy by creating the replicaset from the spec and managing an active and preview service to point to the new replicaset
|
||||
|
|
|
@ -10,4 +10,4 @@ resources:
|
|||
- argo-rollouts-metrics-service.yaml
|
||||
images:
|
||||
- name: argoproj/argo-rollouts
|
||||
newTag: latest
|
||||
newTag: v0.6.1
|
||||
|
|
|
@ -10999,7 +10999,7 @@ spec:
|
|||
containers:
|
||||
- command:
|
||||
- /bin/rollouts-controller
|
||||
image: argoproj/argo-rollouts:latest
|
||||
image: argoproj/argo-rollouts:v0.6.1
|
||||
imagePullPolicy: Always
|
||||
name: argo-rollouts
|
||||
volumeMounts:
|
||||
|
|
|
@ -10900,7 +10900,7 @@ spec:
|
|||
containers:
|
||||
- command:
|
||||
- /bin/rollouts-controller
|
||||
image: argoproj/argo-rollouts:latest
|
||||
image: argoproj/argo-rollouts:v0.6.1
|
||||
imagePullPolicy: Always
|
||||
name: argo-rollouts
|
||||
volumeMounts:
|
||||
|
|
|
@ -67,7 +67,7 @@ func NewRolloutInfo(
|
|||
currentStep, _ := replicasetutil.GetCurrentCanaryStep(ro)
|
||||
if currentStep == nil {
|
||||
roInfo.ActualWeight = "100"
|
||||
} else {
|
||||
} else if ro.Status.AvailableReplicas > 0 {
|
||||
for _, rs := range roInfo.ReplicaSets {
|
||||
if rs.Canary {
|
||||
roInfo.ActualWeight = fmt.Sprintf("%d", (rs.Available*100)/ro.Status.AvailableReplicas)
|
||||
|
|
|
@ -144,6 +144,10 @@ func (c *RolloutController) reconcileBlueGreenPause(activeSvc, previewSvc *corev
|
|||
}
|
||||
|
||||
newRS := roCtx.NewRS()
|
||||
if newRS == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
newRSPodHash := newRS.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
|
||||
if _, ok := activeSvc.Spec.Selector[v1alpha1.DefaultRolloutUniqueLabelKey]; !ok {
|
||||
|
@ -223,6 +227,12 @@ func (c *RolloutController) syncRolloutStatusBlueGreen(previewSvc *corev1.Servic
|
|||
oldRSs := roCtx.OlderRSs()
|
||||
allRSs := roCtx.AllRSs()
|
||||
newStatus := c.calculateBaseStatus(roCtx)
|
||||
|
||||
if replicasetutil.CheckPodSpecChange(r, newRS) {
|
||||
roCtx.PauseContext().ClearPauseConditions()
|
||||
roCtx.PauseContext().RemoveAbort()
|
||||
}
|
||||
|
||||
newStatus.AvailableReplicas = replicasetutil.GetAvailableReplicaCountForReplicaSets([]*appsv1.ReplicaSet{newRS})
|
||||
previewSelector, ok := serviceutil.GetRolloutSelectorLabel(previewSvc)
|
||||
if !ok {
|
||||
|
@ -233,6 +243,7 @@ func (c *RolloutController) syncRolloutStatusBlueGreen(previewSvc *corev1.Servic
|
|||
if !ok {
|
||||
activeSelector = ""
|
||||
}
|
||||
|
||||
newStatus.BlueGreen.ActiveSelector = activeSelector
|
||||
if newStatus.BlueGreen.ActiveSelector != r.Status.BlueGreen.ActiveSelector {
|
||||
previousActiveRS, _ := replicasetutil.GetReplicaSetByTemplateHash(oldRSs, r.Status.BlueGreen.ActiveSelector)
|
||||
|
@ -262,15 +273,23 @@ func (c *RolloutController) syncRolloutStatusBlueGreen(previewSvc *corev1.Servic
|
|||
func calculateScaleUpPreviewCheckPoint(roCtx *blueGreenContext, activeRS *appsv1.ReplicaSet) bool {
|
||||
r := roCtx.Rollout()
|
||||
newRS := roCtx.NewRS()
|
||||
newRSAvailableCount := replicasetutil.GetAvailableReplicaCountForReplicaSets([]*appsv1.ReplicaSet{newRS})
|
||||
if r.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil && newRSAvailableCount == *r.Spec.Strategy.BlueGreen.PreviewReplicaCount {
|
||||
return true
|
||||
} else if reconcileBlueGreenTemplateChange(roCtx) {
|
||||
return false
|
||||
} else if newRS != nil && activeRS != nil && activeRS.Name == newRS.Name {
|
||||
|
||||
if reconcileBlueGreenTemplateChange(roCtx) || r.Spec.Strategy.BlueGreen.PreviewReplicaCount == nil {
|
||||
return false
|
||||
}
|
||||
return r.Status.BlueGreen.ScaleUpPreviewCheckPoint
|
||||
|
||||
if newRS == nil || activeRS == nil || activeRS.Name == newRS.Name {
|
||||
return false
|
||||
}
|
||||
|
||||
// Once the ScaleUpPreviewCheckPoint is set to true, the rollout should keep that value until
|
||||
// the newRS becomes the new activeRS or there is a template change.
|
||||
if r.Status.BlueGreen.ScaleUpPreviewCheckPoint {
|
||||
return r.Status.BlueGreen.ScaleUpPreviewCheckPoint
|
||||
}
|
||||
|
||||
newRSAvailableCount := replicasetutil.GetAvailableReplicaCountForReplicaSets([]*appsv1.ReplicaSet{newRS})
|
||||
return newRSAvailableCount == *r.Spec.Strategy.BlueGreen.PreviewReplicaCount
|
||||
}
|
||||
|
||||
// Should run only on scaling events and not during the normal rollout process.
|
||||
|
@ -303,18 +322,6 @@ func (c *RolloutController) scaleBlueGreen(rollout *v1alpha1.Rollout, newRS *app
|
|||
}
|
||||
}
|
||||
|
||||
previewRS, _ := replicasetutil.GetReplicaSetByTemplateHash(allRS, rollout.Status.BlueGreen.PreviewSelector)
|
||||
if previewRS != nil {
|
||||
previewReplicas := rolloutReplicas
|
||||
if rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil && !rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint {
|
||||
previewReplicas = *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount
|
||||
}
|
||||
if *(previewRS.Spec.Replicas) != previewReplicas {
|
||||
_, _, err := c.scaleReplicaSetAndRecordEvent(previewRS, previewReplicas, rollout)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if newRS != nil {
|
||||
newRSReplicaCount, err := replicasetutil.NewRSNewReplicas(rollout, allRS, newRS)
|
||||
if err != nil {
|
||||
|
|
|
@ -742,6 +742,105 @@ func TestBlueGreenRolloutScaleUpdateActiveRS(t *testing.T) {
|
|||
f.run(getKey(r2, t))
|
||||
}
|
||||
|
||||
func TestPreviewReplicaCountHandleScaleUpPreviewCheckPoint(t *testing.T) {
|
||||
t.Run("TrueAfterMeetingMinAvailable", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
defer f.Close()
|
||||
|
||||
r1 := newBlueGreenRollout("foo", 5, nil, "active", "")
|
||||
r1.Spec.Strategy.BlueGreen.PreviewReplicaCount = pointer.Int32Ptr(3)
|
||||
r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false)
|
||||
rs1 := newReplicaSetWithStatus(r1, 5, 5)
|
||||
r2 := bumpVersion(r1)
|
||||
|
||||
rs2 := newReplicaSetWithStatus(r2, 3, 3)
|
||||
f.kubeobjects = append(f.kubeobjects, rs1, rs2)
|
||||
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)
|
||||
|
||||
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
|
||||
activeSvc := newService("active", 80, map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs1PodHash})
|
||||
|
||||
r2 = updateBlueGreenRolloutStatus(r2, rs2PodHash, rs1PodHash, 3, 3, 8, 5, false, true)
|
||||
f.rolloutLister = append(f.rolloutLister, r2)
|
||||
f.objects = append(f.objects, r2)
|
||||
f.kubeobjects = append(f.kubeobjects, activeSvc)
|
||||
f.serviceLister = append(f.serviceLister, activeSvc)
|
||||
|
||||
patchIndex := f.expectPatchRolloutAction(r1)
|
||||
f.run(getKey(r2, t))
|
||||
patch := f.getPatchedRollout(patchIndex)
|
||||
|
||||
assert.Contains(t, patch, `"scaleUpPreviewCheckPoint":true`)
|
||||
|
||||
})
|
||||
t.Run("FalseAfterActiveServiceSwitch", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
defer f.Close()
|
||||
|
||||
r1 := newBlueGreenRollout("foo", 5, nil, "active", "")
|
||||
r1.Spec.Strategy.BlueGreen.PreviewReplicaCount = pointer.Int32Ptr(3)
|
||||
r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false)
|
||||
rs1 := newReplicaSetWithStatus(r1, 5, 5)
|
||||
now := metav1.Now().Add(10 * time.Second)
|
||||
rs1.Annotations[v1alpha1.DefaultReplicaSetScaleDownDeadlineAnnotationKey] = now.UTC().Format(time.RFC3339)
|
||||
r2 := bumpVersion(r1)
|
||||
|
||||
rs2 := newReplicaSetWithStatus(r2, 5, 5)
|
||||
f.kubeobjects = append(f.kubeobjects, rs1, rs2)
|
||||
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)
|
||||
|
||||
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
|
||||
activeSvc := newService("active", 80, map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs2PodHash})
|
||||
|
||||
r2 = updateBlueGreenRolloutStatus(r2, rs2PodHash, rs1PodHash, 5, 5, 8, 5, false, true)
|
||||
r2.Status.BlueGreen.ScaleUpPreviewCheckPoint = true
|
||||
f.rolloutLister = append(f.rolloutLister, r2)
|
||||
f.objects = append(f.objects, r2)
|
||||
f.kubeobjects = append(f.kubeobjects, activeSvc)
|
||||
f.serviceLister = append(f.serviceLister, activeSvc)
|
||||
|
||||
f.expectPatchReplicaSetAction(rs1)
|
||||
patchIndex := f.expectPatchRolloutAction(r1)
|
||||
|
||||
f.run(getKey(r2, t))
|
||||
patch := f.getPatchedRollout(patchIndex)
|
||||
assert.Contains(t, patch, `"scaleUpPreviewCheckPoint":null`)
|
||||
})
|
||||
t.Run("TrueWhenScalingUpPreview", func(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
defer f.Close()
|
||||
|
||||
r1 := newBlueGreenRollout("foo", 5, nil, "active", "")
|
||||
r1.Spec.Strategy.BlueGreen.PreviewReplicaCount = pointer.Int32Ptr(3)
|
||||
rs1 := newReplicaSetWithStatus(r1, 5, 5)
|
||||
r2 := bumpVersion(r1)
|
||||
|
||||
rs2 := newReplicaSetWithStatus(r2, 3, 3)
|
||||
f.kubeobjects = append(f.kubeobjects, rs1, rs2)
|
||||
f.replicaSetLister = append(f.replicaSetLister, rs1, rs2)
|
||||
|
||||
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
|
||||
activeSvc := newService("active", 80, map[string]string{v1alpha1.DefaultRolloutUniqueLabelKey: rs1PodHash})
|
||||
|
||||
r2 = updateBlueGreenRolloutStatus(r2, rs2PodHash, rs1PodHash, 5, 5, 8, 5, false, true)
|
||||
r2.Status.BlueGreen.ScaleUpPreviewCheckPoint = true
|
||||
f.rolloutLister = append(f.rolloutLister, r2)
|
||||
f.objects = append(f.objects, r2)
|
||||
f.kubeobjects = append(f.kubeobjects, activeSvc)
|
||||
f.serviceLister = append(f.serviceLister, activeSvc)
|
||||
|
||||
f.expectUpdateReplicaSetAction(rs1)
|
||||
f.expectPatchRolloutAction(r2)
|
||||
f.run(getKey(r2, t))
|
||||
})
|
||||
}
|
||||
|
||||
func TestBlueGreenRolloutIgnoringScalingUsePreviewRSCount(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
defer f.Close()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package rollout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
|
@ -34,8 +35,7 @@ func (c *RolloutController) rolloutCanary(rollout *v1alpha1.Rollout, rsList []*a
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stableRS, oldRSs := replicasetutil.GetStableRS(rollout, newRS, previousRSs)
|
||||
roCtx := newCanaryCtx(rollout, newRS, stableRS, oldRSs, exList, arList)
|
||||
roCtx := newCanaryCtx(rollout, newRS, previousRSs, exList, arList)
|
||||
return c.syncRolloutStatusCanary(roCtx)
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,12 @@ func (c *RolloutController) rolloutCanary(rollout *v1alpha1.Rollout, rsList []*a
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stableRS, oldRSs := replicasetutil.GetStableRS(rollout, newRS, previousRSs)
|
||||
|
||||
roCtx := newCanaryCtx(rollout, newRS, stableRS, oldRSs, exList, arList)
|
||||
roCtx := newCanaryCtx(rollout, newRS, previousRSs, exList, arList)
|
||||
logCtx := roCtx.Log()
|
||||
|
||||
logCtx.Info("Cleaning up old replicasets, experiments, and analysis runs")
|
||||
if err := c.cleanupRollouts(oldRSs, roCtx); err != nil {
|
||||
if err := c.cleanupRollouts(roCtx.OlderRSs(), roCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -251,6 +250,7 @@ func (c *RolloutController) syncRolloutStatusCanary(roCtx *canaryContext) error
|
|||
r := roCtx.Rollout()
|
||||
logCtx := roCtx.Log()
|
||||
newRS := roCtx.NewRS()
|
||||
stableRS := roCtx.StableRS()
|
||||
allRSs := roCtx.AllRSs()
|
||||
|
||||
newStatus := c.calculateBaseStatus(roCtx)
|
||||
|
@ -279,8 +279,8 @@ func (c *RolloutController) syncRolloutStatusCanary(roCtx *canaryContext) error
|
|||
return c.persistRolloutStatus(roCtx, &newStatus)
|
||||
}
|
||||
|
||||
if r.Status.Canary.StableRS == "" {
|
||||
msg := "Setting StableRS to CurrentPodHash as it is empty beforehand"
|
||||
if stableRS == nil {
|
||||
msg := fmt.Sprintf("Setting StableRS to CurrentPodHash: StableRS hash: %s", newStatus.CurrentPodHash)
|
||||
logCtx.Info(msg)
|
||||
newStatus.Canary.StableRS = newStatus.CurrentPodHash
|
||||
if stepCount > 0 {
|
||||
|
|
|
@ -62,14 +62,14 @@ func TestReconcileCanaryStepsHandleBaseCases(t *testing.T) {
|
|||
|
||||
// Handle case with no steps
|
||||
r := newCanaryRollout("test", 1, nil, nil, nil, intstr.FromInt(0), intstr.FromInt(1))
|
||||
roCtx := newCanaryCtx(r, nil, nil, nil, nil, nil)
|
||||
roCtx := newCanaryCtx(r, nil, nil, nil, nil)
|
||||
stepResult := controller.reconcileCanaryPause(roCtx)
|
||||
assert.False(t, stepResult)
|
||||
assert.Len(t, fake.Actions(), 0)
|
||||
|
||||
r2 := newCanaryRollout("test", 1, nil, []v1alpha1.CanaryStep{{SetWeight: int32Ptr(10)}}, nil, intstr.FromInt(0), intstr.FromInt(1))
|
||||
r2.Status.CurrentStepIndex = int32Ptr(1)
|
||||
roCtx2 := newCanaryCtx(r2, nil, nil, nil, nil, nil)
|
||||
roCtx2 := newCanaryCtx(r2, nil, nil, nil, nil)
|
||||
stepResult = controller.reconcileCanaryPause(roCtx2)
|
||||
assert.False(t, stepResult)
|
||||
assert.Len(t, fake.Actions(), 0)
|
||||
|
@ -1118,7 +1118,7 @@ func TestNoResumeAfterPauseDurationIfUserPaused(t *testing.T) {
|
|||
r1 := newCanaryRollout("foo", 1, nil, steps, pointer.Int32Ptr(1), intstr.FromInt(1), intstr.FromInt(1))
|
||||
rs1 := newReplicaSetWithStatus(r1, 1, 1)
|
||||
rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey]
|
||||
r1 = updateCanaryRolloutStatus(r1, rs1PodHash, 2, 1, 2, true)
|
||||
r1 = updateCanaryRolloutStatus(r1, rs1PodHash, 1, 1, 1, true)
|
||||
overAMinuteAgo := metav1.Time{Time: time.Now().Add(-61 * time.Second)}
|
||||
r1.Status.ObservedGeneration = conditions.ComputeGenerationHash(r1.Spec)
|
||||
r1.Status.PauseConditions = []v1alpha1.PauseCondition{{
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
analysisutil "github.com/argoproj/argo-rollouts/utils/analysis"
|
||||
experimentutil "github.com/argoproj/argo-rollouts/utils/experiment"
|
||||
logutil "github.com/argoproj/argo-rollouts/utils/log"
|
||||
replicasetutil "github.com/argoproj/argo-rollouts/utils/replicaset"
|
||||
)
|
||||
|
||||
type rolloutContext interface {
|
||||
|
@ -119,11 +120,9 @@ func (bgCtx *blueGreenContext) NewStatus() v1alpha1.RolloutStatus {
|
|||
return bgCtx.newStatus
|
||||
}
|
||||
|
||||
func newCanaryCtx(r *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, stableRS *appsv1.ReplicaSet, olderRSs []*appsv1.ReplicaSet, exList []*v1alpha1.Experiment, arList []*v1alpha1.AnalysisRun) *canaryContext {
|
||||
allRSs := append(olderRSs, newRS)
|
||||
if stableRS != nil {
|
||||
allRSs = append(allRSs, stableRS)
|
||||
}
|
||||
func newCanaryCtx(r *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, otherRSs []*appsv1.ReplicaSet, exList []*v1alpha1.Experiment, arList []*v1alpha1.AnalysisRun) *canaryContext {
|
||||
allRSs := append(otherRSs, newRS)
|
||||
stableRS, oldRSs := replicasetutil.GetStableRS(r, newRS, otherRSs)
|
||||
|
||||
currentArs, otherArs := analysisutil.FilterCurrentRolloutAnalysisRuns(arList, r)
|
||||
currentEx := experimentutil.GetCurrentExperiment(r, exList)
|
||||
|
@ -134,7 +133,7 @@ func newCanaryCtx(r *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, stableRS *appsv
|
|||
log: logCtx,
|
||||
newRS: newRS,
|
||||
stableRS: stableRS,
|
||||
olderRSs: olderRSs,
|
||||
olderRSs: oldRSs,
|
||||
allRSs: allRSs,
|
||||
|
||||
currentArs: currentArs,
|
||||
|
@ -179,7 +178,8 @@ func (cCtx *canaryContext) SetCurrentAnalysisRuns(ars []*v1alpha1.AnalysisRun) {
|
|||
cCtx.currentArs = ars
|
||||
currBackgroundAr := analysisutil.GetCurrentBackgroundAnalysisRun(ars)
|
||||
if currBackgroundAr != nil && !cCtx.PauseContext().IsAborted() {
|
||||
if !currBackgroundAr.Status.Phase.Completed() {
|
||||
switch currBackgroundAr.Status.Phase {
|
||||
case v1alpha1.AnalysisPhasePending, v1alpha1.AnalysisPhaseRunning, v1alpha1.AnalysisPhaseSuccessful, "":
|
||||
cCtx.newStatus.Canary.CurrentBackgroundAnalysisRun = currBackgroundAr.Name
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,18 +77,6 @@ func (c *RolloutController) reconcileNewReplicaSet(roCtx rolloutContext) (bool,
|
|||
}
|
||||
roCtx.Log().Infof("Reconciling new ReplicaSet '%s'", newRS.Name)
|
||||
allRSs := roCtx.AllRSs()
|
||||
if rollout.Spec.Strategy.BlueGreen != nil {
|
||||
rolloutReplicas := defaults.GetReplicasOrDefault(rollout.Spec.Replicas)
|
||||
if *(newRS.Spec.Replicas) == rolloutReplicas {
|
||||
// Scaling not required.
|
||||
return false, nil
|
||||
}
|
||||
if *(newRS.Spec.Replicas) > rolloutReplicas {
|
||||
// Scale down.
|
||||
scaled, _, err := c.scaleReplicaSetAndRecordEvent(newRS, rolloutReplicas, rollout)
|
||||
return scaled, err
|
||||
}
|
||||
}
|
||||
newReplicasCount, err := replicasetutil.NewRSNewReplicas(rollout, allRSs, newRS)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -241,8 +241,7 @@ func (c *RolloutController) syncReplicasOnly(r *v1alpha1.Rollout, rsList []*apps
|
|||
return err
|
||||
}
|
||||
|
||||
stableRS, oldRSs := replicasetutil.GetStableRS(r, newRS, rsList)
|
||||
roCtx := newCanaryCtx(r, newRS, stableRS, oldRSs, exList, arList)
|
||||
roCtx := newCanaryCtx(r, newRS, oldRSs, exList, arList)
|
||||
|
||||
if isScaling {
|
||||
if _, err := c.reconcileCanaryReplicaSets(roCtx); err != nil {
|
||||
|
|
|
@ -261,6 +261,9 @@ func GetStableRS(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, rslist []*
|
|||
if rollout.Status.Canary.StableRS == "" {
|
||||
return nil, rslist
|
||||
}
|
||||
if newRS != nil && newRS.Labels != nil && newRS.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] == rollout.Status.Canary.StableRS {
|
||||
return newRS, rslist
|
||||
}
|
||||
olderRSs := []*appsv1.ReplicaSet{}
|
||||
var stableRS *appsv1.ReplicaSet
|
||||
for i := range rslist {
|
||||
|
|
|
@ -388,6 +388,36 @@ func TestCalculateReplicaCountsForCanaryStableRSdEdgeCases(t *testing.T) {
|
|||
assert.Equal(t, int32(0), stableRSReplicaCount)
|
||||
}
|
||||
|
||||
func TestGetStableRS(t *testing.T) {
|
||||
rs := func(podHash string) appsv1.ReplicaSet {
|
||||
return appsv1.ReplicaSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: podHash,
|
||||
Labels: map[string]string{
|
||||
v1alpha1.DefaultRolloutUniqueLabelKey: podHash,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
rollout := &v1alpha1.Rollout{}
|
||||
rs1 := rs("1")
|
||||
rs2 := rs("2")
|
||||
rs3 := rs("3")
|
||||
noStable, rsList := GetStableRS(rollout, &rs1, []*appsv1.ReplicaSet{&rs2, &rs3})
|
||||
assert.Nil(t, noStable)
|
||||
assert.Len(t, rsList, 2)
|
||||
|
||||
rollout.Status.Canary.StableRS = "1"
|
||||
sameAsNewRS, rsList := GetStableRS(rollout, &rs1, []*appsv1.ReplicaSet{&rs2, &rs3})
|
||||
assert.Equal(t, *sameAsNewRS, rs1)
|
||||
assert.Len(t, rsList, 2)
|
||||
|
||||
stableInOtherRSs, rsList := GetStableRS(rollout, &rs2, []*appsv1.ReplicaSet{&rs1, &rs2, &rs3})
|
||||
assert.Equal(t, *stableInOtherRSs, rs1)
|
||||
assert.Len(t, rsList, 1)
|
||||
|
||||
}
|
||||
func TestGetCurrentCanaryStep(t *testing.T) {
|
||||
rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "", "")
|
||||
rollout.Spec.Strategy.Canary.Steps = nil
|
||||
|
|
|
@ -271,7 +271,7 @@ func checkStepHashChange(rollout *v1alpha1.Rollout) bool {
|
|||
|
||||
// checkPodSpecChange indicates if the rollout spec has changed indicating that the rollout needs to reset the
|
||||
// currentStepIndex to zero. If there is no previous pod spec to compare to the function defaults to false
|
||||
func checkPodSpecChange(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet) bool {
|
||||
func CheckPodSpecChange(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet) bool {
|
||||
if rollout.Status.CurrentPodHash == "" {
|
||||
return false
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ func PodTemplateOrStepsChanged(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaS
|
|||
if checkStepHashChange(rollout) {
|
||||
return true
|
||||
}
|
||||
if checkPodSpecChange(rollout, newRS) {
|
||||
if CheckPodSpecChange(rollout, newRS) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -622,12 +622,12 @@ func TestMaxUnavailable(t *testing.T) {
|
|||
func TestCheckPodSpecChange(t *testing.T) {
|
||||
ro := generateRollout("ngnix")
|
||||
rs := generateRS(ro)
|
||||
assert.False(t, checkPodSpecChange(&ro, &rs))
|
||||
assert.False(t, CheckPodSpecChange(&ro, &rs))
|
||||
ro.Status.CurrentPodHash = controller.ComputeHash(&ro.Spec.Template, ro.Status.CollisionCount)
|
||||
assert.False(t, checkPodSpecChange(&ro, &rs))
|
||||
assert.False(t, CheckPodSpecChange(&ro, &rs))
|
||||
|
||||
ro.Status.CurrentPodHash = "different-hash"
|
||||
assert.True(t, checkPodSpecChange(&ro, &rs))
|
||||
assert.True(t, CheckPodSpecChange(&ro, &rs))
|
||||
}
|
||||
|
||||
func TestCheckStepHashChange(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue