-
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
(jsii)(v2): Cannot apply Aspects to EKS cluster stack #16625
Comments
Hi, @keepler-ivanmarques. Thanks for catching this. The fully qualified name of the class in Python is Marking this as a V2 GA milestone bug. |
Aha, found it. The issue here is lazy loading. jsii doesn't know about the Adding this to the project makes it synth correctly: from aws_cdk import custom_resources, lambda_layer_awscli, lambda_layer_kubectl It's not specific to Aspects... any form of I'm not sure what the best solution is. Obviously we need to load the type information whenever necessary from either side (from Python side or from JavaScript side), but I don't know how to best arrange that. I'm also guessing this is not a v2-specific error. Pretty sure the exact same code would be broken for v1 as well. |
Huh.For reasons that I don't quite fathom, it does not happen for v1: setup.py install_requires=[
"aws-cdk.core==1.126.0",
"aws-cdk.aws-eks==1.126.0",
"aws-cdk.aws-ec2==1.126.0",
"aws-cdk.aws-iam==1.126.0",
], app.py #!/usr/bin/env python3
import os
import jsii
from aws_cdk.core import App, IAspect, Aspects, Tags, Stack, Environment
from aws_cdk import aws_eks as eks, aws_iam as iam, aws_ec2 as ec2
from constructs import Construct, IConstruct
# from aws_cdk import custom_resources, lambda_layer_awscli, lambda_layer_kubectl
@jsii.implements(IAspect)
class PermissionsBoundary:
def __init__(self, permission_boundary_arn: str):
self.permissions_boundary_arn = permission_boundary_arn
def visit(self, node: IConstruct):
print("Visited", node.node.path)
class EksCluster(Stack):
def __init__(self, scope: Construct, id: str, vpc_id:str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
vpc = ec2.Vpc.from_lookup(self, "VPC", vpc_id=vpc_id)
eks_cluster_role = iam.Role(self, id + "-role",
assumed_by=iam.ServicePrincipal("eks.amazonaws.com"),
managed_policies=[
iam.ManagedPolicy.from_aws_managed_policy_name("AmazonEKSServicePolicy"),
iam.ManagedPolicy.from_aws_managed_policy_name("AmazonEKSClusterPolicy")])
eks_master_role = iam.Role(self, id + "-admin",
assumed_by=iam.AccountRootPrincipal())
cluster = eks.Cluster(self, id,
masters_role=eks_master_role,
version=eks.KubernetesVersion.V1_21,
role=eks_cluster_role,
vpc=vpc,
endpoint_access=eks.EndpointAccess.PRIVATE,
default_capacity=0,
output_cluster_name=True,
output_masters_role_arn=True
)
# CDK app
app = App()
env_EU = Environment(region="eu-west-1", account=os.getenv('CDK_DEFAULT_ACCOUNT'))
stack = EksCluster(app, "test-cdkv2-eks-cluster", vpc_id=os.getenv('VPC_ID'), env=env_EU )
Aspects.of(stack).add(PermissionsBoundary(f"arn:aws:iam::{os.getenv('ACCOUNT_ID')}:policy/platform-main-boundary"))
app.synth() Synths fine... |
Pretty sure it works fine in v1 because import aws_cdk.aws_autoscaling._jsii
import aws_cdk.aws_ec2._jsii
import aws_cdk.aws_iam._jsii
import aws_cdk.aws_kms._jsii
import aws_cdk.aws_lambda._jsii
import aws_cdk.aws_lambda_nodejs._jsii
import aws_cdk.aws_ssm._jsii
import aws_cdk.core._jsii
import aws_cdk.custom_resources._jsii
import aws_cdk.lambda_layer_awscli._jsii
import aws_cdk.lambda_layer_kubectl._jsii
import aws_cdk.lambda_layer_node_proxy_agent._jsii
import constructs._jsii And for v2 there is no such file! |
Generating the appropriate |
Callbacks may make references to types from submodules of loaded packages, however due to how the type registration works in the Python runtime, if the submodule has not been loaded, then the types it contains are not registered and will fail resolving. The simplest possible fix is to preemtively load all submodules upfront at the end of the root module's `__init__.py` file, which guarantees that all types have correctly been registered in the runtime (at the expense of some time and memory). Fixes aws/aws-cdk#16625
Callbacks may make references to types from submodules of loaded packages, however due to how the type registration works in the Python runtime, if the submodule has not been loaded, then the types it contains are not registered and will fail resolving. The simplest possible fix is to preemtively load all submodules upfront at the end of the root module's `__init__.py` file, which guarantees that all types have correctly been registered in the runtime (at the expense of some time and memory). Fixes aws/aws-cdk#16625
|
This was fixed in the underlying software (jsii), and will go out with the next jsii release (this week). We will then include this fix in the next CDK v2 release. |
Hi! is this fix be available in CDK V2rc24? Thanks |
@keepler-ivanmarques - Yes, rc24 depends on [email protected], which contains the fix. |
Hi again! Using the same example with rc24 i'm getting this error:
` |
I had the same issue as @keepler-ivanmarques posted above that package.json not found when declaring EKS Cluster in my stack. (using TypeScript/JavaScript). I believe this is a separate issue, created #17059 to track that. |
I'm trying to apply Aspects to a EKS cluster stack, but it fails with a jsii.errors.JavaScriptError. The reason to apply aspects is to apply permission boundaries to every role generated.
Is there any way to work-around this situation? i'm interested in modifying the roles generated by EKS custom resources E.G: Kubectlhandler.
Reproduction Steps
What did you expect to happen?
Print the node paths of every node.
What actually happened?
jsii.errors.JavaScriptError:
Error: Unknown type: aws-cdk-lib.custom_resources.Provider
at KernelHost.completeCallback (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/tmprxijvdhs/lib/program.js:9675:35)
at KernelHost.callbackHandler (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/tmprxijvdhs/lib/program.js:9666:41)
at Object.value (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/tmprxijvdhs/lib/program.js:8536:49)
at recurse (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:83:20)
at recurse (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:95:17)
at recurse (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:95:17)
at recurse (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:95:17)
at invokeAspects (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:69:5)
at Object.synthesize (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/private/synthesis.js:15:5)
at App.synth (/private/var/folders/dk/g35p0fxd719dz_nbyct9y1b40000gp/T/jsii-kernel-wOF0bw/node_modules/aws-cdk-lib/lib/core/lib/stage.js:97:41)
Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: