-
Notifications
You must be signed in to change notification settings - Fork 0
/
envsModel.js
40 lines (31 loc) · 916 Bytes
/
envsModel.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
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const crypto = require("crypto");
const domain = process.env.DOMAIN;
const createEnv = async() => {
const id = 'e' + crypto.randomBytes(8).toString("hex");
await exec(`helm install ${ domain ? `--set ingress.domain=${domain}` : '' } ${id} ./resources/zk-testnet/.`);
return {
id
};
}
const getEnv = async(id) => {
const { stdout } = await exec(`kubectl get configmap ${id}-zk-configmap -o jsonpath="{.data}"`);
return {
id,
metadata: JSON.parse(stdout),
}
};
const deleteEnv = async(id) => {
await exec(`helm uninstall ${id}`);
}
const existsEnv = async(id) => {
const { stdout } = await exec(`helm list -f ${id} -o json`);
return JSON.parse(stdout).length > 0;
}
module.exports = {
createEnv,
getEnv,
deleteEnv,
existsEnv,
}