Skip to content

Commit

Permalink
feat(eks): support for Kubernetes version 1.23 (#22638)
Browse files Browse the repository at this point in the history
Add support for Kubernetes Version 1.23. In order to use this version, customers must pass in a `KubectlLayer` object from `@aws-cdk/lambda-layer-kubectl-v23` to the `kubectlLayer` construct prop of `Cluster`.

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc committed Oct 27, 2022
1 parent 66d1ed3 commit 4e858f2
Show file tree
Hide file tree
Showing 63 changed files with 220 additions and 164 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -91,6 +91,8 @@
"@aws-cdk/aws-cognito/punycode/**",
"@aws-cdk/aws-ecr-assets/minimatch",
"@aws-cdk/aws-ecr-assets/minimatch/**",
"@aws-cdk/aws-eks/semver",
"@aws-cdk/aws-eks/semver/**",
"@aws-cdk/aws-eks/yaml",
"@aws-cdk/aws-eks/yaml/**",
"@aws-cdk/aws-events-targets/aws-sdk",
Expand Down
15 changes: 13 additions & 2 deletions packages/@aws-cdk/aws-eks/lib/cluster.ts
Expand Up @@ -8,6 +8,7 @@ import * as lambda from '@aws-cdk/aws-lambda';
import * as ssm from '@aws-cdk/aws-ssm';
import { Annotations, CfnOutput, CfnResource, IResource, Resource, Stack, Tags, Token, Duration, Size } from '@aws-cdk/core';
import { Construct, Node } from 'constructs';
import * as semver from 'semver';
import * as YAML from 'yaml';
import { AlbController, AlbControllerOptions } from './alb-controller';
import { AwsAuth } from './aws-auth';
Expand Down Expand Up @@ -853,6 +854,15 @@ export class KubernetesVersion {
*/
public static readonly V1_22 = KubernetesVersion.of('1.22');

/**
* Kubernetes version 1.23
*
* When creating a `Cluster` with this version, you need to also specify the
* `kubectlLayer` property with a `KubectlV23Layer` from
* `@aws-cdk/lambda-layer-kubectl-v23`.
*/
public static readonly V1_23 = KubernetesVersion.of('1.23');

/**
* Custom cluster version
* @param version custom version number
Expand Down Expand Up @@ -1372,8 +1382,9 @@ export class Cluster extends ClusterBase {
this.prune = props.prune ?? true;
this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc');

if (props.version === KubernetesVersion.V1_22 && !props.kubectlLayer) {
Annotations.of(this).addWarning(`You created a cluster with Kubernetes Version ${props.version} without specifying the kubectlLayer property. This may cause failures as the kubectl version provided with aws-cdk-lib is 1.20, which is only guaranteed to be compatible with Kubernetes versions 1.19-1.21. Please provide a kubectlLayer from @aws-cdk/lambda-layer-kubectl-v22.`);
const kubectlVersion = new semver.SemVer(`${props.version.version}.0`);
if (semver.gte(kubectlVersion, '1.22.0') && !props.kubectlLayer) {
Annotations.of(this).addWarning(`You created a cluster with Kubernetes Version ${props.version.version} without specifying the kubectlLayer property. This may cause failures as the kubectl version provided with aws-cdk-lib is 1.20, which is only guaranteed to be compatible with Kubernetes versions 1.19-1.21. Please provide a kubectlLayer from @aws-cdk/lambda-layer-kubectl-v${kubectlVersion.minor}.`);
};
this.version = props.version;
this.kubectlLambdaRole = props.kubectlLambdaRole ? props.kubectlLambdaRole : undefined;
Expand Down
8 changes: 5 additions & 3 deletions packages/@aws-cdk/aws-eks/package.json
Expand Up @@ -80,8 +80,8 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/lambda-layer-kubectl-v22": "2.0.0",
"aws-cdk-lib": "2.47.0",
"@aws-cdk/lambda-layer-kubectl-v23": "^2.0.0",
"aws-cdk-lib": "^2.47.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
Expand All @@ -95,7 +95,7 @@
"aws-sdk": "^2.1211.0",
"cdk8s": "^2.5.28",
"cdk8s-plus-21": "^2.0.0-beta.12",
"cdk8s-plus-22": "^2.0.0-rc.158",
"cdk8s-plus-23": "2.0.2",
"jest": "^27.5.1",
"sinon": "^9.2.4"
},
Expand All @@ -113,9 +113,11 @@
"@aws-cdk/lambda-layer-kubectl": "0.0.0",
"@aws-cdk/lambda-layer-node-proxy-agent": "0.0.0",
"constructs": "^10.0.0",
"semver": "^7.3.8",
"yaml": "1.10.2"
},
"bundledDependencies": [
"semver",
"yaml"
],
"homepage": "https://github.com/aws/aws-cdk",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"files": {
"c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30": {
"dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d": {
"source": {
"path": "asset.c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"path": "asset.dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"objectKey": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down Expand Up @@ -144,15 +144,15 @@
}
}
},
"c6b7a3e3c841118ec365de6b3227d6ec23618b7716c20175c7f18822b22fa08d": {
"1e8f5b9efc22fb7df3c3a0e894ec6ddf91d5b71c100c70638ff47b2379c3a749": {
"source": {
"path": "aws-cdk-eks-cluster-alb-controller-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c6b7a3e3c841118ec365de6b3227d6ec23618b7716c20175c7f18822b22fa08d.json",
"objectKey": "1e8f5b9efc22fb7df3c3a0e894ec6ddf91d5b71c100c70638ff47b2379c3a749.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Expand Up @@ -402,9 +402,9 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
"S3Key": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip"
},
"Description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"Description": "/opt/kubectl/kubectl 1.23; /opt/helm/helm 3.9",
"LicenseInfo": "Apache-2.0"
}
},
Expand Down Expand Up @@ -608,7 +608,7 @@
]
},
"Config": {
"version": "1.22",
"version": "1.23",
"roleArn": {
"Fn::GetAtt": [
"ClusterRoleFA261979",
Expand Down
Expand Up @@ -23,7 +23,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c6b7a3e3c841118ec365de6b3227d6ec23618b7716c20175c7f18822b22fa08d.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1e8f5b9efc22fb7df3c3a0e894ec6ddf91d5b71c100c70638ff47b2379c3a749.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -168,7 +168,10 @@
"/aws-cdk-eks-cluster-alb-controller-test/KubectlLayer/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "KubectlLayer600207B5"
"data": "KubectlLayer600207B5",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
]
}
],
"/aws-cdk-eks-cluster-alb-controller-test/Cluster/Role/Resource": [
Expand Down
Expand Up @@ -691,9 +691,9 @@
"s3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"s3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
"s3Key": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip"
},
"description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"description": "/opt/kubectl/kubectl 1.23; /opt/helm/helm 3.9",
"licenseInfo": "Apache-2.0"
}
},
Expand All @@ -704,7 +704,7 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/lambda-layer-kubectl-v22.KubectlV22Layer",
"fqn": "@aws-cdk/lambda-layer-kubectl-v23.KubectlV23Layer",
"version": "2.0.0"
}
},
Expand Down
40 changes: 39 additions & 1 deletion packages/@aws-cdk/aws-eks/test/cluster.test.ts
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { Match, Template } from '@aws-cdk/assertions';
import { Annotations, Match, Template } from '@aws-cdk/assertions';
import * as asg from '@aws-cdk/aws-autoscaling';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
Expand Down Expand Up @@ -3073,6 +3073,44 @@ describe('cluster', () => {
});
});

describe('kubectlLayer annotation', () => {
function message(version: string) {
return [
'You created a cluster with Kubernetes Version 1.23 without specifying the kubectlLayer property.',
'This may cause failures as the kubectl version provided with aws-cdk-lib is 1.20, which is only guaranteed to be compatible with Kubernetes versions 1.19-1.21.',
`Please provide a kubectlLayer from @aws-cdk/lambda-layer-kubectl-v${version}.`,
].join(' ');
}

test('not added when version < 1.22 and no kubectl layer provided', () => {
// GIVEN
const { stack } = testFixture();

// WHEN
new eks.Cluster(stack, 'Cluster1', {
version: eks.KubernetesVersion.V1_21,
prune: false,
});

// THEN
Annotations.fromStack(stack).hasNoWarning('/Stack/Cluster1', message('21'));
});

test('added when version >= 1.22 and no kubectl layer provided', () => {
// GIVEN
const { stack } = testFixture();

// WHEN
new eks.Cluster(stack, 'Cluster1', {
version: eks.KubernetesVersion.V1_23,
prune: false,
});

// THEN
Annotations.fromStack(stack).hasWarning('/Stack/Cluster1', message('23'));
});
});

test('custom awscli layer can be provided', () => {
// GIVEN
const { stack } = testFixture();
Expand Down
Binary file not shown.
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"files": {
"c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30": {
"dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d": {
"source": {
"path": "asset.c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"path": "asset.dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"objectKey": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down Expand Up @@ -105,15 +105,15 @@
}
}
},
"4c83be2cb27d35f5ebcdead395ca2da423e85d21119ceecee4aeb55986d1b0ae": {
"6827931205ccb42a1c15c1b863588327e792dd232f257d2ad1cf32854538f0e3": {
"source": {
"path": "aws-cdk-eks-cluster-bottlerocket-ng-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "4c83be2cb27d35f5ebcdead395ca2da423e85d21119ceecee4aeb55986d1b0ae.json",
"objectKey": "6827931205ccb42a1c15c1b863588327e792dd232f257d2ad1cf32854538f0e3.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Expand Up @@ -434,9 +434,9 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
"S3Key": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip"
},
"Description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"Description": "/opt/kubectl/kubectl 1.23; /opt/helm/helm 3.9",
"LicenseInfo": "Apache-2.0"
}
},
Expand Down Expand Up @@ -640,7 +640,7 @@
]
},
"Config": {
"version": "1.22",
"version": "1.23",
"roleArn": {
"Fn::GetAtt": [
"ClusterRoleFA261979",
Expand Down
Expand Up @@ -23,7 +23,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4c83be2cb27d35f5ebcdead395ca2da423e85d21119ceecee4aeb55986d1b0ae.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6827931205ccb42a1c15c1b863588327e792dd232f257d2ad1cf32854538f0e3.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Expand Up @@ -741,9 +741,9 @@
"s3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"s3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
"s3Key": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip"
},
"description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"description": "/opt/kubectl/kubectl 1.23; /opt/helm/helm 3.9",
"licenseInfo": "Apache-2.0"
}
},
Expand All @@ -754,7 +754,7 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/lambda-layer-kubectl-v22.KubectlV22Layer",
"fqn": "@aws-cdk/lambda-layer-kubectl-v23.KubectlV23Layer",
"version": "2.0.0"
}
},
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"files": {
"c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30": {
"dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d": {
"source": {
"path": "asset.c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"path": "asset.dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"objectKey": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down Expand Up @@ -105,15 +105,15 @@
}
}
},
"d8b035beb3e2f00d909d6388deffc6d1a568e49f218d698a0ff456b1ad3410fa": {
"9911fd83c996d002742fa726a52e047d10938e112537f18be6ddf95b9c29acac": {
"source": {
"path": "aws-cdk-eks-handlers-in-vpc-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "d8b035beb3e2f00d909d6388deffc6d1a568e49f218d698a0ff456b1ad3410fa.json",
"objectKey": "9911fd83c996d002742fa726a52e047d10938e112537f18be6ddf95b9c29acac.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Expand Up @@ -7,9 +7,9 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
"S3Key": "dd8086b05eeea461708bd66ad140d8965ddf70c0e144af871d078fdbddf0a67d.zip"
},
"Description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"Description": "/opt/kubectl/kubectl 1.23; /opt/helm/helm 3.9",
"LicenseInfo": "Apache-2.0"
}
},
Expand Down Expand Up @@ -656,7 +656,7 @@
]
},
"Config": {
"version": "1.22",
"version": "1.23",
"roleArn": {
"Fn::GetAtt": [
"EksAllHandlersInVpcStackRoleC36F09F0",
Expand Down
Expand Up @@ -23,7 +23,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d8b035beb3e2f00d909d6388deffc6d1a568e49f218d698a0ff456b1ad3410fa.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9911fd83c996d002742fa726a52e047d10938e112537f18be6ddf95b9c29acac.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down

0 comments on commit 4e858f2

Please sign in to comment.