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

adds instanceProfileName field to nodegroups #1496

Merged
merged 12 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions nodejs/eks/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ export function createCore(
name,
parent,
args.instanceRole,
args.instanceProfileName,
flostadler marked this conversation as resolved.
Show resolved Hide resolved
args.instanceProfileName ?? nodeGroupOptions.instanceProfileName,
);
}
instanceRoles = pulumi.output([args.instanceRole]);
Expand Down Expand Up @@ -854,7 +854,7 @@ export function createCore(
name,
parent,
instanceRole,
args.instanceProfileName,
args.instanceProfileName ?? nodeGroupOptions.instanceProfileName,
);
} else {
instanceRoles = pulumi.output([]);
Expand Down
198 changes: 196 additions & 2 deletions nodejs/eks/nodegroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

import { isGravitonInstance } from "./nodegroup";
import { isGravitonInstance, resolveInstanceProfileName } from "./nodegroup";
import { getArchitecture } from "./nodegroup";
import { CoreData } from "./cluster";
import { Cluster as ClusterComponent, CoreData } from "./cluster";

const gravitonInstances = [
"c6g.12xlarge",
Expand Down Expand Up @@ -446,6 +446,200 @@ describe("createManagedNodeGroup", function () {
});
});

describe("resolveInstanceProfileName", function () {
beforeAll(() => {
pulumi.runtime.setMocks(
{
newResource: function (args: pulumi.runtime.MockResourceArgs): {
id: string;
state: any;
} {
if (args.type === "aws:iam/instanceProfile:InstanceProfile") {
return {
id: args.inputs.name + "_id",
state: {
name: args.id,
},
};
}
return {
id: args.inputs.name + "_id",
state: args.inputs,
};
},
call: function (args: pulumi.runtime.MockCallArgs) {
return args.inputs;
},
},
"project",
"stack",
false, // Sets the flag `dryRun`, which indicates if pulumi is running in preview mode.
);
});

let ng: typeof import("./nodegroup");
beforeEach(async function () {
ng = await import("./nodegroup");
});

test("no args, no c.nodeGroupOptions throws", async () => {
expect(promisify(resolveInstanceProfileName(
"nodegroup-name",
{},
pulumi.output({
nodeGroupOptions: {},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
),
)).toThrow("an instanceProfile or instanceProfileName is required");
});

test("both args.instanceProfile and args.instanceProfileName throws", async () => {
const instanceProfile = new aws.iam.InstanceProfile("instanceProfile", {});
const name = "nodegroup-name";
expect(() =>
resolveInstanceProfileName(
name,
{
instanceProfile: instanceProfile,
instanceProfileName: "instanceProfileName",
},
pulumi.output({
nodeGroupOptions: {},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
),
).toThrowError(
`invalid args for node group ${name}, instanceProfile and instanceProfileName are mutually exclusive`,
);
});

// test("both c.nodeGroupOptions.instanceProfileName and c.nodeGroupOptions.instanceProfile throws", async () => {
// const instanceProfile = new aws.iam.InstanceProfile("instanceProfile", {});
// const name = "nodegroup-name";
// // const errorOutput = resolveInstanceProfileName(
// // name,
// // {},
// // pulumi.output({
// // nodeGroupOptions: {
// // instanceProfile: instanceProfile,
// // instanceProfileName: "instanceProfileName",
// // },
// // } as pulumi.UnwrappedObject<CoreData>),
// // undefined as any,
// // // )
// // try {
// // await promisify(resolveInstanceProfileName(
// // name,
// // {},
// // pulumi.output({
// // nodeGroupOptions: {
// // instanceProfile: instanceProfile,
// // instanceProfileName: "instanceProfileName",
// // },
// // } as pulumi.UnwrappedObject<CoreData>),
// // undefined as any,
// // ))
// // } catch (error) {
// // // expect(error).toMatchObject(new pulumi.ResourceError(
// // // `invalid args for node group ${name}, instanceProfile and instanceProfileName are mutually exclusive`,
// // // undefined,
// // // ))
// // }

// // await expect(() => promisify(resolveInstanceProfileName(
// // name,
// // {},
// // pulumi.output({
// // nodeGroupOptions: {
// // instanceProfile: instanceProfile,
// // instanceProfileName: "instanceProfileName",
// // },
// // } as pulumi.UnwrappedObject<CoreData>),
// // undefined as any,
// // )
// // )).toThrowError(
// // `invalid nodeGroupOptions for node group ${name}, instanceProfile and instanceProfileName are mutually exclusive`, undefined
// // );
// });

test("args.instanceProfile returns passed instanceProfile", async () => {
const instanceProfile = new aws.iam.InstanceProfile("instanceProfile", {
name: "passedInstanceProfile",
});
const nodeGroupName = "nodegroup-name";
const resolvedInstanceProfileName = resolveInstanceProfileName(
nodeGroupName,
{
instanceProfile: instanceProfile,
},
pulumi.output({
nodeGroupOptions: {},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
);
const expected = await promisify(instanceProfile.name);
const recieved = await promisify(resolvedInstanceProfileName);
expect(recieved).toEqual(expected);
});

test("nodeGroupOptions.instanceProfile returns passed instanceProfile", async () => {
const instanceProfile = new aws.iam.InstanceProfile("instanceProfile", {
name: "passedInstanceProfile",
});
const nodeGroupName = "nodegroup-name";
const resolvedInstanceProfileName = resolveInstanceProfileName(
nodeGroupName,
{},
pulumi.output({
nodeGroupOptions: {
instanceProfile: instanceProfile,
},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
);
const expected = await promisify(instanceProfile.name);
const recieved = await promisify(resolvedInstanceProfileName);
expect(recieved).toEqual(expected);
});

test("args.instanceProfileName returns passed InstanceProfile", async () => {
const nodeGroupName = "nodegroup-name";
const existingInstanceProfileName = "existingInstanceProfileName";
const resolvedInstanceProfileName = resolveInstanceProfileName(
nodeGroupName,
{
instanceProfileName: existingInstanceProfileName,
},
pulumi.output({
nodeGroupOptions: {},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
);
const expected = existingInstanceProfileName;
const received = await promisify(resolvedInstanceProfileName);
expect(received).toEqual(expected);
});

test("nodeGroupOptions.instanceProfileName returns existing InstanceProfile", async () => {
const nodeGroupName = "nodegroup-name";
const existingInstanceProfileName = "existingInstanceProfileName";
const resolvedInstanceProfileName = resolveInstanceProfileName(
nodeGroupName,
{},
pulumi.output({
nodeGroupOptions: {
instanceProfileName: existingInstanceProfileName,
},
} as pulumi.UnwrappedObject<CoreData>),
undefined as any,
);
const expected = existingInstanceProfileName;
const received = await promisify(resolvedInstanceProfileName);
expect(received).toEqual(expected);
});
});

function promisify<T>(output: pulumi.Output<T> | undefined): Promise<T> {
expect(output).toBeDefined();
return new Promise((resolve) => output!.apply(resolve));
Expand Down
Loading
Loading