[aws-eks] Support adding cdk8s charts to the Cluster #9670
Labels
@aws-cdk/aws-eks
Related to Amazon Elastic Kubernetes Service
effort/large
Large work item – several weeks of effort
feature-request
A feature should be added or improved.
in-progress
This issue is being actively worked on.
p1
Milestone
I'd like to be able to build a CDK EKS application that uses cdk8s for the manifest creation part.
Use Case
The
eks.Cluster
construct offers a way of applying Kubernetes manifests as part of the CDK application:This is great, as is it keeps all the moving parts in one place, not having to resort to external
kubectl
commands in order to deploy resources into the cluster.However, this method doesn't offer any type assistance or special capabilities that relate to kubernetes objects, nor it should. It simply accepts a generic object of type
any
. To help create manifests, i'd like to utilize the cdk8s project, and combine it with my CDK application.Since the
cdk8s.Chart
construct has atoJson
method that essentially serializes the objects into a well formatted manifest, i want to do something like this::Proposed Solution
Still don't have a concrete solution to this, but it seems mainly related to making
aws-cdk
andcdk8s
work with a mutually compatible version ofconstructs
.Other
I already did some digging as to the root cause why its actually not working. The snippet i pasted above, produces the following error upon synth:
What happens is that
chart.toJson
will try to resolve any tokens in the object spec, and eventually call the following code from cdk8s:Notice that if refers to tokens classes (
Tokenization
,DefaultTokenResolver
,StringConcat
) from theconstructs
library. Now, the version ofconstructs
thats being used is the one declared by the@aws-cdk/aws-eks
dependency, which is version3.0.3
, and indeed, the token mechanism was removed from this version and these classes no longer exist there.Its worth mentioning that cdk8s itself declares the correct dependency on constructs (for it), i.e
2.0.2
, however, this version is not being installed because theconstructs
dependency is only declared as apeerDependency
in cdk8s. This is intentional because there can only be one version ofconstructs
in the build closure.With a little npm trickery, I managed to eventually force every part of the code to use the correct version of
constructs
, and managed to successfully synth.I then attempted to use a CDK token inside my cdk8s objects, and things broke down again. The following code:
produced this error:
This happens because cdk8s is trying to resolve a CDK token in the context of a cdk8s construct. Resolving the cdk token involves doing
Stack.of(scope)
, where scope is actuallycdk8s.Chart
. TheStack.of
function eventually callsscope.node
, but.node
is not available inconstructs
version2.0.2
.There is I hit the roadblock, there is no way to synthetically augment the
construct
of version2.0.2
to include.node
. And actually, even if there was, it would probably still not work sincecdk8s.Chart
is indeed not acdk.Stack
, so I imagine the following error would have been eventually thrown:Not sure what the correct way forward here, this requires some additional investigation.
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: