From 97281d21415c41f2080ab05c6d81ad46257fe5bd Mon Sep 17 00:00:00 2001 From: Madeline Kusters <80541297+madeline-k@users.noreply.github.com> Date: Thu, 27 Oct 2022 11:26:25 -0700 Subject: [PATCH] use semver --- package.json | 2 ++ packages/@aws-cdk/aws-eks/lib/cluster.ts | 7 ++++--- packages/@aws-cdk/aws-eks/package.json | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 87b1e4c572853..6b8b7b122534a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index 6e4c381e67ce1..e8afe190198d0 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -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'; @@ -1381,9 +1382,9 @@ export class Cluster extends ClusterBase { this.prune = props.prune ?? true; this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc'); - const kubectlVersion = Number(props.version.version) * 100; - if (kubectlVersion >= 122 && !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 % 100}.`); + 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; diff --git a/packages/@aws-cdk/aws-eks/package.json b/packages/@aws-cdk/aws-eks/package.json index 2e2d059c073ff..450c110fe9d81 100644 --- a/packages/@aws-cdk/aws-eks/package.json +++ b/packages/@aws-cdk/aws-eks/package.json @@ -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",