Skip to content

Commit

Permalink
refactor(aws): Updating launch template rollout flag (#4955)
Browse files Browse the repository at this point in the history
- made flag to consider app:account:test
- added an exclude list for apps

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jeyrschabu and mergify[bot] committed Sep 29, 2020
1 parent b1f58e3 commit c697cba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Expand Up @@ -387,23 +387,40 @@ class AutoScalingWorker {
* This is used to gradually roll out launch template.
*/
private boolean shouldSetLaunchTemplate() {
// Request level flag that forces launch configurations.
if (!setLaunchTemplate) {
return false
}

// Property flag to turn off launch template feature. Caching agent might require bouncing the java process
if (!dynamicConfigService.isEnabled("aws.features.launch-templates", false)) {
log.debug("Launch Template feature disabled via configuration.")
return false
}

// application allow list: app1,app2
// This is a comma separated list of applications to exclude
String excludedApps = dynamicConfigService
.getConfig(String.class, "aws.features.launch-templates.excluded-applications", "")
if (application in excludedApps.split(",")) {
return false
}

// Application allow list with the following format:
// app1:account:region1,region2,app2:account:region1
// This allows more control over what account and region pairs to enable for this deployment.
String allowedApps = dynamicConfigService
.getConfig(String.class, "aws.features.launch-templates.allowed-applications", "")
if (application in allowedApps.split(",")) {
return true
for (appAccountRegion in allowedApps.split(",")) {
if (appAccountRegion && appAccountRegion.contains(":")) {
def (app, account, regions) = appAccountRegion.split(":")
if (app == application && account == credentials.name && this.region in (regions as String).split(",")) {
return true
}
}
}

// account:region allow list
// Final check is an allow list for account/region pairs with the following format:
// account:region
String allowedAccountsAndRegions = dynamicConfigService
.getConfig(String.class, "aws.features.launch-templates.allowed-accounts-regions", "")
for (accountRegion in allowedAccountsAndRegions.split(",")) {
Expand Down
Expand Up @@ -110,6 +110,7 @@ class AutoScalingWorkerUnitSpec extends Specification {
def mockAutoScalingWorker = Spy(AutoScalingWorker)
mockAutoScalingWorker.application = "myasg"
mockAutoScalingWorker.stack = "stack"
mockAutoScalingWorker.region = "us-east-1"
mockAutoScalingWorker.freeFormDetails = "details"
mockAutoScalingWorker.credentials = credential
mockAutoScalingWorker.regionScopedProvider = regionScopedProvider
Expand All @@ -127,7 +128,8 @@ class AutoScalingWorkerUnitSpec extends Specification {

then:
1 * dynamicConfigService.isEnabled('aws.features.launch-templates', false) >> true
1 * dynamicConfigService.getConfig(_, _, _) >> { "myasg" }
1 * dynamicConfigService.getConfig(String.class, "aws.features.launch-templates.excluded-applications", "") >> ""
1 * dynamicConfigService.getConfig(String.class,"aws.features.launch-templates.allowed-applications", "") >> { "myasg:foo:us-east-1" }
1 * mockAutoScalingWorker.createAutoScalingGroup(expectedAsgName, null, { it.launchTemplateId == "id" }) >> {}
(sequence == null ? 1 : 0) * clusterProvider.getCluster('myasg', 'test', 'myasg-stack-details') >> { null }
0 * clusterProvider._
Expand Down Expand Up @@ -161,7 +163,8 @@ class AutoScalingWorkerUnitSpec extends Specification {

then:
1 * dynamicConfigService.isEnabled('aws.features.launch-templates', false) >> true
1 * dynamicConfigService.getConfig(_, _, _) >> { "myasg" }
1 * dynamicConfigService.getConfig(String.class, "aws.features.launch-templates.excluded-applications", "") >> ""
1 * dynamicConfigService.getConfig(String.class,"aws.features.launch-templates.allowed-applications", "") >> { "myasg:foo:us-east-1" }
1 * launchTemplateService.createLaunchTemplate(_,_,_,_) >>
new LaunchTemplate(launchTemplateId: "id", latestVersionNumber: 0, launchTemplateName: "lt")
1 * clusterProvider.getCluster('myasg', 'test', 'myasg') >> {
Expand Down

0 comments on commit c697cba

Please sign in to comment.