Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/cluster autoscaler #720

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/addons/apache-airflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions lib/addons/cluster-autoscaler/index.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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<KubernetesVersion, string> = new Map([
[KubernetesVersion.V1_26, "9.29.0"],
[KubernetesVersion.V1_25, "9.29.0"],
[KubernetesVersion.V1_24, "9.25.0"],
Expand All @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions test/cluster-autoscaler.test.ts
Original file line number Diff line number Diff line change
@@ -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",
},
});
});