Skip to content

Commit

Permalink
backward compatibility added, if no maxcount and cpsize provided, jus…
Browse files Browse the repository at this point in the history
…t create normal ASG.
  • Loading branch information
Victor Bi committed Apr 9, 2021
1 parent b515148 commit 60d08f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
15 changes: 5 additions & 10 deletions api/backend/ecs/environment_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func (e *ECSEnvironmentManager) CreateEnvironment(
keyPair := config.AWSKeyPair()
launchConfigurationName := ecsEnvironmentID.LaunchConfigurationName()
volSizes := make(map[string]int)
if operatingSystem == "linux" {
volSizes["/dev/xvda"] = 30;
if operatingSystem == "linux" {
volSizes["/dev/xvda"] = 30
} else {
volSizes["/dev/sda1"] = 200
}
Expand All @@ -219,21 +219,16 @@ func (e *ECSEnvironmentManager) CreateEnvironment(
); err != nil {
return nil, err
}

//set the default value
maxCountToSetInASG := maxClusterCount
if minClusterCount > maxClusterCount {
maxClusterCount = minClusterCount
}
if targetCapSize == 0 {
targetCapSize = 100
maxCountToSetInASG = minClusterCount
}

if err := e.AutoScaling.CreateAutoScalingGroup(
ecsEnvironmentID.AutoScalingGroupName(),
launchConfigurationName,
config.AWSPrivateSubnets(),
minClusterCount,
maxClusterCount,
maxCountToSetInASG,
); err != nil {
return nil, err
}
Expand Down
29 changes: 22 additions & 7 deletions common/aws/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,28 @@ func (this *ECS) CreateCapacityProvider(CapacityProviderName string, AsgArn stri

func (this *ECS) CreateCluster(clusterName string, asgArn string, maxScalingSize, minScalingSize, targetCapSize int) (*Cluster, error) {

capacityProvider, err := this.CreateCapacityProvider(clusterName, asgArn, maxScalingSize, minScalingSize, targetCapSize)
if err != nil {
return nil, err
}
input := &ecs.CreateClusterInput{
ClusterName: aws.String(clusterName),
CapacityProviders: []*string{aws.String(*capacityProvider.Name)},
var input *ecs.CreateClusterInput
//ASG section. If CapSize and maxClusterCount equals to default 0.
classicASGEnabled := targetCapSize == 0 && maxScalingSize == 0
if classicASGEnabled {
input = &ecs.CreateClusterInput{
ClusterName: aws.String(clusterName),
}
} else { //If capacitor provider is enabled.
if minScalingSize > maxScalingSize {
maxScalingSize = minScalingSize
}
if targetCapSize == 0 {
targetCapSize = 100
}
capacityProvider, err := this.CreateCapacityProvider(clusterName, asgArn, maxScalingSize, minScalingSize, targetCapSize)
if err != nil {
return nil, err
}
input = &ecs.CreateClusterInput{
ClusterName: aws.String(clusterName),
CapacityProviders: []*string{aws.String(*capacityProvider.Name)},
}
}

connection, err := this.Connect()
Expand Down

0 comments on commit 60d08f1

Please sign in to comment.