aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[aws-eks] document how to define dependencies between k8s resources

Open lkoniecz opened this issue 7 years ago • 7 comments

Kubernetes resources are not deployed in the order they were added via add_resource method. If one of them is a namespace, for instance, others fail with a namespace not found error.

Reproduction Steps

eks_cluster = aws_eks.Cluster(..)
eks_cluster.add_resource('namespace', namespace_resource)
eks_cluster.add_resource('resource_1', resource_1_deployed_in_the_namespace)
..
eks_cluster.add_resource('resource_n', resource_n_deployed_in_the_namespace)

Error Log

  2/53 | 10:48:01 | CREATE_IN_PROGRESS   | Custom::AWSCDK-EKS-KubernetesResource | DevEksCluster/DevEksCluster/manifest-NginxRole/Resource/Default (DevEksClustermanifestNginxRoleEE01848C) Resource creation Initiated
  3/53 | 10:48:01 | CREATE_FAILED        | Custom::AWSCDK-EKS-KubernetesResource | DevEksCluster/DevEksCluster/manifest-NginxRole/Resource/Default (DevEksClustermanifestNginxRoleEE01848C) Failed to create resource. b'Error from server (NotFound): error when creating "/tmp/manifest.yaml": namespaces "ingress-nginx" not found\n'
	new CustomResource (/tmp/jsii-kernel-jIZKhq/node_modules/@aws-cdk/aws-cloudformation/lib/custom-resource.js:32:25)
	\_ new KubernetesResource (/tmp/jsii-kernel-jIZKhq/node_modules/@aws-cdk/aws-eks/lib/k8s-resource.js:22:9)
	\_ Cluster.addResource (/tmp/jsii-kernel-jIZKhq/node_modules/@aws-cdk/aws-eks/lib/cluster.js:215:16)
	\_ _wrapSandboxCode (/home/lky/Repositories/HuuugeStarsCfConfig/contrib/cloudformation/cdk/eks/cluster/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6498:51)
	\_ Kernel._wrapSandboxCode (/home/lky/Repositories/HuuugeStarsCfConfig/contrib/cloudformation/cdk/eks/cluster/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7131:20)
	\_ ret._ensureSync (/home/lky/Repositories/HuuugeStarsCfConfig/contrib/cloudformation/cdk/eks/cluster/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6498:25)
	\_ Kernel._ensureSync (/home/lky/Repositories/HuuugeStarsCfConfig/contrib/cloudformation/cdk/eks/cluster/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7102:20)

Environment

  • CLI Version :1.4.0
  • Framework Version:1.4.0
  • OS :all
  • Language :all

Other


This is :bug: Bug Report

lkoniecz avatar Sep 30 '19 08:09 lkoniecz

Can be fixed by adding cloudformation dependecies - https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.core.README.html#dependencies

to be closed

lkoniecz avatar Oct 16 '19 06:10 lkoniecz

Yes, dependencies can be used to specify order between resources. We should add some example in the EKS module's README that demonstrates this.

eladb avatar Oct 16 '19 14:10 eladb

Can anyone please help me, I have been trying this thing for 5 days. I have a custom resource in AWS YAML format, which I want to create in AWS CDK. I am able to add condition and ServiceToken using AWS CDK CfnCustomResource but I can't add properties. Please help me to find out the solution.

YAML Template

LookupAmi:
Condition: UseGI
Properties:
  ServiceToken:
      Fn::ImportValue: !Join ['', [!If [ MyProd, '', 'qa-'], Prod-LookupAmiFunction]]
  AMI: {Ref: AMI}      
  appId: {Ref: AppId}
  envType: {Ref: EnvType}
  osType: {Ref: OSType}
Type: Custom::AmiLookup

Corresponding AWS CDK typescript code which is working.

const LookupAmi = new cfn.CfnCustomResource(this, 'LookupAmi', {
  serviceToken : "DSDS"  # Just a random value but it is working



});LookupAmi.cfnOptions.condition = UseGI

I want to add properties of YAML template, how could I do it. Please help me........

VinayRana5674 avatar Jan 31 '20 15:01 VinayRana5674

@lkoniecz @eladb What if there's dependencies in the manifest yaml itself? As you already know, k8s itself recommend to have all the related objects in a yaml. So there's some case one manifest contains several objects with dependencies. For instance, cloudwatch agent's quickstart has namespace deployment as the very first step for its manifest. I wonder what you guys think of dealing with this.

yjw113080 avatar Mar 18 '20 07:03 yjw113080

@yjw113080 I found no other way than splitting the yaml into dependend pieces, in my case, namaspace into one file and all namespaced objects into the other.

lkoniecz avatar Mar 18 '20 11:03 lkoniecz

Yes, dependencies can be used to specify order between resources. We should add some example in the EKS module's README that demonstrates this.

@eladb can you provide an example of how to do this? I am trying to create a dependency between namespace and helm chart.

farshadniayeshpour avatar Apr 23 '20 00:04 farshadniayeshpour

@FarshadNiayesh I ran into a similar situation and provided an example on how to create a dependency between two helm charts. But it would also work to provide a dependency between the namespace & chart: https://github.com/aws/aws-cdk/issues/7592#issuecomment-619598485

arjanschaaf avatar Apr 26 '20 18:04 arjanschaaf