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

Fixed defect when AWS region was not set for core addon version look-up #1045

Merged
merged 4 commits into from
Jul 16, 2024
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
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
Loading