-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathaws.js
79 lines (70 loc) · 2.38 KB
/
aws.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const cmd = require("node-cmd");
const { reservedFromCores, hash } = require("./helpers");
const region = "us-east-1";
const cloudProvider = "aws";
const memType = "binary";
const maxPodScript = "./scripts/max-pods-calculator.sh";
const provisioningTimeScript = "./scripts/aws.launcher.sh";
module.exports = function getAWSInstances(input, pricingInput, includeTime) {
//get the input data which generate by aws cli aws ec2 describe-instance-types --instance-types > aws.json
const instances = [];
for (let i = 0; i < input.length; i++) {
const maxPodCount = parseInt(
cmd
.runSync(
`bash ${maxPodScript} --cni-version 1.9.0 --cni-prefix-delegation-enabled --instance-type ${input[i].InstanceType}`
)
.data?.trim(),
10
);
const provisioningTime = includeTime
? parseInt(
cmd
.runSync(`bash ${provisioningTimeScript} ${input[i].InstanceType}`)
.data?.trim(),
10
)
: undefined;
const totalMemory = input[i].MemoryInfo.SizeInMiB;
const totalCpuCores = input[i].VCpuInfo.DefaultVCpus;
// Source: https://cloudgeometry.io/blog/amazon-eks/#:~:text=EKS%20supports%20many%20EC2%20instance,and%20OS%20under%20some%20load.
if (totalMemory <= 2000) {
continue;
}
if (isNaN(maxPodCount)) {
console.log(
`I could not find the max pod count for the instance ${input[i].InstanceType}`
);
continue;
}
const costPerHour = parseFloat(
pricingInput
.find((it) => it["API Name"] === input[i].InstanceType)
?.["Linux On Demand cost"].replace("$", "")
.replace(" hourly", "")
);
instances.push({
id: hash(input[i].InstanceType),
name: input[i].InstanceType,
os: { memory: { value: 100, type: memType }, cpu: 100 },
kubelet: {
memory: computeKubeletMemory(maxPodCount),
cpu: reservedFromCores(totalCpuCores),
},
evictionThreshold: {
memory: { value: 100, type: memType },
cpu: 0,
},
totalMemory: { value: totalMemory, type: memType },
totalCpu: totalCpuCores * 1000,
costPerHour: isNaN(costPerHour) ? null : costPerHour,
maxPodCount,
provisioningTime,
cloudProvider,
});
}
return instances;
};
function computeKubeletMemory(maxPodCount) {
return { value: 255 + 11 * maxPodCount, type: "binary" };
}