Skip to content

Commit

Permalink
feat(monitored deploy): Support rollback on failure (#3222)
Browse files Browse the repository at this point in the history
* feat(monitored deploy): Support rollback on failure

Add rollback support to monitored deploy strategy.
It's slightly different from the default you get with CreateServerGroup, hence it is removed from there for this strategy

* fix(tests): added happy path tests
  • Loading branch information
marchello2000 authored Oct 15, 2019
1 parent 8aba734 commit dd5dd1f
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractWaitForClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.ScaleDownClusterTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.WaitForScaleDownClusterTask;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ScaleDownClusterStage extends AbstractClusterWideClouddriverOperationStage {
public static final String PIPELINE_CONFIG_TYPE =
StageDefinitionBuilder.getType(ScaleDownClusterStage.class);

@Autowired
public ScaleDownClusterStage(DynamicConfigService dynamicConfigService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
@Component
@ConditionalOnProperty(value = "monitored-deploy.enabled")
public class EvaluateDeploymentHealthStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE =
StageDefinitionBuilder.getType(EvaluateDeploymentHealthStage.class);

@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
builder.withTask("evaluateDeploymentHealth", EvaluateDeploymentHealthTask.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
@Component
@ConditionalOnProperty(value = "monitored-deploy.enabled")
public class NotifyDeployCompletedStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE =
StageDefinitionBuilder.getType(NotifyDeployCompletedStage.class);

@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
builder.withTask("notifyDeployCompleted", NotifyDeployCompletedTask.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
@Component
@ConditionalOnProperty(value = "monitored-deploy.enabled")
public class NotifyDeployStartingStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE =
StageDefinitionBuilder.getType(NotifyDeployStartingStage.class);

@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
builder.withTask("notifyDeployStarting", NotifyDeployStartingTask.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CreateServerGroupStage extends AbstractDeployStrategyStage {
def additionalRollbackContext = [:]

def strategy = Strategy.fromStrategyKey(stageData.strategy)
if ((strategy == Strategy.ROLLING_RED_BLACK) || (strategy == Strategy.MONITORED)) {
if (strategy == Strategy.ROLLING_RED_BLACK) {
// rollback is always supported regardless of where the failure occurred
strategySupportsRollback = true
additionalRollbackContext.enableAndDisableOnly = true
Expand Down Expand Up @@ -156,7 +156,7 @@ class CreateServerGroupStage extends AbstractDeployStrategyStage {
super.onFailureStages(stage, graph)
}

private static class StageData {
static class StageData {
String application
String account
String credentials
Expand Down Expand Up @@ -186,7 +186,7 @@ class CreateServerGroupStage extends AbstractDeployStrategyStage {
}
}

private static class Rollback {
static class Rollback {
Boolean onFailure
Boolean destroyLatest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ExplicitRollback implements Rollback {
Map disableServerGroupContext = new HashMap(parentStage.context)
disableServerGroupContext.serverGroupName = rollbackServerGroupName
def disableServerGroupStage = newStage(
parentStage.execution, disableServerGroupStage.type, "disable", disableServerGroupContext, parentStage, SyntheticStageOwner.STAGE_AFTER
parentStage.execution, disableServerGroupStage.type, "Disable ${disableServerGroupContext.serverGroupName} due to rollback", disableServerGroupContext, parentStage, SyntheticStageOwner.STAGE_AFTER
)

if (disableOnly) {
Expand All @@ -105,7 +105,7 @@ class ExplicitRollback implements Rollback {
enableServerGroupContext.targetHealthyDeployPercentage = targetHealthyRollbackPercentage
enableServerGroupContext.serverGroupName = restoreServerGroupName
def enableServerGroupStage = newStage(
parentStage.execution, enableServerGroupStage.type, "enable", enableServerGroupContext, parentStage, SyntheticStageOwner.STAGE_AFTER
parentStage.execution, enableServerGroupStage.type, "Enable ${enableServerGroupContext.serverGroupName} due to rollback", enableServerGroupContext, parentStage, SyntheticStageOwner.STAGE_AFTER
)

if (enableAndDisableOnly) {
Expand Down Expand Up @@ -254,7 +254,7 @@ class ExplicitRollback implements Rollback {
return newStage(
parentStage.execution,
applySourceServerGroupCapacityStage.type,
"Restore Min Capacity From Snapshot",
"Restore Min Capacity From Snapshot due to rollback",
applySourceServerGroupCapacityContext,
parentStage,
SyntheticStageOwner.STAGE_AFTER
Expand Down
Loading

0 comments on commit dd5dd1f

Please sign in to comment.