Skip to content

Commit

Permalink
Merge branch 'master' into sagemaker-l2
Browse files Browse the repository at this point in the history
  • Loading branch information
petermeansrock authored Mar 11, 2020
2 parents d16127e + 3d99cbf commit 83a3ac2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-eks/lib/kubectl-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { CfnResource, Construct, Stack, Token } from '@aws-cdk/core';
import * as crypto from 'crypto';

const KUBECTL_APP_ARN = 'arn:aws:serverlessrepo:us-east-1:903779448426:applications/lambda-layer-kubectl';
const KUBECTL_APP_CN_ARN = 'arn:aws-cn:serverlessrepo:cn-north-1:487369736442:applications/lambda-layer-kubectl';

const KUBECTL_APP_VERSION = '1.13.7';

export interface KubectlLayerProps {
Expand Down Expand Up @@ -56,7 +58,7 @@ export class KubectlLayer extends Construct implements lambda.ILayerVersion {
type: 'AWS::Serverless::Application',
properties: {
Location: {
ApplicationId: KUBECTL_APP_ARN,
ApplicationId: this.isChina() ? KUBECTL_APP_CN_ARN : KUBECTL_APP_ARN,
SemanticVersion: version
},
Parameters: {
Expand All @@ -75,4 +77,9 @@ export class KubectlLayer extends Construct implements lambda.ILayerVersion {
public addPermission(_id: string, _permission: lambda.LayerVersionPermission): void {
return;
}

public isChina(): boolean {
const region = this.stack.region;
return !Token.isUnresolved(region) && region.startsWith('cn-');
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks/lib/kubectl-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class KubectlProvider extends NestedStack {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
timeout: Duration.minutes(15),
layers: [ KubectlLayer.getOrCreate(this, { version: "2.0.0-beta1" }) ],
layers: [ KubectlLayer.getOrCreate(this, { version: "2.0.0-beta2" }) ],
memorySize: 256,
});

Expand Down
18 changes: 9 additions & 9 deletions packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@
},
"/",
{
"Ref": "AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690S3BucketE6BD216D"
"Ref": "AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859S3BucketBA51B749"
},
"/",
{
Expand All @@ -1766,7 +1766,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690S3VersionKey27D33001"
"Ref": "AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859S3VersionKey723A87EA"
}
]
}
Expand All @@ -1779,7 +1779,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690S3VersionKey27D33001"
"Ref": "AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859S3VersionKey723A87EA"
}
]
}
Expand Down Expand Up @@ -1913,17 +1913,17 @@
"Type": "String",
"Description": "Artifact hash for asset \"809b8ac7e88704d37fac32bbd5cfa56be7ea4d3e9ddb682d216c4b6868cd8fa2\""
},
"AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690S3BucketE6BD216D": {
"AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859S3BucketBA51B749": {
"Type": "String",
"Description": "S3 bucket for asset \"5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690\""
"Description": "S3 bucket for asset \"6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859\""
},
"AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690S3VersionKey27D33001": {
"AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859S3VersionKey723A87EA": {
"Type": "String",
"Description": "S3 key for asset version \"5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690\""
"Description": "S3 key for asset version \"6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859\""
},
"AssetParameters5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690ArtifactHash19392521": {
"AssetParameters6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859ArtifactHash22D2ECF0": {
"Type": "String",
"Description": "Artifact hash for asset \"5736fa6dc98806541544f2c33f17a2495fe0723bd1e59ec62991d68ac3a6e690\""
"Description": "Artifact hash for asset \"6a008e167065eeab066c7f96e7f3c21c2636476b93c075681fba2953ae54a859\""
},
"AssetParameters6348c4414dfcbc19ed407c51ecc75d12faf4ee3219e972437d4ceed53e5b79a0S3BucketEF51ACE0": {
"Type": "String",
Expand Down
44 changes: 44 additions & 0 deletions packages/@aws-cdk/aws-eks/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as eks from '../lib';
import { KubectlLayer } from '../lib/kubectl-layer';
import { spotInterruptHandler } from '../lib/spot-interrupt-handler';
import { testFixture, testFixtureNoVpc } from './util';

Expand Down Expand Up @@ -32,6 +33,49 @@ export = {
test.done();
},

'create custom cluster correctly in any aws region'(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'stack', { env: { region: 'us-east-1' } });

// WHEN
const vpc = new ec2.Vpc(stack, 'VPC');
new eks.Cluster(stack, 'Cluster', { vpc, kubectlEnabled: true, defaultCapacity: 0 });
const layer = KubectlLayer.getOrCreate(stack, {});

// THEN
expect(stack).to(haveResource('Custom::AWSCDK-EKS-Cluster'));
expect(stack).to(haveResourceLike('AWS::Serverless::Application', {
Location: {
ApplicationId: 'arn:aws:serverlessrepo:us-east-1:903779448426:applications/lambda-layer-kubectl',
}
}));
test.equal(layer.isChina(), false);
test.done();
},

'create custom cluster correctly in any aws region in china'(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'stack', { env: { region: 'cn-north-1' } });

// WHEN
const vpc = new ec2.Vpc(stack, 'VPC');
new eks.Cluster(stack, 'Cluster', { vpc, kubectlEnabled: true, defaultCapacity: 0 });
new KubectlLayer(stack, 'NewLayer');
const layer = KubectlLayer.getOrCreate(stack);

// THEN
expect(stack).to(haveResource('Custom::AWSCDK-EKS-Cluster'));
expect(stack).to(haveResourceLike('AWS::Serverless::Application', {
Location: {
ApplicationId: 'arn:aws-cn:serverlessrepo:cn-north-1:487369736442:applications/lambda-layer-kubectl',
}
}));
test.equal(layer.isChina(), true);
test.done();
},

'if "vpc" is not specified, vpc with default configuration will be created'(test: Test) {
// GIVEN
const { stack } = testFixtureNoVpc();
Expand Down

0 comments on commit 83a3ac2

Please sign in to comment.