-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(aws_eks): New isolated subnets (CDK 1.140) leads to error in cdk's EKS logic #19122
Comments
Hey @ThomasSteinbach 👋🏻 Thanks for opening the issue with us. Have you tried using the latest SubnetType API? |
@ryparker , @otaviomacedo I have updated the bug description for also CDK v2. Meanwhile we have migrated from CDK v1 to v2 and got the error in a different form with I also added a complete, self contained example of how to reproduce the error. The only thing you need is an AWS account with a VPC containing |
Hi @otaviomacedo , as assignee to this issue I'd like to inform you that I have updated the bug description with a new section "Solution". There I've described how to fix this bug as CDK/TS developer. In short: Simply add the newly introduced isolated subnets to the dummy VPC here: |
Thanks, @ThomasSteinbach. I haven't had time to look into this yet, but rest assured that I'll do it this week. In the meantime, if you want to create a PR with your solution, go ahead and I'll be happy to review it. |
) The lack of isolated subnet groups in the dummy response causes VPC lookups to fail. Fixes #19122. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
UPDATE 2022-03-04: This is definately a bug and I've got a solution. See the last chapter Workaround / Solution at the very end of my bug report.
What is the problem?
The problem is that the VPC and EKS construct doesn't work properly with the newly introduced aws_ec2.SubnetType.ISOLATED in CDK 1.140 ( see #18638) as well with the aws_ec2.SubnetType.PRIVATE_ISOLATED and aws_ec2.SubnetType.PRIVATE_WITH_NAT.
Problems especially occur on imported VPCs which just have "isolated" (formerly "private") subnets.
CDK v1
With CDK 1.140 former private networks were recognized as isolated networks - see #18638
As a result of this we had to change the parameter for aws_eks.Cluster(vpc_subnets) to
[aws_ec2.SubnetSelection(subnet_type=aws_ec2.SubnetType.ISOLATED)]
.However the new isolated subnets seem to collide with the aws_eks.Cluster(endpoint_access) value of
aws_eks.EndpointAccess.PRIVATE
:CDK v2
After migrating to CDK v2 we have changed the aws_ec2.SubnetType.ISOLATED (v1) to aws_ec2.SubnetType.PRIVATE_ISOLATED (v2). This is because the AWS
cdk-cli
will store our VPC subnets within thecdk.context.json
as "isolated":Synthesizing the app leads to the exact same error as with the previous CDK v1 example:
Reproduction Steps
mkdir /tmp/bug && cd /tmp/bug
cdk init --language=python
bug/bug_stack.py
):cdk synth
should lead to the following error:Oddness / "Workaround"
When changing the subnet type to
PRIVATE_WITH_NAT
...... and running
cdk synth
again, thecdk-cli
is doing a real lookup into our AWS account and will create acdk.context.json
with following content:The synthsization itself will exit with following error:
Now an important behavior to mention: With this
cdk.context.json
present, when changing the subnet selection back toPRIVATE_ISOLATED
thecdk synth
will work!That mean on the one hand CDK will fail to pass the subnet type checks of the EKS construct before doing the lookups, because CDK just passes "fake" public/private (private_with_nat) subnets to the EKS construct. If CDK reads the sunbnets from the
cdk.context.json
, cdk passes the proper isolated (private_isolated) subnets to EKS. On the other hand CDK fails to accept the isolated (private_isolated) subnets as "private" (private_with_nat) subnets in the VPC construct. That wrong logic definately needs to be fixed.What did you expect to happen?
I'd expect to happen that the code will synthesize with
ISOLATED
(v1)/PRIVATE_ISOLATED
(v1) subnets as before with private subnets.We changed nothing but the subnet selection from private to isolated networks, as the cdk lookup detects our networks as 'isolated' since cdk 1.140.
What actually happened?
cdk synth
complains aboutCDK CLI Version
3.13.0 (build b0b744d)
Framework Version
1.144 / 2.13.0
Node.js Version
v16.13.0
OS
Linux/Mac/Win
Language
Python
Language Version
Python 3.7, 3.8, 3.9, 3.10
UPDATES after new insights from 2022-03-04
Solution
The bug is, that on unresolved VPC lookups CDK uses a dummy VPC which doesn't contain isolated subnets.
So if you filter your subnets for any construct for only isolated subnets, the list of subnets returned is empy. This causes all the errors shown, as in my example of the EKS construct.
CDK returns this dummy VPC when either the
cdk.context.json
is not available or the lookup is not possible (e.g. you have no api access to your AWS account).The solution for CDK developers should be to also add isolated subnets to the dummy VPC here (link for CDK v2.15.0):
https://github.com/aws/aws-cdk/blob/v2.15.0/packages/%40aws-cdk/aws-ec2/lib/vpc.ts#L2172
Please forgive me, that I didn't provide a merge request myself. I mainly use CDK in Python and never got into JS/TS.
Workaround (Python)
With the solution in mind we created a workaround, we created our custom VPC singleton whenever we got the dummy VPC. Our custom VPC includes isolated subnets. Because this dummy vpc is only used on unresolved VPC lookups, this VPC never gets into the real deployed stack, where the actual lookup will succeed.
The text was updated successfully, but these errors were encountered: