Skip to content

Commit a883fed

Browse files
Elad Ben-Israelmergify[bot]
andcommitted
fix(eks): default capacity uses desiredCapacity which is an anti-pattern (#5651)
* fix(eks): default capacity uses desiredCapacity which is an anti-pattern As described in #5215, `desiredCapacity` is not the recommended way to configure an auto scaling group since it will cause the ASG to reset the number of nodes in every CloudFormation deployment. Since EKS's default capacity uses `desiredCapacity` instead of `minCapacity`, as of #5507 this would emit a warning: "desiredCapacity has been configured. Be aware this will reset the size of your AutoScalingGroup on every deployment". This change modifies the behavior of the default capacity such that it will configure the ASG using `minCapacity` instead of `desiredCapacity` as recommended by ASG. Fixes #5650 * Update integ.eks-cluster.defaults.expected.json Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent e0c41d4 commit a883fed

13 files changed

+16
-22
lines changed

packages/@aws-cdk/aws-eks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ You can add customized capacity through `cluster.addCapacity()` or
8888
```ts
8989
cluster.addCapacity('frontend-nodes', {
9090
instanceType: new ec2.InstanceType('t2.medium'),
91-
desiredCapacity: 3,
91+
minCapacity: 3,
9292
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }
9393
});
9494
```
@@ -125,7 +125,7 @@ you can use `kubeletExtraArgs` to add custom node labels or taints.
125125
// up to ten spot instances
126126
cluster.addCapacity('spot', {
127127
instanceType: new ec2.InstanceType('t3.large'),
128-
desiredCapacity: 2,
128+
minCapacity: 2,
129129
bootstrapOptions: {
130130
kubeletExtraArgs: '--node-labels foo=bar,goo=far',
131131
awsApiRetryAttempts: 5

packages/@aws-cdk/aws-eks/lib/cluster.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ export class Cluster extends Resource implements ICluster {
401401
}
402402

403403
// allocate default capacity if non-zero (or default).
404-
const desiredCapacity = props.defaultCapacity === undefined ? DEFAULT_CAPACITY_COUNT : props.defaultCapacity;
405-
if (desiredCapacity > 0) {
404+
const minCapacity = props.defaultCapacity === undefined ? DEFAULT_CAPACITY_COUNT : props.defaultCapacity;
405+
if (minCapacity > 0) {
406406
const instanceType = props.defaultCapacityInstance || DEFAULT_CAPACITY_TYPE;
407-
this.defaultCapacity = this.addCapacity('DefaultCapacity', { instanceType, desiredCapacity });
407+
this.defaultCapacity = this.addCapacity('DefaultCapacity', { instanceType, minCapacity });
408408
}
409409

410410
const outputConfigCommand = props.outputConfigCommand === undefined ? true : props.outputConfigCommand;

packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.expected.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,7 @@
10391039
"Type": "AWS::AutoScaling::AutoScalingGroup",
10401040
"Properties": {
10411041
"MaxSize": "2",
1042-
"MinSize": "1",
1043-
"DesiredCapacity": "2",
1042+
"MinSize": "2",
10441043
"LaunchConfigurationName": {
10451044
"Ref": "ClusterDefaultCapacityLaunchConfig72790CF7"
10461045
},
@@ -1380,4 +1379,4 @@
13801379
"Default": "/aws/service/eks/optimized-ami/1.14/amazon-linux-2/recommended/image_id"
13811380
}
13821381
}
1383-
}
1382+
}

packages/@aws-cdk/aws-eks/test/integ.eks-cluster.kubectl-disabled.expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,6 @@
941941
"Properties": {
942942
"MaxSize": "1",
943943
"MinSize": "1",
944-
"DesiredCapacity": "1",
945944
"LaunchConfigurationName": {
946945
"Ref": "EKSClusterNodesLaunchConfig921F1106"
947946
},

packages/@aws-cdk/aws-eks/test/integ.eks-cluster.kubectl-disabled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class EksClusterStack extends TestStack {
1818

1919
cluster.addCapacity('Nodes', {
2020
instanceType: new ec2.InstanceType('t2.medium'),
21-
desiredCapacity: 1, // Raise this number to add more nodes
21+
minCapacity: 1, // Raise this number to add more nodes
2222
});
2323
/// !hide
2424
}

packages/@aws-cdk/aws-eks/test/integ.eks-cluster.lit.expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,6 @@
10401040
"Properties": {
10411041
"MaxSize": "1",
10421042
"MinSize": "1",
1043-
"DesiredCapacity": "1",
10441043
"LaunchConfigurationName": {
10451044
"Ref": "EKSClusterNodesLaunchConfig921F1106"
10461045
},

packages/@aws-cdk/aws-eks/test/integ.eks-cluster.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EksClusterStack extends TestStack {
1717

1818
cluster.addCapacity('Nodes', {
1919
instanceType: new ec2.InstanceType('t2.medium'),
20-
desiredCapacity: 1, // Raise this number to add more nodes
20+
minCapacity: 1, // Raise this number to add more nodes
2121
});
2222
/// !hide
2323
}

packages/@aws-cdk/aws-eks/test/integ.eks-helm.lit.expected.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@
948948
"Type": "AWS::AutoScaling::AutoScalingGroup",
949949
"Properties": {
950950
"MaxSize": "3",
951-
"MinSize": "1",
952-
"DesiredCapacity": "3",
951+
"MinSize": "3",
953952
"LaunchConfigurationName": {
954953
"Ref": "cluster22NodesLaunchConfig184BF3BA"
955954
},

packages/@aws-cdk/aws-eks/test/integ.eks-helm.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ClusterStack extends TestStack {
3838
// automatically be mapped via aws-auth to allow nodes to join the cluster.
3939
this.cluster.addCapacity('Nodes', {
4040
instanceType: new ec2.InstanceType('t2.medium'),
41-
desiredCapacity: 3,
41+
minCapacity: 3,
4242
});
4343

4444
// add two Helm charts to the cluster. This will be the Kubernetes dashboard and the Nginx Ingress Controller

packages/@aws-cdk/aws-eks/test/integ.eks-kubectl.lit.expected.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@
948948
"Type": "AWS::AutoScaling::AutoScalingGroup",
949949
"Properties": {
950950
"MaxSize": "3",
951-
"MinSize": "1",
952-
"DesiredCapacity": "3",
951+
"MinSize": "3",
953952
"LaunchConfigurationName": {
954953
"Ref": "cluster22NodesLaunchConfig184BF3BA"
955954
},

0 commit comments

Comments
 (0)