From 394acc9d3f7f1e36bac51eaf0c5fbf958a4006cf Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Mon, 22 May 2023 09:20:41 -0400 Subject: [PATCH 01/15] CW Container Insight Receivers and Exporters --- lib/addons/container-insights/index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/addons/container-insights/index.ts b/lib/addons/container-insights/index.ts index 4b78a1810..9805df1e4 100644 --- a/lib/addons/container-insights/index.ts +++ b/lib/addons/container-insights/index.ts @@ -14,15 +14,11 @@ const defaultProps = { name: "adot-exporter-for-eks-on-ec2", namespace: undefined, // the chart will choke if this value is set chart: "adot-exporter-for-eks-on-ec2", - version: "0.1.0", + version: "0.10.0", release: "adot-eks-addon", repository: "https://aws-observability.github.io/aws-otel-helm-charts" }; - -/** - * @deprecated Use CloudWatchAdotAddOn. - */ export class ContainerInsightsAddOn extends HelmAddOn { constructor(props?: ContainerInsightAddonProps) { @@ -47,6 +43,19 @@ export class ContainerInsightsAddOn extends HelmAddOn { clusterName: cluster.clusterName, fluentbit: { enabled: true + }, + adotCollector:{ + daemonSet: { + service: { + metrics: { + receivers: ["awscontainerinsightreceiver"], + exporters: ["awsemf"], + } + }, + cwexporters: { + logStreamName: "EKSNode", + } + } } }; From 0dd58344da8403ca0b8c218d240e95d0a7329f63 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Mon, 22 May 2023 13:25:08 -0400 Subject: [PATCH 02/15] CW Container Insight Receivers and Exporters --- docs/addons/container-insights.md | 10 +++++---- examples/blueprint-construct/index.ts | 31 +++++++++++++------------- lib/addons/container-insights/index.ts | 29 +++++++++++++++++++++++- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/docs/addons/container-insights.md b/docs/addons/container-insights.md index dc23f3158..08974d0c2 100644 --- a/docs/addons/container-insights.md +++ b/docs/addons/container-insights.md @@ -10,6 +10,8 @@ CloudWatch does not automatically create all possible metrics from the log data, Metrics collected by Container Insights are charged as custom metrics. For more information about [CloudWatch pricing](https://aws.amazon.com/cloudwatch/pricing/), see Amazon CloudWatch Pricing. +Also it is important to note that this add-on can not co-exist with `adot-addon` on same EKS cluster. `adot-addon` and this add-on is mutually exclusive due to `adot-collector-sa` service account. + ## Usage Add the following as an add-on to your main.ts file to add Containers Insights to your cluster @@ -34,7 +36,7 @@ Once the Container Insights add-on has been installed in your cluster, validate ```bash kubectl get all -n amazon-cloudwatch -kubectl get all -n amzn-cloudwatch-metrics +kubectl get all -n amazon-metrics ``` You should see output similar to the following respectively (assuming two node cluster): @@ -48,11 +50,11 @@ NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE daemonset.apps/fluent-bit 2 2 2 2 2 100s NAME READY STATUS RESTARTS AGE -pod/adot-collector-daemonset-b2rpc 1/1 Running 0 106s -pod/adot-collector-daemonset-k6tfw 1/1 Running 2 106s +pod/adot-collector-daemonset-k7n4p 1/1 Running 0 2m4s +pod/adot-collector-daemonset-qjdps 1/1 Running 0 114s NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE -daemonset.apps/adot-collector-daemonset 2 2 2 2 2 106s +daemonset.apps/adot-collector-daemonset 2 2 2 2 2 73m ``` To enable or disable control plane logs with the console, run the following command in your terminal. diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index 1946f21dc..5324349d9 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -51,12 +51,13 @@ export default class BlueprintConstruct { new blueprints.addons.CertManagerAddOn(), new blueprints.addons.KubeStateMetricsAddOn(), new blueprints.addons.PrometheusNodeExporterAddOn(), - new blueprints.addons.AdotCollectorAddOn(), - new blueprints.addons.AmpAddOn({ - ampPrometheusEndpoint: ampPrometheusEndpoint, - }), - new blueprints.addons.XrayAdotAddOn(), + // new blueprints.addons.AdotCollectorAddOn(), + // new blueprints.addons.AmpAddOn({ + // ampPrometheusEndpoint: ampPrometheusEndpoint, + // }), + // new blueprints.addons.XrayAdotAddOn(), // new blueprints.addons.CloudWatchAdotAddOn(), + new blueprints.addons.ContainerInsightsAddOn(), new blueprints.addons.IstioBaseAddOn(), new blueprints.addons.IstioControlPlaneAddOn(), new blueprints.addons.CalicoOperatorAddOn(), @@ -141,16 +142,16 @@ export default class BlueprintConstruct { irsaRoles: ["CloudWatchFullAccess", "AmazonSQSFullAccess"] }), new blueprints.addons.AWSPrivateCAIssuerAddon(), - new blueprints.addons.JupyterHubAddOn({ - efsConfig: { - pvcName: "efs-persist", - removalPolicy: cdk.RemovalPolicy.DESTROY, - capacity: '10Gi', - }, - serviceType: blueprints.JupyterHubServiceType.CLUSTERIP, - notebookStack: 'jupyter/datascience-notebook', - values: { prePuller: { hook: { enabled: false }}} - }), + // new blueprints.addons.JupyterHubAddOn({ + // efsConfig: { + // pvcName: "efs-persist", + // removalPolicy: cdk.RemovalPolicy.DESTROY, + // capacity: '10Gi', + // }, + // serviceType: blueprints.JupyterHubServiceType.CLUSTERIP, + // notebookStack: 'jupyter/datascience-notebook', + // values: { prePuller: { hook: { enabled: false }}} + // }), new blueprints.EmrEksAddOn(), new blueprints.AwsBatchAddOn(), new blueprints.AwsForFluentBitAddOn(), diff --git a/lib/addons/container-insights/index.ts b/lib/addons/container-insights/index.ts index 9805df1e4..2ab6abd39 100644 --- a/lib/addons/container-insights/index.ts +++ b/lib/addons/container-insights/index.ts @@ -5,6 +5,8 @@ import { assertEC2NodeGroup } from "../.."; import { ClusterInfo } from "../../spi"; import { HelmAddOn, HelmAddOnUserProps } from "../helm-addon"; import { ValuesSchema } from "./values"; +import { createNamespace } from "../../utils"; +import { KubernetesManifest } from "aws-cdk-lib/aws-eks"; export interface ContainerInsightAddonProps extends Omit { values?: ValuesSchema @@ -31,13 +33,33 @@ export class ContainerInsightsAddOn extends HelmAddOn { deploy(clusterInfo: ClusterInfo): Promise { const cluster = clusterInfo.cluster; const nodeGroups = assertEC2NodeGroup(clusterInfo, ContainerInsightsAddOn.name); - const policy = ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy'); nodeGroups.forEach(nodeGroup => { nodeGroup.role.addManagedPolicy(policy); }); + // Create an adot-collector service account. + const serviceAccountName = "adot-collector-sa"; + let serviceAccountNamespace; + + if (this.props.namespace) { + serviceAccountNamespace = this.props.namespace; + } + else { + serviceAccountNamespace = "amazon-metrics" + } + + const ns = createNamespace(serviceAccountNamespace, cluster, true); + const sa = cluster.addServiceAccount(serviceAccountName, { + name: serviceAccountName, + namespace: serviceAccountNamespace, + }); + + // Apply Managed IAM policy to the service account. + sa.role.addManagedPolicy(policy) + sa.node.addDependency(ns); + let values: ValuesSchema = { awsRegion: cluster.stack.region, clusterName: cluster.clusterName, @@ -52,6 +74,11 @@ export class ContainerInsightsAddOn extends HelmAddOn { exporters: ["awsemf"], } }, + serviceAccount: { + annotations: { + "eks.amazonaws.com/role-arn": sa.role.roleArn + } + }, cwexporters: { logStreamName: "EKSNode", } From efa6ca3d9cb3d69de0e1b06be58aeff063c60fc5 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Tue, 23 May 2023 08:56:29 -0400 Subject: [PATCH 03/15] Fixing PR Issues --- examples/blueprint-construct/index.ts | 2 +- lib/addons/container-insights/index.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index 5324349d9..138001410 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -57,7 +57,7 @@ export default class BlueprintConstruct { // }), // new blueprints.addons.XrayAdotAddOn(), // new blueprints.addons.CloudWatchAdotAddOn(), - new blueprints.addons.ContainerInsightsAddOn(), + // new blueprints.addons.ContainerInsightsAddOn(), new blueprints.addons.IstioBaseAddOn(), new blueprints.addons.IstioControlPlaneAddOn(), new blueprints.addons.CalicoOperatorAddOn(), diff --git a/lib/addons/container-insights/index.ts b/lib/addons/container-insights/index.ts index 2ab6abd39..32283a9c5 100644 --- a/lib/addons/container-insights/index.ts +++ b/lib/addons/container-insights/index.ts @@ -66,8 +66,12 @@ export class ContainerInsightsAddOn extends HelmAddOn { fluentbit: { enabled: true }, - adotCollector:{ + serviceAccount: { + create: false, + }, + adotCollector: { daemonSet: { + createNamespace: false, service: { metrics: { receivers: ["awscontainerinsightreceiver"], @@ -75,9 +79,7 @@ export class ContainerInsightsAddOn extends HelmAddOn { } }, serviceAccount: { - annotations: { - "eks.amazonaws.com/role-arn": sa.role.roleArn - } + create: false, }, cwexporters: { logStreamName: "EKSNode", @@ -89,6 +91,7 @@ export class ContainerInsightsAddOn extends HelmAddOn { values = merge(values, this.props.values ?? {}); const chart = this.addHelmChart(clusterInfo, values, true, false); + chart.node.addDependency(sa); return Promise.resolve(chart); } } \ No newline at end of file From aceeb2135b474490e0e99c9e5f62f60e7df6ddc9 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Fri, 26 May 2023 22:57:59 -0400 Subject: [PATCH 04/15] Container Insights Module --- examples/blueprint-construct/index.ts | 4 ++-- lib/addons/container-insights/index.ts | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index 138001410..06dd892e5 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -57,7 +57,7 @@ export default class BlueprintConstruct { // }), // new blueprints.addons.XrayAdotAddOn(), // new blueprints.addons.CloudWatchAdotAddOn(), - // new blueprints.addons.ContainerInsightsAddOn(), + new blueprints.addons.ContainerInsightsAddOn(), new blueprints.addons.IstioBaseAddOn(), new blueprints.addons.IstioControlPlaneAddOn(), new blueprints.addons.CalicoOperatorAddOn(), @@ -207,7 +207,7 @@ export default class BlueprintConstruct { "LaunchTemplate": "Custom", "Instance": "ONDEMAND" }, - requireImdsv2: true + requireImdsv2: false } }, { diff --git a/lib/addons/container-insights/index.ts b/lib/addons/container-insights/index.ts index 32283a9c5..089c66fd2 100644 --- a/lib/addons/container-insights/index.ts +++ b/lib/addons/container-insights/index.ts @@ -5,8 +5,7 @@ import { assertEC2NodeGroup } from "../.."; import { ClusterInfo } from "../../spi"; import { HelmAddOn, HelmAddOnUserProps } from "../helm-addon"; import { ValuesSchema } from "./values"; -import { createNamespace } from "../../utils"; -import { KubernetesManifest } from "aws-cdk-lib/aws-eks"; +import { conflictsWith, createNamespace } from "../../utils"; export interface ContainerInsightAddonProps extends Omit { values?: ValuesSchema @@ -16,7 +15,7 @@ const defaultProps = { name: "adot-exporter-for-eks-on-ec2", namespace: undefined, // the chart will choke if this value is set chart: "adot-exporter-for-eks-on-ec2", - version: "0.10.0", + version: "0.15.0", release: "adot-eks-addon", repository: "https://aws-observability.github.io/aws-otel-helm-charts" }; @@ -30,6 +29,7 @@ export class ContainerInsightsAddOn extends HelmAddOn { /** * @override */ + @conflictsWith("AdotCollectorAddOn") deploy(clusterInfo: ClusterInfo): Promise { const cluster = clusterInfo.cluster; const nodeGroups = assertEC2NodeGroup(clusterInfo, ContainerInsightsAddOn.name); @@ -63,9 +63,6 @@ export class ContainerInsightsAddOn extends HelmAddOn { let values: ValuesSchema = { awsRegion: cluster.stack.region, clusterName: cluster.clusterName, - fluentbit: { - enabled: true - }, serviceAccount: { create: false, }, From b27ae45f92f84410aaf5f8eb5a646a4b2258ccc5 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Fri, 26 May 2023 23:21:16 -0400 Subject: [PATCH 05/15] CW PR --- examples/blueprint-construct/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index 99072b448..1e203aff4 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -59,13 +59,13 @@ export default class BlueprintConstruct { new blueprints.addons.CertManagerAddOn(), new blueprints.addons.KubeStateMetricsAddOn(), new blueprints.addons.PrometheusNodeExporterAddOn(), - // new blueprints.addons.AdotCollectorAddOn(), - // new blueprints.addons.AmpAddOn({ - // ampPrometheusEndpoint: ampPrometheusEndpoint, - // }), - // new blueprints.addons.XrayAdotAddOn(), + new blueprints.addons.AdotCollectorAddOn(), + new blueprints.addons.AmpAddOn({ + ampPrometheusEndpoint: ampWorkspace.attrPrometheusEndpoint, + }), + new blueprints.addons.XrayAdotAddOn(), // new blueprints.addons.CloudWatchAdotAddOn(), - new blueprints.addons.ContainerInsightsAddOn(), + // new blueprints.addons.ContainerInsightsAddOn(), new blueprints.addons.IstioBaseAddOn(), new blueprints.addons.IstioControlPlaneAddOn(), new blueprints.addons.CalicoOperatorAddOn(), From de415bcdf22d86b9e62c1f49bc0f46afbc207207 Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Tue, 6 Jun 2023 14:06:56 -0700 Subject: [PATCH 06/15] add clarity for creating own VPC resource provider --- docs/resource-providers/index.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/resource-providers/index.md b/docs/resource-providers/index.md index 65f2f5c6a..3666cb7ce 100644 --- a/docs/resource-providers/index.md +++ b/docs/resource-providers/index.md @@ -40,7 +40,22 @@ Example implementations: class VpcResourceProvider implements ResourceProvider { provide(context: ResourceContext): IVpc { const scope = context.scope; // stack - ... + return new Vpc(scope, '', { + availabilityZones: ['us-east-1a', 'us-east-1b', 'us-east-1c'], // VPC spans all AZs + subnetConfiguration: [{ + cidrMask: 24, + name: 'private', + subnetType: SubnetType.PRIVATE_WITH_EGRESS + }, { + cidrMask: 24, + name: 'public', + subnetType: SubnetType.PUBLIC + }], + natGatewaySubnets: { + availabilityZones: ['us-east-1b'] // NAT gateway only in 1 AZ + subnetType: SubnetType.PUBLIC + } + }); } } @@ -124,6 +139,7 @@ export class ClusterInfo { **Registering Resource Providers for a Blueprint** Note: `GlobalResources.HostedZone` and `GlobalResources.Certificate` are provided for convenience as commonly referenced constants. +Full list of Resource Providers can be found [here](https://aws-quickstart.github.io/cdk-eks-blueprints/api/modules/resources.html). ```typescript const myVpcId = ...; // e.g. app.node.tryGetContext('my-vpc', 'default) will look up property my-vpc in the cdk.json @@ -229,7 +245,7 @@ blueprints.EksBlueprint.builder() ## Implementing Custom Resource Providers 1. Select the type of the resource that you need. Let's say it will be an FSx File System. Note: it must be one of the derivatives/implementations of `IResource` interface. -2. Implement ResourceProvider interface: +2. Implement [`ResourceProvider`](https://aws-quickstart.github.io/cdk-eks-blueprints/api/interfaces/ResourceProvider.html) interface: ```typescript class MyResourceProvider implements blueprints.ResourceProvider { From 6be9feab81e4b6d064265d9584fd18d13861903c Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Wed, 7 Jun 2023 15:03:41 -0700 Subject: [PATCH 07/15] fix autoscaler example --- docs/addons/cluster-autoscaler.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/addons/cluster-autoscaler.md b/docs/addons/cluster-autoscaler.md index e890cfd64..d049e050f 100644 --- a/docs/addons/cluster-autoscaler.md +++ b/docs/addons/cluster-autoscaler.md @@ -14,7 +14,7 @@ import * as blueprints from '@aws-quickstart/eks-blueprints'; const app = new cdk.App(); -const addOn = new blueprints.addons.ClusterAutoscalerAddOn(); +const addOn = new blueprints.addons.ClusterAutoScalerAddOn(); const blueprint = blueprints.EksBlueprint.builder() .addOns(addOn) From 080e2702b43a2b23b58c3583b859d825f304ab0b Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Thu, 8 Jun 2023 08:45:12 -0700 Subject: [PATCH 08/15] create new resourceprovider example --- docs/resource-providers/index.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/resource-providers/index.md b/docs/resource-providers/index.md index 3666cb7ce..2b1211b0e 100644 --- a/docs/resource-providers/index.md +++ b/docs/resource-providers/index.md @@ -40,7 +40,23 @@ Example implementations: class VpcResourceProvider implements ResourceProvider { provide(context: ResourceContext): IVpc { const scope = context.scope; // stack - return new Vpc(scope, '', { + ... + } +} + +class DynamoDbTableResourceProvider implements ResourceProvider { + provide(context: ResourceContext): ITable { + ... + } +} + +/** + * Example implementation of a VPC Provider that creates a NAT Gateway + * which is available in all 3 AZs of the VPC while only being in one + */ +class OtherVpcResourceProvider implements ResourceProvider { + provide(context: ResourceContext): IVpc { + return new Vpc(context.scope, '', { availabilityZones: ['us-east-1a', 'us-east-1b', 'us-east-1c'], // VPC spans all AZs subnetConfiguration: [{ cidrMask: 24, @@ -59,12 +75,6 @@ class VpcResourceProvider implements ResourceProvider { } } -class DynamoDbTableResourceProvider implements ResourceProvider { - provide(context: ResourceContext): ITable { - ... - } -} - ``` Access to registered resources from other resource providers and/or add-ons and teams: From 1b736c036e1636eb16c3e2e6dd1b240319416c6f Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Thu, 8 Jun 2023 11:52:09 -0700 Subject: [PATCH 09/15] fix naming in grafana docs --- docs/addons/grafana-operator.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/addons/grafana-operator.md b/docs/addons/grafana-operator.md index a97954a2b..62398a306 100644 --- a/docs/addons/grafana-operator.md +++ b/docs/addons/grafana-operator.md @@ -35,11 +35,11 @@ There should be list the grafana-operator namespace ```bash grafana-operator Active 31m ``` -Verify if the pods are running correctly in flux-system namespace +Verify if everything is running correctly in the grafana-operator namespace ```bash -kubectl get pods -n grafana-operator +kubectl get all -n grafana-operator ``` -There should list 3 pods starting with name flux-system +This should list 1 pod, 1 service, 1 deployment, and 1 replica-set starting with name grafana-operator For Eg: ```bash NAME READY STATUS RESTARTS AGE From 285ccb06684b2dda7a586475365923bc1d38f7e9 Mon Sep 17 00:00:00 2001 From: shapirov Date: Fri, 26 May 2023 23:04:55 -0400 Subject: [PATCH 10/15] 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 11/15] 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 From 9290611ff717e3fc51acd57664a7bd6f6003243f Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Fri, 9 Jun 2023 13:41:13 -0700 Subject: [PATCH 12/15] add instructions to bootstrap specific region - #629 --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 30b0a9805..2d4a10d2d 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -77,7 +77,7 @@ For application of the EKS Blueprints Framework with [AWS Organizations](https:/ [Bootstrap](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html) your environment with the following command. ```bash -cdk bootstrap +cdk bootstrap aws:/// ``` Note: if the account/region combination used in the code example above is different from the initial combination used with `cdk bootstrap`, you will need to perform `cdk bootstrap` again to avoid error. From 9fc79eb5ab508d4beb3b43668e1a599e1fe4b1b4 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Mon, 12 Jun 2023 10:09:04 -0400 Subject: [PATCH 13/15] Fixing Lint Issues --- lib/addons/apache-airflow/index.ts | 6 +++--- lib/addons/container-insights/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 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", diff --git a/lib/addons/container-insights/index.ts b/lib/addons/container-insights/index.ts index 089c66fd2..b47f1c486 100644 --- a/lib/addons/container-insights/index.ts +++ b/lib/addons/container-insights/index.ts @@ -47,7 +47,7 @@ export class ContainerInsightsAddOn extends HelmAddOn { serviceAccountNamespace = this.props.namespace; } else { - serviceAccountNamespace = "amazon-metrics" + serviceAccountNamespace = "amazon-metrics"; } const ns = createNamespace(serviceAccountNamespace, cluster, true); @@ -57,7 +57,7 @@ export class ContainerInsightsAddOn extends HelmAddOn { }); // Apply Managed IAM policy to the service account. - sa.role.addManagedPolicy(policy) + sa.role.addManagedPolicy(policy); sa.node.addDependency(ns); let values: ValuesSchema = { From bc3ab25cac785a22012a1a396664b794ff49aeb1 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Mon, 12 Jun 2023 10:10:32 -0400 Subject: [PATCH 14/15] Fixing Lint Issues --- 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 4be391af6..16dc428ca 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 - new KubernetesManifest(clusterInfo.cluster, 'apache-airflow-efs-sc', { + const efsResources = new KubernetesManifest(clusterInfo.cluster, 'apache-airflow-efs-sc', { cluster: clusterInfo.cluster, manifest: [{ apiVersion: "storage.k8s.io/v1", From a0f05abdcdc3c30e3bdb0787231472e7274f990b Mon Sep 17 00:00:00 2001 From: Zach Jacobson Date: Mon, 12 Jun 2023 11:36:13 -0700 Subject: [PATCH 15/15] change providers to resources, fix incorrenct paths, and fix parenthesis --- docs/addons/external-dns.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/addons/external-dns.md b/docs/addons/external-dns.md index 9b72e8561..ee8d6e850 100644 --- a/docs/addons/external-dns.md +++ b/docs/addons/external-dns.md @@ -16,12 +16,12 @@ const app = new cdk.App(); const hostedZoneName = ... const addOn = new blueprints.addons.ExternalDnsAddOn({ - hostedZoneProviders: [hostedZoneName]; // can be multiple + hostedZoneResources: [hostedZoneName]; // can be multiple }); const blueprint = blueprints.EksBlueprint.builder() .addOns(addOn) - .resourceProvider(hostedZoneName, new blueprints.addons.LookupHostedZoneProvider(hostedZoneName)) + .resourceProvider(hostedZoneName, new blueprints.LookupHostedZoneProvider(hostedZoneName)) .addOns(addOn) .build(app, 'my-stack-name'); ``` @@ -75,8 +75,8 @@ blueprints.EksBlueprint.builder() // Register hosted zone1 under the name of MyHostedZone1 .resourceProvider("MyHostedZone1", new blueprints.LookupHostedZoneProvider(myDomainName)) .addOns(new blueprints.addons.ExternalDnsAddOn({ - hostedZoneProviders: ["MyHostedZone1"]; - }) + hostedZoneResources: ["MyHostedZone1"]; + })) .build(...); ``` @@ -86,10 +86,10 @@ If the hosted zone ID is known, then the recommended approach is to use a `Impor const myHostedZoneId = ""; blueprints.EksBlueprint.builder() // Register hosted zone1 under the name of MyHostedZone1 - .resourceProvider("MyHostedZone1", new blueprints.addons.ImportHostedZoneProvider(myHostedZoneId)) + .resourceProvider("MyHostedZone1", new blueprints.ImportHostedZoneProvider(myHostedZoneId)) .addOns(new blueprints.addons.ExternalDnsAddOn({ - hostedZoneProviders: ["MyHostedZone1"]; - }) + hostedZoneResources: ["MyHostedZone1"]; + })) .build(...); ``` @@ -128,10 +128,10 @@ blueprints.EksBlueprint.builder() parentAccountId: parentDnsAccountId, delegatingRoleName: 'DomainOperatorRole', wildcardSubdomain: true - }) + })) .addOns(new blueprints.addons.ExternalDnsAddOn({ - hostedZoneProviders: ["MyHostedZone1"]; - }) + hostedZoneResources: ["MyHostedZone1"]; + })) ```