From 5e01cc2e4ca7946ea5e7f6eb5335ffcec6a07923 Mon Sep 17 00:00:00 2001 From: Xia Zhao <78883180+xazhao@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:38:21 -0800 Subject: [PATCH] chore(eks): add warning to make kubectlLayer property required in the future (#32483) ### Reason for this change `kubectlLayer` property in EKS Cluster is currently optional. If not provided, it will use a very outdated version (1.20). This default outdated version adds a outdated dependency to CDK which should be removed. However, we can't simply update the version because it will be a breaking change. To avoid this issue happening again, we can send a warning first then we can do a one-time breaking change to make the property required. Another reason is the synth error (users have to provide the property) is better than we upgrading the version silently which may lead to some unexpected behavior. ### Description of changes Update warning to let customers know this property will become required in 2025 Jan. ### Description of how you validated changes ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk-lib/aws-eks/lib/cluster.ts | 6 ++---- .../aws-cdk-lib/aws-eks/test/cluster.test.ts | 20 +++---------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/packages/aws-cdk-lib/aws-eks/lib/cluster.ts b/packages/aws-cdk-lib/aws-eks/lib/cluster.ts index 2c624a477c9b8..8f66f4efa8b3a 100644 --- a/packages/aws-cdk-lib/aws-eks/lib/cluster.ts +++ b/packages/aws-cdk-lib/aws-eks/lib/cluster.ts @@ -1,7 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; import { Construct, Node } from 'constructs'; -import * as semver from 'semver'; import * as YAML from 'yaml'; import { IAccessPolicy, IAccessEntry, AccessEntry, AccessPolicy, AccessScopeType } from './access-entry'; import { IAddon, Addon } from './addon'; @@ -1579,9 +1578,8 @@ export class Cluster extends ClusterBase { this.prune = props.prune ?? true; this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc'); - const kubectlVersion = new semver.SemVer(`${props.version.version}.0`); - if (semver.gte(kubectlVersion, '1.22.0') && !props.kubectlLayer) { - Annotations.of(this).addWarningV2('@aws-cdk/aws-eks:clusterKubectlLayerNotSpecified', `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}.`); + if (!props.kubectlLayer) { + Annotations.of(this).addWarningV2('@aws-cdk/aws-eks:clusterKubectlLayerNotSpecified', `You created a cluster with Kubernetes Version ${props.version.version} without specifying the kubectlLayer property. The property will become required instead of optional in 2025 Jan. Please update your CDK code to provide a kubectlLayer.`); }; this.version = props.version; diff --git a/packages/aws-cdk-lib/aws-eks/test/cluster.test.ts b/packages/aws-cdk-lib/aws-eks/test/cluster.test.ts index 254987e61065e..b539eb46d0a34 100644 --- a/packages/aws-cdk-lib/aws-eks/test/cluster.test.ts +++ b/packages/aws-cdk-lib/aws-eks/test/cluster.test.ts @@ -3140,26 +3140,12 @@ describe('cluster', () => { function message(version: string) { return [ `You created a cluster with Kubernetes Version 1.${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${version}. [ack: @aws-cdk/aws-eks:clusterKubectlLayerNotSpecified]`, + 'The property will become required instead of optional in 2025 Jan. Please update your CDK code to provide a kubectlLayer.', + '[ack: @aws-cdk/aws-eks:clusterKubectlLayerNotSpecified]', ].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', () => { + test('no kubectl layer provided', () => { // GIVEN const { stack } = testFixture();