Skip to content

Commit

Permalink
fix(core): Support wait before scaling down in red/black (#1789)
Browse files Browse the repository at this point in the history
Set `delayBeforeScaleDownSec` in your stage context.
  • Loading branch information
ajordens authored Nov 9, 2017
1 parent 7c17d88 commit f752ad6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RedBlackStrategy implements Strategy, ApplicationContextAware {
stages << newStage(
stage.execution,
waitStage.type,
"wait",
"Wait Before Disable",
waitContext,
stage,
SyntheticStageOwner.STAGE_AFTER
Expand All @@ -110,6 +110,18 @@ class RedBlackStrategy implements Strategy, ApplicationContextAware {
)

if (stageData.scaleDown) {
if(stageData?.getDelayBeforeScaleDown()) {
def waitContext = [waitTime: stageData?.getDelayBeforeScaleDown()]
stages << newStage(
stage.execution,
waitStage.type,
"Wait Before Scale Down",
waitContext,
stage,
SyntheticStageOwner.STAGE_AFTER
)
}

def scaleDown = baseContext + [
allowScaleDownActive : false,
remainingFullSizeServerGroups: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class StageData {

@Deprecated
long delayBeforeDisableSec
long delayBeforeScaleDownSec

long delayBeforeCleanup
PipelineBeforeCleanup pipelineBeforeCleanup
Expand Down Expand Up @@ -67,6 +68,10 @@ class StageData {
return this.delayBeforeCleanup ?: this.delayBeforeDisableSec
}

long getDelayBeforeScaleDown() {
return this.delayBeforeScaleDownSec
}

@Deprecated
List<String> getRegions() {
availabilityZones?.keySet()?.toList() ?: (region ? [region] : [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.netflix.spinnaker.moniker.Moniker
import com.netflix.spinnaker.orca.clouddriver.pipeline.cluster.DisableClusterStage
import com.netflix.spinnaker.orca.clouddriver.pipeline.cluster.ScaleDownClusterStage
import com.netflix.spinnaker.orca.clouddriver.pipeline.cluster.ShrinkClusterStage
import com.netflix.spinnaker.orca.pipeline.WaitStage
import com.netflix.spinnaker.orca.pipeline.model.Execution
import com.netflix.spinnaker.orca.pipeline.model.Stage
import com.netflix.spinnaker.orca.pipeline.model.SyntheticStageOwner
Expand All @@ -30,25 +31,29 @@ class RedBlackStrategySpec extends Specification {
def ShrinkClusterStage shrinkClusterStage = new ShrinkClusterStage()
def ScaleDownClusterStage scaleDownClusterStage = new ScaleDownClusterStage()
def DisableClusterStage disableClusterStage = new DisableClusterStage()
def WaitStage waitStage = new WaitStage()

def "should compose flow"() {
given:
Moniker moniker = new Moniker(app: "unit", stack: "test");
Moniker moniker = new Moniker(app: "unit", stack: "tests");
def ctx = [
account : "testAccount",
application : "unit",
stack : "tests",
moniker : moniker,
cloudProvider : "aws",
region : "north",
availabilityZones: [
north: ["pole-1a"]
]
account : "testAccount",
application : "unit",
stack : "tests",
moniker : moniker,
cloudProvider : "aws",
region : "north",
availabilityZones : [
north: ["pole-1a"]
]
]
def stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
def strat = new RedBlackStrategy(shrinkClusterStage: shrinkClusterStage,
scaleDownClusterStage: scaleDownClusterStage,
disableClusterStage: disableClusterStage)
def stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
def strat = new RedBlackStrategy(
shrinkClusterStage: shrinkClusterStage,
scaleDownClusterStage: scaleDownClusterStage,
disableClusterStage: disableClusterStage,
waitStage: waitStage
)

when:
def syntheticStages = strat.composeFlow(stage)
Expand All @@ -71,7 +76,7 @@ class RedBlackStrategySpec extends Specification {

when:
ctx.maxRemainingAsgs = 10
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
syntheticStages = strat.composeFlow(stage)
beforeStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_BEFORE }
afterStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_AFTER }
Expand All @@ -85,7 +90,7 @@ class RedBlackStrategySpec extends Specification {

when:
ctx.scaleDown = true
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
syntheticStages = strat.composeFlow(stage)
beforeStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_BEFORE }
afterStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_AFTER }
Expand All @@ -100,7 +105,7 @@ class RedBlackStrategySpec extends Specification {

when:
ctx.interestingHealthProviderNames = ["Google"]
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
stage = new Stage(Execution.newPipeline("orca"), "whatever", ctx)
syntheticStages = strat.composeFlow(stage)
beforeStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_BEFORE }
afterStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_AFTER }
Expand All @@ -110,5 +115,23 @@ class RedBlackStrategySpec extends Specification {
afterStages.size() == 3
afterStages.first().type == shrinkClusterStage.type
afterStages.first().context.interestingHealthProviderNames == ["Google"]

when:
ctx.delayBeforeDisableSec = 5
ctx.delayBeforeScaleDownSec = 10
stage = new Stage(Execution.newPipeline("orca"), "resize", ctx)
syntheticStages = strat.composeFlow(stage)
beforeStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_BEFORE }
afterStages = syntheticStages.findAll { it.syntheticStageOwner == SyntheticStageOwner.STAGE_AFTER }

then:
beforeStages.isEmpty()
afterStages[0].type == shrinkClusterStage.type
afterStages[1].type == waitStage.type
afterStages[1].context.waitTime == 5
afterStages[2].type == disableClusterStage.type
afterStages[3].type == waitStage.type
afterStages[3].context.waitTime == 10
afterStages[4].type == scaleDownClusterStage.type
}
}

0 comments on commit f752ad6

Please sign in to comment.