From 5ab83af27cfdbc0d0cbc7b6afec2f601175303ac Mon Sep 17 00:00:00 2001 From: Adam Jordens Date: Thu, 19 Oct 2017 20:00:11 -0700 Subject: [PATCH] feat(provider/amazon): Rollback support for PREVIOUS_IMAGE strategy (#4291) Rolling back to a previous image is available iff: - a `spinnaker:metadata` entity tag exists with `previousServerGroup` details - there are no other server groups in the cluster/region --- .../rollbackServerGroup.controller.js | 30 +++++++++++++- .../details/rollback/rollbackServerGroup.html | 41 +++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.controller.js b/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.controller.js index 1d5bc44a089..80aefd47b69 100644 --- a/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.controller.js +++ b/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.controller.js @@ -2,6 +2,7 @@ const angular = require('angular'); +import { get } from 'lodash'; import { SERVER_GROUP_WRITER, TASK_MONITOR_BUILDER } from '@spinnaker/core'; module.exports = angular.module('spinnaker.amazon.serverGroup.details.rollback.controller', [ @@ -18,6 +19,28 @@ module.exports = angular.module('spinnaker.amazon.serverGroup.details.rollback.c var desired = serverGroup.capacity.desired; + var rollbackType = 'EXPLICIT'; + + if (allServerGroups.length === 0 && serverGroup.entityTags) { + const previousServerGroup = get(serverGroup, 'entityTags.creationMetadata.value.previousServerGroup'); + if (previousServerGroup) { + rollbackType = 'PREVIOUS_IMAGE'; + $scope.previousServerGroup = { + name: previousServerGroup.name, + imageName: previousServerGroup.imageName + }; + + if (previousServerGroup.imageId && previousServerGroup.imageId !== previousServerGroup.imageName) { + $scope.previousServerGroup.imageId = previousServerGroup.imageId; + } + + const buildNumber = get(previousServerGroup, 'buildInfo.jenkins.number'); + if (buildNumber) { + $scope.previousServerGroup.buildNumber = buildNumber; + } + } + } + if (desired < 10) { var healthyPercent = 100; } else if (desired < 20) { @@ -28,7 +51,7 @@ module.exports = angular.module('spinnaker.amazon.serverGroup.details.rollback.c } $scope.command = { - rollbackType: 'EXPLICIT', + rollbackType: rollbackType, rollbackContext: { rollbackServerGroupName: serverGroup.name, targetHealthyRollbackPercentage: healthyPercent @@ -53,6 +76,11 @@ module.exports = angular.module('spinnaker.amazon.serverGroup.details.rollback.c return false; } + if (rollbackType === 'PREVIOUS_IMAGE') { + // no need to validate when using an explicit image + return true; + } + return command.rollbackContext.restoreServerGroupName !== undefined; }; diff --git a/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.html b/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.html index 229b1b5ca2e..732e0ccc996 100644 --- a/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.html +++ b/app/scripts/modules/amazon/src/serverGroup/details/rollback/rollbackServerGroup.html @@ -10,13 +10,25 @@

Rollback {{serverGroup.name}}

Restore to
-
- +
+ {{ctrl.label($select.selected)}} +
+ {{ previousServerGroup.name }} (no longer deployed)
+ + Image: {{ previousServerGroup.imageName}} + ({{ previousServerGroup.imageId }})
+
+ + Build #{{ previousServerGroup.buildNumber }} + +
@@ -52,7 +64,7 @@

Rollback {{serverGroup.name}}

Rollback Operations -
+
  1. Enable {{ command.rollbackContext.restoreServerGroupName || 'previous server group' }}
  2. @@ -76,6 +88,29 @@

    Rollback {{serverGroup.name}}

+
+
+
    +
  1. Deploy {{ previousServerGroup.imageId }} [ + min: {{serverGroup.capacity.desired}}, + max: {{ serverGroup.capacity.max }}, + desired: {{ serverGroup.capacity.desired }} + ]
    (minimum capacity pinned at {{serverGroup.capacity.desired}} to prevent autoscaling down during deploy) +
  2. + Wait for at least {{minHealthy(command.rollbackContext.targetHealthyRollbackPercentage)}} + instances to report as healthy +
  3. + +
  4. Disable {{ serverGroup.name }}
  5. +
  6. Restore minimum capacity of new server group [ + min: {{ serverGroup.capacity.min }} + ]
  7. +
+

+ This rollback will affect server groups in {{ serverGroup.account }} ({{ serverGroup.region }}). +

+
+