Skip to content

Commit 5197882

Browse files
authored
fix(eks): eks cluster name exceeding the limit of 100 characters (#34449)
### Issue # (if applicable) Relates to #30632 but does not close the issue. ### Reason for this change The cluster name can exceed 100 characters, which exceeds the limit for EKS. ### Description of changes - Check if the cluster name exceeds 100 characters - If it does, throw a validation error ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Added unit test ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent ac0e4ca commit 5197882

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,11 @@ export class Cluster extends ClusterBase {
16971697
throw new ValidationError('Cannot specify serviceIpv4Cidr with ipFamily equal to IpFamily.IP_V6', this);
16981698
}
16991699

1700+
// Check if the cluster name exceeds 100 characters
1701+
if (!Token.isUnresolved(this.physicalName) && this.physicalName.length > 100) {
1702+
throw new ValidationError('Cluster name cannot be more than 100 characters', this);
1703+
}
1704+
17001705
this.validateRemoteNetworkConfig(props);
17011706

17021707
this.authenticationMode = props.authenticationMode;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ describe('cluster', () => {
112112
}).toThrow(/Cannot specify clusterHandlerSecurityGroup without placeClusterHandlerInVpc set to true/);
113113
});
114114

115+
test('throws when cluster name exceeds 100 characters', () => {
116+
const { stack } = testFixture();
117+
const longClusterName = 'X'.repeat(200);
118+
119+
expect(() => {
120+
new eks.Cluster(stack, 'Cluster', {
121+
version: CLUSTER_VERSION,
122+
clusterName: longClusterName,
123+
kubectlLayer: new KubectlV31Layer(stack, 'KubectlLayer'),
124+
});
125+
}).toThrow(/Cluster name cannot be more than 100 characters/);
126+
});
127+
115128
describe('imported Vpc from unparseable list tokens', () => {
116129
let stack: cdk.Stack;
117130
let vpc: ec2.IVpc;

0 commit comments

Comments
 (0)