-
Notifications
You must be signed in to change notification settings - Fork 7
/
kubernetes.ts
161 lines (157 loc) · 3.65 KB
/
kubernetes.ts
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { events } from "../helpers/events";
import { VMHL } from "../high_level//machine";
import { QSFSDiskModel } from "../modules/models";
import { Network } from "../primitives/network";
import { Deployment } from "../zos/deployment";
import { WorkloadTypes } from "../zos/workload";
import { HighLevelBase } from "./base";
const Flist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist";
class KubernetesHL extends HighLevelBase {
async add_master(
name: string,
nodeId: number,
secret: string,
cpu: number,
memory: number,
rootfs_size: number,
diskSize: number,
publicIp: boolean,
publicIp6: boolean,
planetary: boolean,
network: Network,
sshKey: string,
metadata = "",
description = "",
qsfs_disks: QSFSDiskModel[] = [],
qsfsProjectName = "",
addAccess = false,
accessNodeId = 0,
ip = "",
corex = false,
solutionProviderId: number,
zlogsOutput?: string,
gpus: string[] = [],
) {
events.emit("logs", `Creating a master with name: ${name} on node: ${nodeId}, network: ${network.name}`);
const machine = new VMHL(this.config);
const mountpoint = "/mnt/data";
const env = {
SSH_KEY: sshKey,
K3S_TOKEN: secret,
K3S_DATA_DIR: mountpoint,
K3S_FLANNEL_IFACE: "eth0",
K3S_NODE_NAME: name,
K3S_URL: "",
};
const disk = {
name: `${name}_disk`,
size: diskSize,
mountpoint: mountpoint,
};
return await machine.create(
name,
nodeId,
Flist,
cpu,
memory,
rootfs_size,
[disk],
publicIp,
publicIp6,
planetary,
network,
"/sbin/zinit init",
env,
metadata,
description,
qsfs_disks,
qsfsProjectName,
addAccess,
accessNodeId,
ip,
corex,
solutionProviderId,
zlogsOutput,
gpus,
);
}
async add_worker(
name: string,
nodeId: number,
secret: string,
masterIp: string,
cpu: number,
memory: number,
rootfs_size: number,
diskSize: number,
publicIp: boolean,
publicIp6: boolean,
planetary: boolean,
network: Network,
sshKey: string,
metadata = "",
description = "",
qsfs_disks: QSFSDiskModel[] = [],
qsfsProjectName = "",
addAccess = false,
accessNodeId = 0,
ip = "",
corex = false,
solutionProviderId: number,
zlogsOutput?: string,
gpus: string[] = [],
) {
events.emit("logs", `Creating a worker with name: ${name} on node: ${nodeId}, network: ${network.name}`);
const machine = new VMHL(this.config);
const mountpoint = "/mnt/data";
const env = {
SSH_KEY: sshKey,
K3S_TOKEN: secret,
K3S_DATA_DIR: mountpoint,
K3S_FLANNEL_IFACE: "eth0",
K3S_NODE_NAME: name,
K3S_URL: `https://${masterIp}:6443`,
};
const disk = {
name: `${name}_disk`,
size: diskSize,
mountpoint: mountpoint,
};
return await machine.create(
name,
nodeId,
Flist,
cpu,
memory,
rootfs_size,
[disk],
publicIp,
publicIp6,
planetary,
network,
"/sbin/zinit init",
env,
metadata,
description,
qsfs_disks,
qsfsProjectName,
addAccess,
accessNodeId,
ip,
corex,
solutionProviderId,
zlogsOutput,
gpus,
);
}
async delete(deployment: Deployment, names: string[]) {
return await this._delete(deployment, names, [
WorkloadTypes.zmachine,
WorkloadTypes.zmount,
WorkloadTypes.ip,
WorkloadTypes.ipv4,
WorkloadTypes.zlogs,
]); // TODO: remove deprecated
}
}
export { KubernetesHL };