Skip to content

Commit

Permalink
fix(aws): Better support for serializing instanceType (#5111)
Browse files Browse the repository at this point in the history
Moves the instance type determination (launch config vs template) to the `AmazonServerGroup`
and out of the `ServerGroupController`.
  • Loading branch information
ajordens committed Nov 19, 2020
1 parent 7067aba commit 4e0e57c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class AmazonServerGroup implements ServerGroup, Serializable {
return securityGroups
}

@Override
String getInstanceType() {
return launchConfig?.instanceType ?: ((Map<String, String>)launchTemplate?.launchTemplateData)?.instanceType
}

@Override
ServerGroup.InstanceCounts getInstanceCounts() {
Collection<Instance> instances = getInstances()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ default String getType() {
@Empty
Map<String, Object> getLaunchConfig();

default String getInstanceType() {
return null;
}

/**
* A collection of attributes describing the tags of this server group
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ class ServerGroupController {
sg.application = moniker.app
sg.stack = moniker.stack
sg.freeFormDetail = moniker.detail

//The following fields exist in the non-expanded result and so even though there is some
//minor data duplication here it seems reasonable to also set these fields in the expanded result.
if (serverGroup.launchConfig) {
if (serverGroup.launchConfig.instanceType) {
sg.instanceType = serverGroup.launchConfig.instanceType
}
}
if (serverGroup.launchTemplate && serverGroup.launchTemplate.launchTemplateData) {
instanceType = serverGroup.launchTemplate.launchTemplateData.instanceType
}
sg.account = cluster.accountName

return sg
Expand Down Expand Up @@ -301,16 +290,8 @@ class ServerGroupController {
securityGroups = serverGroup.getSecurityGroups()
loadBalancers = serverGroup.getLoadBalancers()
serverGroupManagers = serverGroup.getServerGroupManagers()
instanceType = serverGroup.getInstanceType()
moniker = serverGroup.getMoniker()
if (serverGroup.launchConfig) {
if (serverGroup.launchConfig.instanceType) {
instanceType = serverGroup.launchConfig.instanceType
}
}

if (serverGroup.launchTemplate && serverGroup.launchTemplate.launchTemplateData) {
instanceType = serverGroup.launchTemplate.launchTemplateData.instanceType
}

if (serverGroup.tags) {
tags = serverGroup.tags
Expand Down

0 comments on commit 4e0e57c

Please sign in to comment.