-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
91 lines (78 loc) · 2.2 KB
/
app.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
const awsPluginLibrary = require("@kaholo/aws-plugin-library");
const {
EKSClient,
CreateClusterCommand,
DescribeClusterCommand,
waitUntilClusterActive,
} = require("@aws-sdk/client-eks");
const autocomplete = require("./autocomplete");
const { fetchToken } = require("./helpers");
const { prepareCreateClusterPayload } = require("./payload-functions");
const { CREDENTIAL_KEYS } = require("./consts");
const kubectl = require("./kubectl");
const helmCli = require("./helm-cli");
async function createCluster(client, params, region) {
const awsCreateCluster = awsPluginLibrary.generateAwsMethod(
CreateClusterCommand,
prepareCreateClusterPayload,
);
const { cluster } = await awsCreateCluster(client, params, region);
if (!params.waitForActiveStatus) {
return cluster;
}
const clusterName = cluster.name;
await waitUntilClusterActive({ client }, {
name: clusterName,
});
return client.send(
new DescribeClusterCommand({ name: clusterName }),
);
}
async function runKubectlCommand(client, parameters) {
const {
clusterName,
command: commandArgs,
workingDirectory,
} = parameters;
const { cluster } = await client.send(
new DescribeClusterCommand({ name: clusterName }),
);
const token = await fetchToken(parameters);
const kubeCtlConfig = {
kubeToken: token,
kubeApiServer: cluster.endpoint,
kubeCertificate: cluster.certificateAuthority.data,
command: commandArgs.join(" "),
workingDirectory,
};
return kubectl.runCommand(kubeCtlConfig);
}
async function runHelmCommand(client, parameters) {
const {
clusterName,
command: commandArgs,
workingDirectory,
} = parameters;
const { cluster } = await client.send(
new DescribeClusterCommand({ name: clusterName }),
);
const token = await fetchToken(parameters);
const helmConfig = {
kubeToken: token,
kubeApiServer: cluster.endpoint,
kubeCertificate: cluster.certificateAuthority.data,
command: commandArgs.join(" "),
workingDirectory,
};
return helmCli.runCommand(helmConfig);
}
module.exports = awsPluginLibrary.bootstrap(
EKSClient,
{
createCluster,
runKubectlCommand,
runHelmCommand,
},
autocomplete,
CREDENTIAL_KEYS,
);