Skip to content

Commit

Permalink
chore(eks): add warning to make kubectlLayer property required in the…
Browse files Browse the repository at this point in the history
… 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*
  • Loading branch information
xazhao authored Dec 17, 2024
1 parent 93ff387 commit 5e01cc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
6 changes: 2 additions & 4 deletions packages/aws-cdk-lib/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

Expand Down
20 changes: 3 additions & 17 deletions packages/aws-cdk-lib/aws-eks/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 5e01cc2

Please sign in to comment.