eks: cannot deploy multiple EKS clusters within the same stack
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the bug
We cannot use multiple EKS clusters within the same stack.
It seems that the cause is the hardcoded ID of the `KubectlLayer`.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
2.160.0
### Expected Behavior
Deploys successfully.
### Current Behavior
Fails to deploy.
### Reproduction Steps
```ts
import * as eks from 'aws-cdk-lib/aws-eks';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { getClusterVersionConfig } from './integ-tests-kubernetes-version';
class MultipleEksClusterStack extends Stack {
constructor(scope: App, id: string) {
super(scope, id);
const vpc = new ec2.Vpc(this, 'Vpc', { natGateways: 1 });
new eks.Cluster(this, 'EnabledCluster', {
vpc,
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
bootstrapSelfManagedAddons: true,
});
new eks.Cluster(this, 'DisabledCluster', {
vpc,
...getClusterVersionConfig(this, eks.KubernetesVersion.V1_30),
bootstrapSelfManagedAddons: false,
});
}
}
```
Results
```sh
/Users/kazuhoshinozuka/git/aws-cdk/node_modules/constructs/lib/construct.js:375
throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
^
Error: There is already a Construct with name 'KubectlLayer' in MultipleEksClusterStack [EksClusterStack]
at Node.addChild (/Users/kazuhoshinozuka/git/aws-cdk/node_modules/constructs/lib/construct.js:375:19)
at new Node (/Users/kazuhoshinozuka/git/aws-cdk/node_modules/constructs/lib/construct.js:38:21)
at new Construct (/Users/kazuhoshinozuka/git/aws-cdk/node_modules/constructs/lib/construct.js:426:21)
at new Resource (/Users/kazuhoshinozuka/git/aws-cdk/packages/aws-cdk-lib/core/lib/resource.js:32:9)
at new LayerVersion (/Users/kazuhoshinozuka/git/aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/layers.js:57:9)
at new KubectlV30Layer (/Users/kazuhoshinozuka/git/aws-cdk/node_modules/@aws-cdk/lambda-layer-kubectl-v30/lib/kubectl-layer.js:13:9)
at getClusterVersionConfig (/Users/kazuhoshinozuka/git/aws-cdk/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ-tests-kubernetes-version.js:27:23)
at new EksClusterStack (/Users/kazuhoshinozuka/git/aws-cdk/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-bootstrap-self-managed-addons.js:19:77)
at Object. (/Users/kazuhoshinozuka/git/aws-cdk/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-bootstrap-self-managed-addons.js:25:15)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.160.0
### Framework Version
_No response_
### Node.js Version
v22.9.0
### OS
macOS
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start with getClusterVersionConfig in packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ-tests-kubernetes-version.js and the integ.eks-bootstrap-self-managed-addons.js reproduction. Trace how each EKS cluster creates KubectlV30Layer and inspect the aws-eks implementation for the hardcoded construct ID. Done means the integration case can synthesize and deploy both clusters without a construct-name collision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, kubernetes, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100