underpost 2.8.791 → 2.8.792
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/db.js +1 -0
- package/cli.md +3 -1
- package/docker-compose.yml +1 -1
- package/package.json +1 -1
- package/src/cli/cluster.js +12 -0
- package/src/cli/index.js +1 -0
- package/src/cli/lxd.js +158 -2
- package/src/index.js +1 -1
package/README.md
CHANGED
package/bin/db.js
CHANGED
package/cli.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## underpost ci/cd cli v2.8.
|
|
1
|
+
## underpost ci/cd cli v2.8.792
|
|
2
2
|
|
|
3
3
|
### Usage: `underpost [options] [command]`
|
|
4
4
|
```
|
|
@@ -486,6 +486,8 @@ Options:
|
|
|
486
486
|
--create-vm <vm-id> Create default virtual machines
|
|
487
487
|
--init-vm <vm-id> Get init vm underpost script
|
|
488
488
|
--info-vm <vm-id> Get all info vm
|
|
489
|
+
--test <vm-id> Test health, status and network connectivity
|
|
490
|
+
for a VM
|
|
489
491
|
--root-size <gb-size> Set root size vm
|
|
490
492
|
--join-node <nodes> Comma separated worker and control node e.
|
|
491
493
|
g. k8s-worker-1,k8s-control
|
package/docker-compose.yml
CHANGED
package/package.json
CHANGED
package/src/cli/cluster.js
CHANGED
|
@@ -293,6 +293,18 @@ class UnderpostCluster {
|
|
|
293
293
|
shellExec(`sudo systemctl daemon-reload`);
|
|
294
294
|
shellExec(`sudo systemctl restart containerd`);
|
|
295
295
|
shellExec(`sysctl net.bridge.bridge-nf-call-iptables=1`);
|
|
296
|
+
// Clean ip tables
|
|
297
|
+
shellExec(`sudo iptables -F`);
|
|
298
|
+
shellExec(`sudo iptables -X`);
|
|
299
|
+
shellExec(`sudo iptables -t nat -F`);
|
|
300
|
+
shellExec(`sudo iptables -t nat -X`);
|
|
301
|
+
shellExec(`sudo iptables -t raw -F`);
|
|
302
|
+
shellExec(`sudo iptables -t raw -X`);
|
|
303
|
+
shellExec(`sudo iptables -t mangle -F`);
|
|
304
|
+
shellExec(`sudo iptables -t mangle -X`);
|
|
305
|
+
shellExec(`sudo iptables -P INPUT ACCEPT`);
|
|
306
|
+
shellExec(`sudo iptables -P FORWARD ACCEPT`);
|
|
307
|
+
shellExec(`sudo iptables -P OUTPUT ACCEPT`);
|
|
296
308
|
},
|
|
297
309
|
chown() {
|
|
298
310
|
shellExec(`mkdir -p ~/.kube`);
|
package/src/cli/index.js
CHANGED
|
@@ -283,6 +283,7 @@ program
|
|
|
283
283
|
.option('--create-vm <vm-id>', 'Create default virtual machines')
|
|
284
284
|
.option('--init-vm <vm-id>', 'Get init vm underpost script')
|
|
285
285
|
.option('--info-vm <vm-id>', 'Get all info vm')
|
|
286
|
+
.option('--test <vm-id>', 'Test health, status and network connectivity for a VM')
|
|
286
287
|
.option('--root-size <gb-size>', 'Set root size vm')
|
|
287
288
|
.option('--join-node <nodes>', 'Comma separated worker and control node e. g. k8s-worker-1,k8s-control')
|
|
288
289
|
.option(
|
package/src/cli/lxd.js
CHANGED
|
@@ -3,8 +3,34 @@ import { getLocalIPv4Address } from '../server/dns.js';
|
|
|
3
3
|
import { pbcopy, shellExec } from '../server/process.js';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @class UnderpostLxd
|
|
8
|
+
* @description Provides a set of static methods to interact with LXD,
|
|
9
|
+
* encapsulating common LXD operations for VM management and network testing.
|
|
10
|
+
*/
|
|
6
11
|
class UnderpostLxd {
|
|
7
12
|
static API = {
|
|
13
|
+
/**
|
|
14
|
+
* @method callback
|
|
15
|
+
* @description Main entry point for LXD operations based on provided options.
|
|
16
|
+
* @param {object} options - Configuration options for LXD operations.
|
|
17
|
+
* @param {boolean} [options.init=false] - Initialize LXD.
|
|
18
|
+
* @param {boolean} [options.reset=false] - Reset LXD installation.
|
|
19
|
+
* @param {boolean} [options.dev=false] - Run in development mode (adjusts paths).
|
|
20
|
+
* @param {boolean} [options.install=false] - Install LXD snap.
|
|
21
|
+
* @param {boolean} [options.createVirtualNetwork=false] - Create default LXD bridge network (lxdbr0).
|
|
22
|
+
* @param {boolean} [options.createAdminProfile=false] - Create admin-profile for VMs.
|
|
23
|
+
* @param {boolean} [options.control=false] - Flag for control plane VM initialization.
|
|
24
|
+
* @param {boolean} [options.worker=false] - Flag for worker node VM initialization.
|
|
25
|
+
* @param {string} [options.initVm=''] - Initialize a specific VM.
|
|
26
|
+
* @param {string} [options.createVm=''] - Create a new VM with the given name.
|
|
27
|
+
* @param {string} [options.infoVm=''] - Display information about a specific VM.
|
|
28
|
+
* @param {string} [options.rootSize=''] - Root disk size for new VMs (e.g., '32GiB').
|
|
29
|
+
* @param {string} [options.joinNode=''] - Join a worker node to a control plane (format: 'workerName,controlName').
|
|
30
|
+
* @param {string} [options.expose=''] - Expose ports from a VM to the host (format: 'vmName:port1,port2').
|
|
31
|
+
* @param {string} [options.deleteExpose=''] - Delete exposed ports from a VM (format: 'vmName:port1,port2').
|
|
32
|
+
* @param {string} [options.test=''] - Test health, status and network connectivity for a VM.
|
|
33
|
+
*/
|
|
8
34
|
async callback(
|
|
9
35
|
options = {
|
|
10
36
|
init: false,
|
|
@@ -12,6 +38,7 @@ class UnderpostLxd {
|
|
|
12
38
|
dev: false,
|
|
13
39
|
install: false,
|
|
14
40
|
createVirtualNetwork: false,
|
|
41
|
+
createAdminProfile: false,
|
|
15
42
|
control: false,
|
|
16
43
|
worker: false,
|
|
17
44
|
initVm: '',
|
|
@@ -21,6 +48,7 @@ class UnderpostLxd {
|
|
|
21
48
|
joinNode: '',
|
|
22
49
|
expose: '',
|
|
23
50
|
deleteExpose: '',
|
|
51
|
+
test: '',
|
|
24
52
|
},
|
|
25
53
|
) {
|
|
26
54
|
const npmRoot = getNpmRootPath();
|
|
@@ -67,6 +95,7 @@ ipv6.address=none`);
|
|
|
67
95
|
flag = ' -s -- --kubeadm';
|
|
68
96
|
shellExec(`lxc exec ${options.initVm} -- bash -c 'mkdir -p /home/dd/engine'`);
|
|
69
97
|
shellExec(`lxc file push /home/dd/engine/engine-private ${options.initVm}/home/dd/engine --recursive`);
|
|
98
|
+
shellExec(`lxc file push /home/dd/engine/manifests ${options.initVm}/home/dd/engine --recursive`);
|
|
70
99
|
} else if (options.worker == true) {
|
|
71
100
|
flag = ' -s -- --worker';
|
|
72
101
|
}
|
|
@@ -91,7 +120,6 @@ ipv6.address=none`);
|
|
|
91
120
|
console.log({ controlNode, ports });
|
|
92
121
|
const protocols = ['tcp']; // udp
|
|
93
122
|
const hostIp = getLocalIPv4Address();
|
|
94
|
-
// The vmIp will now be the static IP assigned in the admin-profile
|
|
95
123
|
const vmIp = shellExec(
|
|
96
124
|
`lxc list ${controlNode} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
97
125
|
{ stdout: true },
|
|
@@ -111,11 +139,139 @@ ipv6.address=none`);
|
|
|
111
139
|
const protocols = ['tcp']; // udp
|
|
112
140
|
for (const port of ports.split(',')) {
|
|
113
141
|
for (const protocol of protocols) {
|
|
114
|
-
// The device name is consistent: {controlNode}-port-{port}
|
|
115
142
|
shellExec(`lxc config device remove ${controlNode} ${controlNode}-${protocol}-port-${port}`);
|
|
116
143
|
}
|
|
117
144
|
}
|
|
118
145
|
}
|
|
146
|
+
|
|
147
|
+
// New 'test' option implementation
|
|
148
|
+
if (options.test && typeof options.test === 'string') {
|
|
149
|
+
const vmName = options.test;
|
|
150
|
+
console.log(`Starting comprehensive test for VM: ${vmName}`);
|
|
151
|
+
|
|
152
|
+
// 1. Monitor for IPv4 address
|
|
153
|
+
let vmIp = '';
|
|
154
|
+
let retries = 0;
|
|
155
|
+
const maxRetries = 10;
|
|
156
|
+
const delayMs = 5000; // 5 seconds
|
|
157
|
+
|
|
158
|
+
while (!vmIp && retries < maxRetries) {
|
|
159
|
+
try {
|
|
160
|
+
console.log(`Attempting to get IPv4 address for ${vmName} (Attempt ${retries + 1}/${maxRetries})...`);
|
|
161
|
+
vmIp = shellExec(
|
|
162
|
+
`lxc list ${vmName} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
163
|
+
{ stdout: true },
|
|
164
|
+
).trim();
|
|
165
|
+
if (vmIp) {
|
|
166
|
+
console.log(`IPv4 address found for ${vmName}: ${vmIp}`);
|
|
167
|
+
} else {
|
|
168
|
+
console.log(`IPv4 address not yet available for ${vmName}. Retrying in ${delayMs / 1000} seconds...`);
|
|
169
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error(`Error getting IPv4 address: ${error.message}`);
|
|
173
|
+
console.log(`Retrying in ${delayMs / 1000} seconds...`);
|
|
174
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
175
|
+
}
|
|
176
|
+
retries++;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!vmIp) {
|
|
180
|
+
console.error(`Failed to get IPv4 address for ${vmName} after ${maxRetries} attempts. Aborting tests.`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 2. Iteratively check connection to google.cl
|
|
185
|
+
let connectedToGoogle = false;
|
|
186
|
+
retries = 0;
|
|
187
|
+
while (!connectedToGoogle && retries < maxRetries) {
|
|
188
|
+
try {
|
|
189
|
+
console.log(`Checking connectivity to google.cl from ${vmName} (Attempt ${retries + 1}/${maxRetries})...`);
|
|
190
|
+
const curlOutput = shellExec(
|
|
191
|
+
`lxc exec ${vmName} -- curl -s -o /dev/null -w "%{http_code}" http://google.cl`,
|
|
192
|
+
{ stdout: true },
|
|
193
|
+
);
|
|
194
|
+
if (curlOutput.startsWith('2') || curlOutput.startsWith('3')) {
|
|
195
|
+
console.log(`Successfully connected to google.cl from ${vmName}.`);
|
|
196
|
+
connectedToGoogle = true;
|
|
197
|
+
} else {
|
|
198
|
+
console.log(`Connectivity to google.cl not yet verified. Retrying in ${delayMs / 1000} seconds...`);
|
|
199
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error(`Error checking connectivity to google.cl: ${error.message}`);
|
|
203
|
+
console.log(`Retrying in ${delayMs / 1000} seconds...`);
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
205
|
+
}
|
|
206
|
+
retries++;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!connectedToGoogle) {
|
|
210
|
+
console.error(
|
|
211
|
+
`Failed to connect to google.cl from ${vmName} after ${maxRetries} attempts. Aborting further tests.`,
|
|
212
|
+
);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 3. Check other connectivity, network, and VM health parameters
|
|
217
|
+
console.log(`\n--- Comprehensive Health Report for ${vmName} ---`);
|
|
218
|
+
|
|
219
|
+
// VM Status
|
|
220
|
+
console.log('\n--- VM Status ---');
|
|
221
|
+
try {
|
|
222
|
+
const vmStatus = shellExec(`lxc list ${vmName} --format json`, { stdout: true, silent: true });
|
|
223
|
+
console.log(JSON.stringify(JSON.parse(vmStatus), null, 2));
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error(`Error getting VM status: ${error.message}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// CPU Usage
|
|
229
|
+
console.log('\n--- CPU Usage ---');
|
|
230
|
+
try {
|
|
231
|
+
const cpuUsage = shellExec(`lxc exec ${vmName} -- bash -c 'top -bn1 | grep "Cpu(s)"'`, { stdout: true });
|
|
232
|
+
console.log(cpuUsage.trim());
|
|
233
|
+
} catch (error) {
|
|
234
|
+
console.error(`Error getting CPU usage: ${error.message}`);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Memory Usage
|
|
238
|
+
console.log('\n--- Memory Usage ---');
|
|
239
|
+
try {
|
|
240
|
+
const memoryUsage = shellExec(`lxc exec ${vmName} -- bash -c 'free -m'`, { stdout: true });
|
|
241
|
+
console.log(memoryUsage.trim());
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.error(`Error getting memory usage: ${error.message}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Disk Usage
|
|
247
|
+
console.log('\n--- Disk Usage (Root Partition) ---');
|
|
248
|
+
try {
|
|
249
|
+
const diskUsage = shellExec(`lxc exec ${vmName} -- bash -c 'df -h /'`, { stdout: true });
|
|
250
|
+
console.log(diskUsage.trim());
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error(`Error getting disk usage: ${error.message}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Network Interface Status
|
|
256
|
+
console.log('\n--- Network Interface Status (ip a) ---');
|
|
257
|
+
try {
|
|
258
|
+
const ipA = shellExec(`lxc exec ${vmName} -- bash -c 'ip a'`, { stdout: true });
|
|
259
|
+
console.log(ipA.trim());
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(`Error getting network interface status: ${error.message}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// DNS Resolution (resolv.conf)
|
|
265
|
+
console.log('\n--- DNS Configuration (/etc/resolv.conf) ---');
|
|
266
|
+
try {
|
|
267
|
+
const resolvConf = shellExec(`lxc exec ${vmName} -- bash -c 'cat /etc/resolv.conf'`, { stdout: true });
|
|
268
|
+
console.log(resolvConf.trim());
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error(`Error getting DNS configuration: ${error.message}`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
console.log(`\nComprehensive test for VM: ${vmName} completed.`);
|
|
274
|
+
}
|
|
119
275
|
},
|
|
120
276
|
};
|
|
121
277
|
}
|