Skip to content

Commit

Permalink
Fixed defect when AWS region was not set for core addon version look-…
Browse files Browse the repository at this point in the history
…up (#1045)

* Fixed defect when AWS region was not set for core addon version look-up despite an explicit setting on the blueprint. Resolves #1015

* Refactored version look up API and fixed tests. Upgraded default version as per current state of AWS describe-addon-versions API

* removed log file that was used for debug

* lint issues addressed
  • Loading branch information
shapirov103 authored Jul 16, 2024
1 parent ccb5a03 commit b8c51d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions examples/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ builder()
.clusterProvider(new bp.MngClusterProvider({
...publicCluster
}))
.addOns(new bp.addons.VpcCniAddOn())
.enableControlPlaneLogTypes(bp.ControlPlaneLogType.API, bp.ControlPlaneLogType.AUDIT)
.build(app, "mng-blueprint");

Expand Down
10 changes: 5 additions & 5 deletions lib/addons/cloud-watch-insights/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {KubernetesVersion} from "aws-cdk-lib/aws-eks";
// aws eks describe-addon-versions --kubernetes-version <kubernetes-version> --addon-name amazon-cloudwatch-observability \
// --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table
const versionMap: Map<KubernetesVersion, string> = new Map([
[KubernetesVersion.V1_30, "v1.7.0-eksbuild.1"],
[KubernetesVersion.V1_29, "v1.7.0-eksbuild.1"],
[KubernetesVersion.V1_28, "v1.7.0-eksbuild.1"],
[KubernetesVersion.V1_27, "v1.7.0-eksbuild.1"],
[KubernetesVersion.V1_26, "v1.7.0-eksbuild.1"],
[KubernetesVersion.V1_30, "v1.8.0-eksbuild.1"],
[KubernetesVersion.V1_29, "v1.8.0-eksbuild.1"],
[KubernetesVersion.V1_28, "v1.8.0-eksbuild.1"],
[KubernetesVersion.V1_27, "v1.8.0-eksbuild.1"],
[KubernetesVersion.V1_26, "v1.8.0-eksbuild.1"],
]);


Expand Down
19 changes: 12 additions & 7 deletions lib/addons/core-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CoreAddOn implements ClusterAddOn {
let version: string = this.coreAddOnProps.version;

if (this.coreAddOnProps.version === "auto") {
version = await this.provideVersion(clusterInfo, this.coreAddOnProps.versionMap);
version = await this.provideVersion(clusterInfo);
}

let addOnProps = {
Expand Down Expand Up @@ -176,8 +176,8 @@ export class CoreAddOn implements ClusterAddOn {
return result;
}

async provideVersion(clusterInfo: ClusterInfo, versionMap?: Map<KubernetesVersion, string>) : Promise<string> {
const client = new sdk.EKSClient(clusterInfo.cluster.stack.region);
async provideVersion(clusterInfo: ClusterInfo) : Promise<string> {
const client = new sdk.EKSClient({ region: clusterInfo.cluster.stack.region });
const command = new sdk.DescribeAddonVersionsCommand({
addonName: this.coreAddOnProps.addOnName,
kubernetesVersion: clusterInfo.version.version
Expand Down Expand Up @@ -210,12 +210,17 @@ export class CoreAddOn implements ClusterAddOn {
logger.warn(`Failed to retrieve add-on versions from EKS for add-on ${this.coreAddOnProps.addOnName}.`);
logger.warn("Possible reasons for failures - Unauthorized or Authentication failure or Network failure on the terminal.");
logger.warn(" Falling back to default version.");
if (!versionMap) {
throw new Error(`No version map provided and no default version found for add-on ${this.coreAddOnProps.addOnName}`);
}
let version: string = versionMap.get(clusterInfo.version) ?? versionMap.values().next().value;
let version: string = this.provideDefaultAutoVersion(clusterInfo.version);
userLog.debug(`Core add-on ${this.coreAddOnProps.addOnName} has autoselected version ${version}`);
return version;
}
}

provideDefaultAutoVersion(version: KubernetesVersion) : string {
const versionMap = this.coreAddOnProps.versionMap;
if (versionMap) {
return versionMap.get(version) ?? versionMap.values().next().value;
}
throw new Error(`No default version found for add-on ${this.coreAddOnProps.addOnName}`);
}
}
12 changes: 7 additions & 5 deletions test/cloudwatch-insights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@ describe('Unit test for CloudWatch Addon', () => {
});
});

test("Stack is defined when using a specified version of EKS", async () => {
test("Stack is defined when using a specified version of EKS and \"auto\" version", async () => {
const app = new cdk.App();


const addOn = new blueprints.CloudWatchInsights();
const version = KubernetesVersion.V1_29;
const blueprint = await blueprints.EksBlueprint.builder()
.version(KubernetesVersion.V1_29)
.version(version)
.account("123456789012").region('us-east-2')
.addOns(new blueprints.CloudWatchInsights())
.addOns(addOn)
.buildAsync(app, 'cloudwatch-insights-specific-eks-version');

const template = Template.fromStack(blueprint);

template.hasResource("AWS::EKS::Addon", {
Properties: {
"AddonVersion": Match.exact("v1.7.0-eksbuild.1")
"AddonVersion": Match.exact(addOn.provideDefaultAutoVersion(version))
}
});
});
Expand Down

0 comments on commit b8c51d2

Please sign in to comment.