Skip to content

Commit

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

Notes:
- Updating integration tests are still in progress

Closes #20263 

----

### All Submissions:

* [x] 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

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] 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
madeline-k authored Oct 25, 2022
1 parent fc9e142 commit 91704aa
Show file tree
Hide file tree
Showing 83 changed files with 1,231 additions and 921 deletions.
20 changes: 16 additions & 4 deletions packages/@aws-cdk/aws-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,26 @@ The kubectl handler uses `kubectl`, `helm` and the `aws` CLI in order to
interact with the cluster. These are bundled into AWS Lambda layers included in
the `@aws-cdk/lambda-layer-awscli` and `@aws-cdk/lambda-layer-kubectl` modules.

You can specify a custom `lambda.LayerVersion` if you wish to use a different
version of these tools. The handler expects the layer to include the following
three executables:
The version of kubectl used must be compatible wtih the Kubernetes version of the cluster. kubectl is supported within one minor version (older or newer) of Kubernetes (see [Kubernetes version skew policy](https://kubernetes.io/releases/version-skew-policy/#kubectl)). Only version 1.20 of kubectl is available in `aws-cdk-lib`. If you need a different version, you will need to use one of the `@aws-cdk/lambda-layer-kubectlvXY` packages.

```ts
import { KubectlV22Layer } from '@aws-cdk/lambda-layer-kubectl-v22';

const cluster = new eks.Cluster(this, 'hello-eks', {
version: eks.KubernetesVersion.V1_22,
kubectlLayer: new KubectlV22Layer(this, 'kubectl'),
});

```

You can also specify a custom `lambda.LayerVersion` if you wish to use a
different version of these tools, or a version not available in any of the
`@aws-cdk/lambda-layer-kubectlvXY` packages. The handler expects the layer to
include the following two executables:

```text
helm/helm
kubectl/kubectl
awscli/aws
```

See more information in the
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,15 @@ export class KubernetesVersion {
*/
public static readonly V1_21 = KubernetesVersion.of('1.21');

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

/**
* Custom cluster version
* @param version custom version number
Expand Down Expand Up @@ -1362,6 +1371,10 @@ 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.`);
};
this.version = props.version;
this.kubectlLambdaRole = props.kubectlLambdaRole ? props.kubectlLambdaRole : undefined;

Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-eks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/lambda-layer-kubectl-v22": "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 Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{
"version": "21.0.0",
"files": {
"c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30": {
"source": {
"path": "asset.c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"4288ebb3652acdf2d828b7db7ca44a7162a401ace50ebb4026e84b18a02a06ee": {
"source": {
"path": "asset.4288ebb3652acdf2d828b7db7ca44a7162a401ace50ebb4026e84b18a02a06ee.zip",
Expand Down Expand Up @@ -66,19 +79,6 @@
}
}
},
"c6964dbf0c556ec82ce09622e99ad6f6d4e488cdaac0ef9e8492e078ec61ffed": {
"source": {
"path": "asset.c6964dbf0c556ec82ce09622e99ad6f6d4e488cdaac0ef9e8492e078ec61ffed.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c6964dbf0c556ec82ce09622e99ad6f6d4e488cdaac0ef9e8492e078ec61ffed.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"42973d1d89f4a393a64981f78d088964ba13e63a3aab4478cd74109c77cf9174": {
"source": {
"path": "asset.42973d1d89f4a393a64981f78d088964ba13e63a3aab4478cd74109c77cf9174",
Expand Down Expand Up @@ -131,28 +131,28 @@
}
}
},
"b426f1001506d25688ef81611f184e1ef5ebf1662e67bb4933b045477f10a56e": {
"a5c54a47681dc263bb296e341ff9500a68cc18f5d368dd66b41793f364332175": {
"source": {
"path": "awscdkeksclusteralbcontrollertestawscdkawseksKubectlProviderA1AC28D1.nested.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "b426f1001506d25688ef81611f184e1ef5ebf1662e67bb4933b045477f10a56e.json",
"objectKey": "a5c54a47681dc263bb296e341ff9500a68cc18f5d368dd66b41793f364332175.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"a7952c511d282bd028c89eada46178e2c8388a5649c0fc3d3364479c01bca79e": {
"4dddd3bf7eb63d312c638e331fc885e2dbb8d3398b739973a85d928c5178ec45": {
"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": "a7952c511d282bd028c89eada46178e2c8388a5649c0fc3d3364479c01bca79e.json",
"objectKey": "4dddd3bf7eb63d312c638e331fc885e2dbb8d3398b739973a85d928c5178ec45.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@
}
}
},
"KubectlLayer600207B5": {
"Type": "AWS::Lambda::LayerVersion",
"Properties": {
"Content": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c0f40a9fd16d1698ca05765606c04c8724dc5c8355b6e124a39af09449a3aa30.zip"
},
"Description": "/opt/kubectl/kubectl 1.22; /opt/helm/helm 3.9",
"LicenseInfo": "Apache-2.0"
}
},
"ClusterRoleFA261979": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -595,7 +608,7 @@
]
},
"Config": {
"version": "1.21",
"version": "1.22",
"roleArn": {
"Fn::GetAtt": [
"ClusterRoleFA261979",
Expand Down Expand Up @@ -1017,7 +1030,7 @@
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"/b426f1001506d25688ef81611f184e1ef5ebf1662e67bb4933b045477f10a56e.json"
"/a5c54a47681dc263bb296e341ff9500a68cc18f5d368dd66b41793f364332175.json"
]
]
},
Expand All @@ -1034,6 +1047,9 @@
"Arn"
]
},
"referencetoawscdkeksclusteralbcontrollertestKubectlLayerD13282C5Ref": {
"Ref": "KubectlLayer600207B5"
},
"referencetoawscdkeksclusteralbcontrollertestVpcPrivateSubnet1Subnet7C7DBEE5Ref": {
"Ref": "VpcPrivateSubnet1Subnet536B997A"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"Ref": "AwsCliLayerF44AAF94"
},
{
"Ref": "KubectlLayer600207B5"
"Ref": "referencetoawscdkeksclusteralbcontrollertestKubectlLayerD13282C5Ref"
}
],
"MemorySize": 1024,
Expand Down Expand Up @@ -146,18 +146,6 @@
"Description": "/opt/awscli/aws"
}
},
"KubectlLayer600207B5": {
"Type": "AWS::Lambda::LayerVersion",
"Properties": {
"Content": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "c6964dbf0c556ec82ce09622e99ad6f6d4e488cdaac0ef9e8492e078ec61ffed.zip"
},
"Description": "/opt/kubectl/kubectl and /opt/helm/helm"
}
},
"ProviderframeworkonEventServiceRole9FF04296": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -311,6 +299,9 @@
"referencetoawscdkeksclusteralbcontrollertestClusterCreationRoleA16C24E9Arn": {
"Type": "String"
},
"referencetoawscdkeksclusteralbcontrollertestKubectlLayerD13282C5Ref": {
"Type": "String"
},
"referencetoawscdkeksclusteralbcontrollertestVpcPrivateSubnet1Subnet7C7DBEE5Ref": {
"Type": "String"
},
Expand Down
Original file line number Diff line number Diff line change
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}/a7952c511d282bd028c89eada46178e2c8388a5649c0fc3d3364479c01bca79e.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4dddd3bf7eb63d312c638e331fc885e2dbb8d3398b739973a85d928c5178ec45.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -165,6 +165,12 @@
"data": "VpcVPCGWBF912B6E"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/KubectlLayer/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "KubectlLayer600207B5"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/Cluster/Role/Resource": [
{
"type": "aws:cdk:logicalId",
Expand Down Expand Up @@ -417,12 +423,6 @@
"data": "AwsCliLayerF44AAF94"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/@aws-cdk--aws-eks.KubectlProvider/KubectlLayer/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "KubectlLayer600207B5"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/@aws-cdk--aws-eks.KubectlProvider/Provider/framework-onEvent/ServiceRole/Resource": [
{
"type": "aws:cdk:logicalId",
Expand Down Expand Up @@ -459,6 +459,12 @@
"data": "referencetoawscdkeksclusteralbcontrollertestClusterCreationRoleA16C24E9Arn"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/@aws-cdk--aws-eks.KubectlProvider/reference-to-awscdkeksclusteralbcontrollertestKubectlLayerD13282C5Ref": [
{
"type": "aws:cdk:logicalId",
"data": "referencetoawscdkeksclusteralbcontrollertestKubectlLayerD13282C5Ref"
}
],
"/aws-cdk-eks-cluster-alb-controller-test/@aws-cdk--aws-eks.KubectlProvider/reference-to-awscdkeksclusteralbcontrollertestVpcPrivateSubnet1Subnet7C7DBEE5Ref": [
{
"type": "aws:cdk:logicalId",
Expand Down
Loading

0 comments on commit 91704aa

Please sign in to comment.