-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathazure.js
93 lines (83 loc) · 2.4 KB
/
azure.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const { reservedKubeletMemory, si2binary, hash } = require("./helpers");
const cmd = require("node-cmd");
const region = "eastus";
const cloudProvider = "azure";
const memType = "binary";
const maxPodCount = 250;
const provisioningTimeScript = "./scripts/azure.launcher.sh";
// source: https://docs.microsoft.com/en-us/azure/aks/quotas-skus-regions#restricted-vm-sizes
const invalidSKUs = [
"Standard_A0",
"Standard_A1",
"Standard_A1_v2",
"Standard_B1ls",
"Standard_B1s",
"Standard_B1ms",
"Standard_F1",
"Standard_F1s",
"Standard_A2",
"Standard_D1",
"Standard_D1_v2",
"Standard_DS1",
"Standard_DS1_v2",
].map((it) => it.toLowerCase());
module.exports = function getAzureInstances(input, pricingInput, includeTime) {
//get the input data which generate by az vm list-sizes --location eastus > azure.json
const instances = [];
for (let i = 0; i < input.length; i++) {
const totalMemory = input[i].memoryInMb;
const totalCpuCores = input[i].numberOfCores;
const name = input[i].name;
if (invalidSKUs.includes(name.toLowerCase())) {
continue;
}
if (name.toLowerCase().endsWith("promo")) {
continue;
}
const costPerHour = pricingInput.find((it) => it["VM name"] === name)?.[
"Linux $"
];
const provisioningTime = includeTime
? parseInt(
cmd
.runSync(`bash ${provisioningTimeScript} ${input[i].name}`)
.data?.trim(),
10
)
: undefined;
instances.push({
id: hash(input[i].name),
name: input[i].name
.replace(/_/g, " ")
.replace(/Standard /, "")
.trim(),
os: { memory: { value: 100, type: memType }, cpu: 100 },
kubelet: {
memory: {
value: Math.round(
si2binary(
reservedKubeletMemory({ value: totalMemory, type: memType })
)
),
type: memType,
},
cpu: reservedFromCores(totalCpuCores),
},
evictionThreshold: {
memory: { value: 100, type: memType },
cpu: 0,
},
totalMemory: { value: totalMemory, type: memType },
totalCpu: totalCpuCores * 1000,
costPerHour,
maxPodCount,
provisioningTime,
cloudProvider,
});
}
return instances;
};
function reservedFromCores(cores) {
const map = { 1: 60, 2: 100, 4: 140, 8: 180, 16: 260, 32: 420, 64: 740 };
return cores in map ? map[cores] : 0;
}