From 285ccb06684b2dda7a586475365923bc1d38f7e9 Mon Sep 17 00:00:00 2001 From: shapirov Date: Fri, 26 May 2023 23:04:55 -0400 Subject: [PATCH 1/2] fixed lint warnings --- lib/addons/apache-airflow/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/addons/apache-airflow/index.ts b/lib/addons/apache-airflow/index.ts index 16dc428ca..4be391af6 100644 --- a/lib/addons/apache-airflow/index.ts +++ b/lib/addons/apache-airflow/index.ts @@ -62,8 +62,8 @@ export interface AirflowAddOnProps extends HelmAddOnUserProps { const AIRFLOW = 'airflow'; const RELEASE = 'blueprints-addon-apache-airflow'; -const AIRFLOWSC = 'apache-airflow-sc' -const AIRFLOWPVC = 'efs-apache-airflow-pvc' +const AIRFLOWSC = 'apache-airflow-sc'; +const AIRFLOWPVC = 'efs-apache-airflow-pvc'; /** * Default props to be used when creating the Helm chart @@ -182,7 +182,7 @@ function populateValues(clusterInfo: ClusterInfo, ns: KubernetesManifest, helmOp assert(efs, "Please provide the name of EFS File System."); // Need to create a storage class and pvc for the EFS - const efsResources = new KubernetesManifest(clusterInfo.cluster, 'apache-airflow-efs-sc', { + new KubernetesManifest(clusterInfo.cluster, 'apache-airflow-efs-sc', { cluster: clusterInfo.cluster, manifest: [{ apiVersion: "storage.k8s.io/v1", From 0861d5234b103d6e7e1fe0477f1e6b12b3552a80 Mon Sep 17 00:00:00 2001 From: shapirov Date: Fri, 9 Jun 2023 16:37:19 -0400 Subject: [PATCH 2/2] Fixing autoscaler to not fail on version mismatch and using the latest by default --- lib/addons/cluster-autoscaler/index.ts | 12 +++--- test/cluster-autoscaler.test.ts | 60 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 test/cluster-autoscaler.test.ts diff --git a/lib/addons/cluster-autoscaler/index.ts b/lib/addons/cluster-autoscaler/index.ts index f6eb8872f..22077f622 100644 --- a/lib/addons/cluster-autoscaler/index.ts +++ b/lib/addons/cluster-autoscaler/index.ts @@ -1,11 +1,10 @@ import { CfnJson, Tags } from "aws-cdk-lib"; import { KubernetesVersion } from "aws-cdk-lib/aws-eks"; import * as iam from "aws-cdk-lib/aws-iam"; -import { assert } from "console"; import { Construct } from "constructs"; import { assertEC2NodeGroup } from "../../cluster-providers"; import { ClusterInfo } from "../../spi"; -import { conflictsWith, createNamespace, createServiceAccount, setPath } from "../../utils"; +import { conflictsWith, createNamespace, createServiceAccount, logger, setPath } from "../../utils"; import { HelmAddOn, HelmAddOnUserProps } from "../helm-addon"; /** @@ -41,8 +40,7 @@ const defaultProps: ClusterAutoScalerAddOnProps = { /** * Version of the autoscaler, controls the image tag */ -const versionMap = new Map([ - [KubernetesVersion.of("1.26"), "9.29.0"], +const versionMap: Map = new Map([ [KubernetesVersion.V1_26, "9.29.0"], [KubernetesVersion.V1_25, "9.29.0"], [KubernetesVersion.V1_24, "9.25.0"], @@ -68,8 +66,10 @@ export class ClusterAutoScalerAddOn extends HelmAddOn { if(this.options.version?.trim() === 'auto') { this.options.version = versionMap.get(clusterInfo.version); - assert(this.options.version, "Unable to auto-detect cluster autoscaler version. Applying latest. Provided EKS cluster version: " - + clusterInfo.version?.version ?? clusterInfo.version); + if(!this.options.version) { + this.options.version = versionMap.values().next().value; + logger.warn(`Unable to auto-detect cluster autoscaler version. Applying latest: ${this.options.version}`); + } } const cluster = clusterInfo.cluster; diff --git a/test/cluster-autoscaler.test.ts b/test/cluster-autoscaler.test.ts new file mode 100644 index 000000000..5fb149445 --- /dev/null +++ b/test/cluster-autoscaler.test.ts @@ -0,0 +1,60 @@ +import * as cdk from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { KubernetesVersion } from 'aws-cdk-lib/aws-eks'; +import * as blueprints from '../lib'; + +test("Cluster autoscaler correctly is using correct defaults if EKS version is not defined in the version map", () => { + const app = new cdk.App(); + + const stack = blueprints.EksBlueprint.builder() + .account('123456789').region('us-west-2') + .version(KubernetesVersion.of("1.27")) + .addOns(new blueprints.ClusterAutoScalerAddOn()) + .build(app, "ca-stack-127"); + + const template = Template.fromStack(stack); + + template.hasResource("Custom::AWSCDK-EKS-HelmChart", { + Properties: { + Version: "9.29.0", + }, + }); +}); + + +test("Cluster autoscaler correctly is using correct version for 1.26", () => { + const app = new cdk.App(); + + const stack = blueprints.EksBlueprint.builder() + .account('123456789').region('us-west-2') + .version(KubernetesVersion.V1_26) + .addOns(new blueprints.ClusterAutoScalerAddOn()) + .build(app, "ca-stack-126"); + + const template = Template.fromStack(stack); + + template.hasResource("Custom::AWSCDK-EKS-HelmChart", { + Properties: { + Version: "9.29.0", + }, + }); +}); + + +test("Cluster autoscaler correctly is using correct version for 1.26 specified as string", () => { + const app = new cdk.App(); + + const stack = blueprints.EksBlueprint.builder() + .account('123456789').region('us-west-2') + .version(KubernetesVersion.of("1.26")) + .addOns(new blueprints.ClusterAutoScalerAddOn()) + .build(app, "ca-stack-127"); + + const template = Template.fromStack(stack); + + template.hasResource("Custom::AWSCDK-EKS-HelmChart", { + Properties: { + Version: "9.29.0", + }, + }); +}); \ No newline at end of file