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

fix(core): Support wait before scaling down in red/black #1789

Merged
merged 2 commits into from
Nov 9, 2017
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
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
}
}