underpost 3.2.5 → 3.2.9

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.
Files changed (144) hide show
  1. package/.github/workflows/release.cd.yml +1 -2
  2. package/CHANGELOG.md +351 -1
  3. package/CLI-HELP.md +40 -13
  4. package/Dockerfile +0 -4
  5. package/README.md +4 -4
  6. package/bin/build.js +14 -5
  7. package/bin/deploy.js +570 -1
  8. package/bin/file.js +6 -0
  9. package/conf.js +11 -2
  10. package/jsconfig.json +1 -1
  11. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +2 -2
  12. package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +2 -2
  13. package/manifests/deployment/dd-default-development/deployment.yaml +2 -6
  14. package/manifests/deployment/dd-test-development/deployment.yaml +136 -66
  15. package/manifests/deployment/dd-test-development/proxy.yaml +41 -5
  16. package/package.json +24 -15
  17. package/scripts/k3s-node-setup.sh +2 -2
  18. package/scripts/nat-iptables.sh +103 -18
  19. package/src/api/core/core.controller.js +10 -10
  20. package/src/api/core/core.service.js +10 -10
  21. package/src/api/default/default.controller.js +10 -10
  22. package/src/api/default/default.service.js +10 -10
  23. package/src/api/document/document.controller.js +12 -12
  24. package/src/api/document/document.model.js +10 -16
  25. package/src/api/file/file.controller.js +8 -8
  26. package/src/api/file/file.model.js +10 -10
  27. package/src/api/file/file.service.js +36 -36
  28. package/src/api/test/test.controller.js +8 -8
  29. package/src/api/test/test.service.js +8 -8
  30. package/src/api/user/guest.service.js +99 -0
  31. package/src/api/user/user.controller.js +6 -6
  32. package/src/api/user/user.model.js +8 -13
  33. package/src/api/user/user.service.js +3 -20
  34. package/src/cli/cluster.js +61 -14
  35. package/src/cli/db.js +47 -2
  36. package/src/cli/deploy.js +67 -35
  37. package/src/cli/fs.js +79 -8
  38. package/src/cli/image.js +43 -1
  39. package/src/cli/index.js +26 -1
  40. package/src/cli/release.js +57 -1
  41. package/src/cli/repository.js +69 -31
  42. package/src/cli/run.js +415 -36
  43. package/src/cli/ssh.js +1 -1
  44. package/src/cli/static.js +43 -115
  45. package/src/client/Default.index.js +21 -33
  46. package/src/client/components/core/404.js +4 -4
  47. package/src/client/components/core/500.js +4 -4
  48. package/src/client/components/core/Account.js +73 -60
  49. package/src/client/components/core/AgGrid.js +23 -33
  50. package/src/client/components/core/Alert.js +12 -13
  51. package/src/client/components/core/AppStore.js +1 -1
  52. package/src/client/components/core/Auth.js +35 -37
  53. package/src/client/components/core/Badge.js +7 -13
  54. package/src/client/components/core/BtnIcon.js +15 -17
  55. package/src/client/components/core/CalendarCore.js +42 -63
  56. package/src/client/components/core/Chat.js +13 -15
  57. package/src/client/components/core/ClientEvents.js +87 -0
  58. package/src/client/components/core/ColorPaletteElement.js +309 -0
  59. package/src/client/components/core/Content.js +17 -14
  60. package/src/client/components/core/Css.js +15 -71
  61. package/src/client/components/core/CssCore.js +12 -16
  62. package/src/client/components/core/D3Chart.js +4 -4
  63. package/src/client/components/core/Docs.js +64 -91
  64. package/src/client/components/core/DropDown.js +69 -91
  65. package/src/client/components/core/EventBus.js +92 -0
  66. package/src/client/components/core/EventsUI.js +14 -17
  67. package/src/client/components/core/FileExplorer.js +96 -228
  68. package/src/client/components/core/FullScreen.js +47 -75
  69. package/src/client/components/core/Input.js +24 -69
  70. package/src/client/components/core/Keyboard.js +25 -18
  71. package/src/client/components/core/KeyboardAvoidance.js +145 -0
  72. package/src/client/components/core/LoadingAnimation.js +25 -31
  73. package/src/client/components/core/LogIn.js +41 -41
  74. package/src/client/components/core/LogOut.js +23 -14
  75. package/src/client/components/core/Modal.js +462 -178
  76. package/src/client/components/core/NotificationManager.js +14 -18
  77. package/src/client/components/core/Panel.js +54 -50
  78. package/src/client/components/core/PanelForm.js +25 -125
  79. package/src/client/components/core/Polyhedron.js +110 -214
  80. package/src/client/components/core/PublicProfile.js +39 -32
  81. package/src/client/components/core/Recover.js +48 -44
  82. package/src/client/components/core/Responsive.js +88 -32
  83. package/src/client/components/core/RichText.js +9 -18
  84. package/src/client/components/core/Router.js +24 -3
  85. package/src/client/components/core/SearchBox.js +37 -37
  86. package/src/client/components/core/SignUp.js +39 -30
  87. package/src/client/components/core/SocketIo.js +31 -2
  88. package/src/client/components/core/SocketIoHandler.js +6 -6
  89. package/src/client/components/core/ToggleSwitch.js +8 -20
  90. package/src/client/components/core/ToolTip.js +5 -17
  91. package/src/client/components/core/Translate.js +56 -59
  92. package/src/client/components/core/Validator.js +26 -16
  93. package/src/client/components/core/Wallet.js +15 -26
  94. package/src/client/components/core/Worker.js +163 -27
  95. package/src/client/components/core/windowGetDimensions.js +7 -7
  96. package/src/client/components/default/{MenuDefault.js → AppShellDefault.js} +87 -87
  97. package/src/client/components/default/CssDefault.js +12 -12
  98. package/src/client/components/default/LogInDefault.js +6 -4
  99. package/src/client/components/default/LogOutDefault.js +6 -4
  100. package/src/client/components/default/RouterDefault.js +47 -0
  101. package/src/client/components/default/SettingsDefault.js +4 -4
  102. package/src/client/components/default/SignUpDefault.js +6 -4
  103. package/src/client/components/default/TranslateDefault.js +3 -3
  104. package/src/client/services/core/core.service.js +17 -49
  105. package/src/client/services/default/default.management.js +159 -267
  106. package/src/client/services/default/default.service.js +10 -16
  107. package/src/client/services/document/document.service.js +14 -19
  108. package/src/client/services/file/file.service.js +8 -13
  109. package/src/client/services/test/test.service.js +8 -13
  110. package/src/client/services/user/guest.service.js +86 -0
  111. package/src/client/services/user/user.management.js +5 -5
  112. package/src/client/services/user/user.service.js +14 -20
  113. package/src/client/ssr/body/404.js +3 -3
  114. package/src/client/ssr/body/500.js +3 -3
  115. package/src/client/ssr/body/CacheControl.js +5 -2
  116. package/src/client/ssr/body/DefaultSplashScreen.js +19 -12
  117. package/src/client/ssr/mailer/DefaultRecoverEmail.js +19 -20
  118. package/src/client/ssr/mailer/DefaultVerifyEmail.js +15 -16
  119. package/src/client/ssr/offline/Maintenance.js +12 -11
  120. package/src/client/ssr/offline/NoNetworkConnection.js +3 -3
  121. package/src/client/ssr/pages/Test.js +2 -2
  122. package/src/client/sw/core.sw.js +212 -0
  123. package/src/index.js +1 -1
  124. package/src/runtime/express/Dockerfile +4 -4
  125. package/src/runtime/lampp/Dockerfile +8 -7
  126. package/src/runtime/wp/Dockerfile +11 -17
  127. package/src/server/client-build-docs.js +45 -46
  128. package/src/server/client-build.js +334 -60
  129. package/src/server/client-formatted.js +47 -16
  130. package/src/server/conf.js +5 -4
  131. package/src/server/data-query.js +32 -20
  132. package/src/server/dns.js +22 -0
  133. package/src/server/ipfs-client.js +232 -91
  134. package/src/server/process.js +13 -27
  135. package/src/server/start.js +17 -3
  136. package/src/server/valkey.js +141 -235
  137. package/tsconfig.docs.json +15 -0
  138. package/typedoc.json +29 -0
  139. package/jsdoc.json +0 -52
  140. package/src/client/components/core/ColorPalette.js +0 -5267
  141. package/src/client/components/core/JoyStick.js +0 -80
  142. package/src/client/components/default/RoutesDefault.js +0 -49
  143. package/src/client/sw/default.sw.js +0 -127
  144. package/src/client/sw/template.sw.js +0 -84
@@ -3,8 +3,8 @@ import { TestService } from './test.service.js';
3
3
 
4
4
  const logger = loggerFactory(import.meta);
5
5
 
6
- const TestController = {
7
- post: async (req, res, options) => {
6
+ class TestController {
7
+ static post = async (req, res, options) => {
8
8
  try {
9
9
  return res.status(200).json({
10
10
  status: 'success',
@@ -17,8 +17,8 @@ const TestController = {
17
17
  message: error.message,
18
18
  });
19
19
  }
20
- },
21
- get: async (req, res, options) => {
20
+ };
21
+ static get = async (req, res, options) => {
22
22
  try {
23
23
  const result = await TestService.get(req, res, options);
24
24
  if (result)
@@ -37,8 +37,8 @@ const TestController = {
37
37
  message: error.message,
38
38
  });
39
39
  }
40
- },
41
- delete: async (req, res, options) => {
40
+ };
41
+ static delete = async (req, res, options) => {
42
42
  try {
43
43
  const result = await TestService.delete(req, res, options);
44
44
 
@@ -53,7 +53,7 @@ const TestController = {
53
53
  message: error.message,
54
54
  });
55
55
  }
56
- },
57
- };
56
+ };
57
+ }
58
58
 
59
59
  export { TestController };
@@ -5,14 +5,14 @@ import { getYouTubeID, validatePassword } from '../../client/components/core/Com
5
5
 
6
6
  const logger = loggerFactory(import.meta);
7
7
 
8
- const TestService = {
9
- post: async (req, res, options) => {
8
+ class TestService {
9
+ static post = async (req, res, options) => {
10
10
  switch (req.params.id) {
11
11
  default:
12
12
  break;
13
13
  }
14
- },
15
- get: async (req, res, options) => {
14
+ };
15
+ static get = async (req, res, options) => {
16
16
  switch (req.params.id) {
17
17
  case 'verify-email':
18
18
  return validator.isEmail(req.query.email);
@@ -23,13 +23,13 @@ const TestService = {
23
23
 
24
24
  default:
25
25
  }
26
- },
27
- delete: async (req, res, options) => {
26
+ };
27
+ static delete = async (req, res, options) => {
28
28
  switch (req.params.id) {
29
29
  default:
30
30
  break;
31
31
  }
32
- },
33
- };
32
+ };
33
+ }
34
34
 
35
35
  export { TestService };
@@ -0,0 +1,99 @@
1
+ import mongoose from 'mongoose';
2
+ import { UserDto } from './user.model.js';
3
+ import { ValkeyAPI } from '../../server/valkey.js';
4
+ import { hashPassword, getBearerToken, jwtSign } from '../../server/auth.js';
5
+
6
+ // ─── TTL ──────────────────────────────────────────────────────────────────────
7
+
8
+ const _guestTtlMs = () => {
9
+ const minutes = Number.parseInt(process.env.REFRESH_EXPIRE_MINUTES || '60', 10);
10
+ return Number.isFinite(minutes) && minutes > 0 ? minutes * 60 * 1000 : 60 * 60 * 1000;
11
+ };
12
+
13
+ // ─── Domain helpers ───────────────────────────────────────────────────────────
14
+
15
+ /**
16
+ * Constructs a new ephemeral guest user object.
17
+ * This is domain logic specific to the guest lifecycle; it does not belong
18
+ * in the generic Valkey storage module.
19
+ *
20
+ * @param {{ host?: string }} options
21
+ * @returns {object}
22
+ */
23
+ const buildGuestUser = (options) => {
24
+ const now = new Date().toISOString();
25
+ const _id = new mongoose.Types.ObjectId().toString();
26
+ const role = 'guest';
27
+ return {
28
+ _id: `${role}${_id}`,
29
+ username: `${role}${_id.slice(-5)}`,
30
+ email: `${_id}@${options.host || 'localhost'}`,
31
+ password: hashPassword(process.env.JWT_SECRET),
32
+ role,
33
+ emailConfirmed: false,
34
+ profileImageId: null,
35
+ publicKey: [],
36
+ phoneNumbers: [],
37
+ activeSessions: [],
38
+ failedLoginAttempts: 0,
39
+ recoverTimeOut: null,
40
+ lastLoginDate: null,
41
+ createdAt: now,
42
+ updatedAt: now,
43
+ guestSessionExpiresAt: Date.now() + _guestTtlMs(),
44
+ };
45
+ };
46
+
47
+ /**
48
+ * Projects a user object to the public-safe fields defined by UserDto.select.get().
49
+ * Keeps this logic next to the guest domain instead of in a generic utility.
50
+ *
51
+ * @param {object} user
52
+ * @returns {object}
53
+ */
54
+ const _toPublicUser = (user) => {
55
+ const select = UserDto.select.get();
56
+ return Object.fromEntries(
57
+ Object.keys(select)
58
+ .filter((k) => select[k] === 1 && k in user)
59
+ .map((k) => [k, user[k]]),
60
+ );
61
+ };
62
+
63
+ const _withRefreshedExpiry = (user) => ({ ...user, guestSessionExpiresAt: Date.now() + _guestTtlMs() });
64
+
65
+ // ─── Service ──────────────────────────────────────────────────────────────────
66
+
67
+ class GuestService {
68
+ static async create(req, options) {
69
+ const user = buildGuestUser(options);
70
+
71
+ await ValkeyAPI.set(options, user.email, user, _guestTtlMs());
72
+
73
+ return {
74
+ token: jwtSign(
75
+ UserDto.auth.payload(user, null, req.ip, req.headers['user-agent'], options.host, options.path),
76
+ options,
77
+ ),
78
+ user: _toPublicUser(user),
79
+ };
80
+ }
81
+
82
+ static async auth(req, options) {
83
+ const user = await ValkeyAPI.get(options, req.auth.user.email);
84
+ if (!user) throw new Error('guest user expired');
85
+
86
+ const expiresAt = Number(user.guestSessionExpiresAt || 0);
87
+ if (expiresAt && expiresAt <= Date.now()) throw new Error('guest user expired');
88
+
89
+ const refreshed = _withRefreshedExpiry(user);
90
+ await ValkeyAPI.set(options, refreshed.email, refreshed, _guestTtlMs());
91
+
92
+ return {
93
+ user: _toPublicUser(refreshed),
94
+ token: getBearerToken(req),
95
+ };
96
+ }
97
+ }
98
+
99
+ export { GuestService };
@@ -25,11 +25,11 @@ const handleRequest = (serviceMethod) => async (req, res, options) => {
25
25
  }
26
26
  };
27
27
 
28
- const UserController = {
29
- post: handleRequest(UserService.post),
30
- get: handleRequest(UserService.get),
31
- delete: handleRequest(UserService.delete),
32
- put: handleRequest(UserService.put),
33
- };
28
+ class UserController {
29
+ static post = handleRequest(UserService.post);
30
+ static get = handleRequest(UserService.get);
31
+ static delete = handleRequest(UserService.delete);
32
+ static put = handleRequest(UserService.put);
33
+ }
34
34
 
35
35
  export { UserController };
@@ -3,7 +3,6 @@ import validator from 'validator';
3
3
  import { userRoleEnum } from '../../client/components/core/CommonJs.js';
4
4
  import crypto from 'crypto';
5
5
  // https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
6
-
7
6
  const UserSchema = new Schema(
8
7
  {
9
8
  email: {
@@ -88,13 +87,10 @@ const UserSchema = new Schema(
88
87
  timestamps: true,
89
88
  },
90
89
  );
91
-
92
90
  const UserModel = model('User', UserSchema);
93
-
94
91
  const ProviderSchema = UserSchema;
95
-
96
- const UserDto = {
97
- select: {
92
+ class UserDto {
93
+ static select = {
98
94
  get: () => {
99
95
  return {
100
96
  _id: 1,
@@ -112,8 +108,8 @@ const UserDto = {
112
108
  getAll: () => {
113
109
  return { _id: 1 };
114
110
  },
115
- },
116
- public: {
111
+ };
112
+ static public = {
117
113
  get: () => {
118
114
  return {
119
115
  _id: 1,
@@ -125,8 +121,8 @@ const UserDto = {
125
121
  updatedAt: 1,
126
122
  };
127
123
  },
128
- },
129
- auth: {
124
+ };
125
+ static auth = {
130
126
  payload: (user, jwtid, ip, userAgent, host, path) => {
131
127
  const tokenPayload = {
132
128
  _id: user._id.toString(),
@@ -141,7 +137,6 @@ const UserDto = {
141
137
  };
142
138
  return tokenPayload;
143
139
  },
144
- },
145
- };
146
-
140
+ };
141
+ }
147
142
  export { UserSchema, UserModel, userRoleEnum, ProviderSchema, UserDto };
@@ -9,7 +9,6 @@ import {
9
9
  refreshSessionAndToken,
10
10
  logoutSession,
11
11
  jwtSign,
12
- getBearerToken,
13
12
  validatePasswordMiddleware,
14
13
  } from '../../server/auth.js';
15
14
  import { MailerProvider } from '../../mailer/MailerProvider.js';
@@ -19,8 +18,8 @@ import validator from 'validator';
19
18
  import { DataBaseProvider } from '../../db/DataBaseProvider.js';
20
19
  import { FileFactory, FileCleanup } from '../file/file.service.js';
21
20
  import { UserDto } from './user.model.js';
22
- import { selectDtoFactory, ValkeyAPI } from '../../server/valkey.js';
23
21
  import { timer } from '../../client/components/core/CommonJs.js';
22
+ import { GuestService } from './guest.service.js';
24
23
 
25
24
  const logger = loggerFactory(import.meta);
26
25
 
@@ -226,15 +225,7 @@ const UserService = {
226
225
  } else throw new Error('Invalid credentials');
227
226
 
228
227
  case 'guest': {
229
- const user = await ValkeyAPI.valkeyObjectFactory(options, 'user');
230
- await ValkeyAPI.setValkeyObject(options, user.email, user);
231
- return {
232
- token: jwtSign(
233
- UserDto.auth.payload(user, null, req.ip, req.headers['user-agent'], options.host, options.path),
234
- options,
235
- ),
236
- user: selectDtoFactory(user, UserDto.select.get()),
237
- };
228
+ return await GuestService.create(req, options);
238
229
  }
239
230
 
240
231
  default:
@@ -360,8 +351,7 @@ const UserService = {
360
351
  case 'auth': {
361
352
  let user;
362
353
  if (req.auth.user._id.match('guest')) {
363
- user = await ValkeyAPI.getValkeyObject(options, req.auth.user.email);
364
- if (!user) throw new Error('guest user expired');
354
+ return await GuestService.auth(req, options);
365
355
  } else
366
356
  user = await User.findOne({
367
357
  _id: req.auth.user._id,
@@ -369,13 +359,6 @@ const UserService = {
369
359
 
370
360
  if (!user) throw new Error('user not found');
371
361
 
372
- const guestUser = await ValkeyAPI.getValkeyObject(options, req.auth.user.email);
373
- if (guestUser)
374
- return {
375
- user: selectDtoFactory(guestUser, UserDto.select.get()),
376
- token: getBearerToken(req),
377
- };
378
-
379
362
  return {
380
363
  token: await refreshSessionAndToken(req, res, User, options),
381
364
  user: await User.findOne({
@@ -172,9 +172,19 @@ class UnderpostCluster {
172
172
  const podNetworkCidr = options.podNetworkCidr || '192.168.0.0/16';
173
173
  const controlPlaneEndpoint = options.controlPlaneEndpoint || `${os.hostname()}:6443`;
174
174
 
175
- // Initialize kubeadm control plane
175
+ // Initialize kubeadm control plane.
176
+ // Use CRI-O socket when available, otherwise fall back to containerd.
177
+ const crioSocket = 'unix:///var/run/crio/crio.sock';
178
+ const containerdSocket = 'unix:///run/containerd/containerd.sock';
179
+ const criSocket =
180
+ shellExec(`test -S /var/run/crio/crio.sock && echo crio || echo containerd`, {
181
+ stdout: true,
182
+ silent: true,
183
+ }).trim() === 'crio'
184
+ ? crioSocket
185
+ : containerdSocket;
176
186
  shellExec(
177
- `sudo kubeadm init --pod-network-cidr=${podNetworkCidr} --control-plane-endpoint="${controlPlaneEndpoint}"`,
187
+ `sudo kubeadm init --pod-network-cidr=${podNetworkCidr} --control-plane-endpoint="${controlPlaneEndpoint}" --cri-socket=${criSocket}`,
178
188
  );
179
189
  // Configure kubectl for the current user
180
190
  Underpost.cluster.chown('kubeadm'); // Pass 'kubeadm' to chown
@@ -389,8 +399,17 @@ EOF
389
399
  );
390
400
  shellExec(`rm -f ${tarPath}`);
391
401
  } else if (options.kubeadm || options.k3s) {
392
- // Kubeadm / K3s: use crictl to pull directly into containerd
393
- shellExec(`sudo crictl pull ${image}`);
402
+ // Kubeadm / K3s: use crictl to pull directly into the active CRI runtime.
403
+ // crictl is not in sudo's secure_path; pass full PATH through env.
404
+ // Point crictl at CRI-O when the socket exists, otherwise fall back to containerd.
405
+ const criSock =
406
+ shellExec(`test -S /var/run/crio/crio.sock && echo crio || echo containerd`, {
407
+ stdout: true,
408
+ silent: true,
409
+ }).trim() === 'crio'
410
+ ? 'unix:///var/run/crio/crio.sock'
411
+ : 'unix:///run/containerd/containerd.sock';
412
+ shellExec(`sudo env PATH="$PATH:/usr/local/bin:/usr/bin" crictl --runtime-endpoint ${criSock} pull ${image}`);
394
413
  }
395
414
  },
396
415
 
@@ -453,12 +472,11 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
453
472
  shellExec(`sudo sysctl -w fs.inotify.max_queued_events=2099999999`);
454
473
 
455
474
  // shellExec(`sudo sysctl --system`); // Apply sysctl changes immediately
456
- // Apply NAT iptables rules.
475
+ // Apply NAT iptables rules and configure firewalld for Kubernetes.
476
+ // nat-iptables.sh enables firewalld and opens all required ports; do NOT stop it
477
+ // afterwards — keeping firewalld running with these rules is required for
478
+ // multi-machine kubeadm inter-node communication.
457
479
  shellExec(`${underpostRoot}/scripts/nat-iptables.sh`, { silent: true });
458
-
459
- // Disable firewalld (common cause of network issues in Kubernetes)
460
- shellExec(`sudo systemctl stop firewalld`); // Stop if running
461
- shellExec(`sudo systemctl disable firewalld`); // Disable from starting on boot
462
480
  },
463
481
 
464
482
  /**
@@ -575,8 +593,10 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
575
593
  shellExec('sudo systemctl stop kubelet');
576
594
  shellExec('sudo systemctl stop docker');
577
595
  shellExec('sudo systemctl stop podman');
578
- // Safely unmount pod filesystems to avoid errors.
579
- shellExec('sudo umount -f /var/lib/kubelet/pods/*/*');
596
+ // Lazy-unmount all kubelet pod mounts to avoid 'Device or resource busy' on rm.
597
+ shellExec(
598
+ `sudo sh -c 'findmnt --raw --noheadings -o TARGET | grep /var/lib/kubelet | sort -r | xargs -r umount -l' 2>/dev/null || true`,
599
+ );
580
600
 
581
601
  // Phase 3: Execute official uninstallation commands (type-specific)
582
602
  const clusterType = options.clusterType || 'kind';
@@ -584,6 +604,14 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
584
604
  `Phase 3/7: Executing official reset/uninstallation commands for cluster type: '${clusterType}'...`,
585
605
  );
586
606
  if (clusterType === 'kubeadm') {
607
+ // Kill control plane processes that hold ports (6443, 10257, 10259, 2379, 2380)
608
+ // so the next `kubeadm init` does not fail with [ERROR Port-xxxx].
609
+ logger.info(' -> Stopping and killing control plane containers and processes...');
610
+ shellExec('sudo crictl rm -a -f 2>/dev/null || true');
611
+ shellExec('sudo crictl rmp -a -f 2>/dev/null || true');
612
+ shellExec('sudo systemctl stop etcd 2>/dev/null || true');
613
+ for (const port of [6443, 10259, 10257, 2379, 2380])
614
+ shellExec(`sudo fuser -k ${port}/tcp 2>/dev/null || true`);
587
615
  logger.info(' -> Executing kubeadm reset...');
588
616
  shellExec('sudo kubeadm reset --force');
589
617
  } else if (clusterType === 'k3s') {
@@ -600,7 +628,12 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
600
628
  // Remove any leftover configurations and data.
601
629
  shellExec('sudo rm -rf /etc/kubernetes/*');
602
630
  shellExec('sudo rm -rf /etc/cni/net.d/*');
631
+ // Second-pass lazy umount before rm to clear any remaining busy mounts.
632
+ shellExec(
633
+ `sudo sh -c 'findmnt --raw --noheadings -o TARGET | grep /var/lib/kubelet | sort -r | xargs -r umount -l' 2>/dev/null || true`,
634
+ );
603
635
  shellExec('sudo rm -rf /var/lib/kubelet/*');
636
+ shellExec('sudo rm -rf /var/lib/etcd');
604
637
  shellExec('sudo rm -rf /var/lib/cni/*');
605
638
  shellExec('sudo rm -rf /var/lib/docker/*');
606
639
  shellExec('sudo rm -rf /var/lib/containerd/*');
@@ -613,11 +646,14 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
613
646
  // Remove iptables rules and CNI network interfaces.
614
647
  shellExec('sudo iptables -F');
615
648
  shellExec('sudo iptables -t nat -F');
616
- shellExec('sudo ip link del cni0');
617
- shellExec('sudo ip link del flannel.1');
649
+ shellExec('sudo ip link del cni0 2>/dev/null || true');
650
+ shellExec('sudo ip link del flannel.1 2>/dev/null || true');
651
+ shellExec('sudo ip link del vxlan.calico 2>/dev/null || true');
652
+ shellExec('sudo ip link del tunl0 2>/dev/null || true');
618
653
 
619
654
  logger.info('Phase 6/7: Clean up images');
620
- shellExec(`podman rmi $(podman images -qa) --force`);
655
+ shellExec('sudo podman rmi --all --force 2>/dev/null || true');
656
+ shellExec('sudo crictl rmi --prune 2>/dev/null || true');
621
657
 
622
658
  // Phase 6: Reload daemon and finalize
623
659
  logger.info('Phase 7/7: Reloading the system daemon and finalizing...');
@@ -687,6 +723,9 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
687
723
  // Install Podman
688
724
  shellExec(`sudo dnf -y install podman`);
689
725
 
726
+ // Install CRI-O (required for kubeadm with CRI-O socket)
727
+ shellExec(`node bin run install-crio`);
728
+
690
729
  // Install Kind (Kubernetes in Docker)
691
730
  shellExec(`[ $(uname -m) = ${archData.name} ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-${archData.alias}
692
731
  chmod +x ./kind
@@ -744,6 +783,14 @@ EOF`);
744
783
  console.log('Removing Podman...');
745
784
  shellExec(`sudo dnf -y remove podman`);
746
785
 
786
+ // Remove CRI-O
787
+ console.log('Removing CRI-O...');
788
+ shellExec(`sudo systemctl stop crio 2>/dev/null || true`);
789
+ shellExec(`sudo systemctl disable crio 2>/dev/null || true`);
790
+ shellExec(`sudo dnf -y remove cri-o`);
791
+ shellExec(`sudo rm -f /etc/yum.repos.d/cri-o.repo`);
792
+ shellExec(`sudo rm -f /etc/crictl.yaml`);
793
+
747
794
  // Remove Kubeadm, Kubelet, and Kubectl
748
795
  console.log('Removing Kubernetes tools...');
749
796
  shellExec(`sudo yum remove -y kubelet kubeadm kubectl`);
package/src/cli/db.js CHANGED
@@ -839,6 +839,8 @@ class UnderpostDB {
839
839
  pods: podsToProcess.map((p) => p.NAME),
840
840
  });
841
841
 
842
+ let exportSucceeded = false;
843
+
842
844
  // Process each pod
843
845
  for (const pod of podsToProcess) {
844
846
  logger.info('Processing pod', { podName: pod.NAME, node: pod.NODE, status: pod.STATUS });
@@ -871,7 +873,7 @@ class UnderpostDB {
871
873
 
872
874
  if (options.export === true) {
873
875
  const outputPath = options.outPath || toNewSqlPath;
874
- await Underpost.db._exportMariaDB({
876
+ const success = await Underpost.db._exportMariaDB({
875
877
  pod,
876
878
  namespace,
877
879
  dbName,
@@ -879,6 +881,7 @@ class UnderpostDB {
879
881
  password,
880
882
  outputPath,
881
883
  });
884
+ exportSucceeded = exportSucceeded || success;
882
885
  }
883
886
  break;
884
887
  }
@@ -909,13 +912,14 @@ class UnderpostDB {
909
912
 
910
913
  if (options.export === true) {
911
914
  const outputPath = options.outPath || toNewBsonPath;
912
- Underpost.db._exportMongoDB({
915
+ const success = Underpost.db._exportMongoDB({
913
916
  pod,
914
917
  namespace,
915
918
  dbName,
916
919
  outputPath,
917
920
  collections: options.collections,
918
921
  });
922
+ exportSucceeded = exportSucceeded || success;
919
923
  }
920
924
  break;
921
925
  }
@@ -926,6 +930,10 @@ class UnderpostDB {
926
930
  }
927
931
  }
928
932
 
933
+ if (options.export === true && exportSucceeded === true) {
934
+ Underpost.db._enforceBackupRetention(`../${repoName}/${hostFolder}`);
935
+ }
936
+
929
937
  // Mark this host+path combination as processed
930
938
  processedHostPaths.add(hostPathKey);
931
939
  }
@@ -948,6 +956,43 @@ class UnderpostDB {
948
956
  throw error;
949
957
  }
950
958
  },
959
+ /**
960
+ * Helper: Removes old timestamp backup folders and keeps only the newest ones.
961
+ * @method _enforceBackupRetention
962
+ * @memberof UnderpostDB
963
+ * @param {string} backupDir - Path to host-folder backup directory.
964
+ * @param {number} [maxRetention=MAX_BACKUP_RETENTION] - Maximum folders to keep.
965
+ * @return {number} Number of removed backup folders.
966
+ */
967
+ _enforceBackupRetention(backupDir, maxRetention = MAX_BACKUP_RETENTION) {
968
+ try {
969
+ if (!fs.existsSync(backupDir)) return 0;
970
+
971
+ const timestamps = fs
972
+ .readdirSync(backupDir)
973
+ .filter((entry) => /^\d+$/.test(entry))
974
+ .sort((a, b) => parseInt(b, 10) - parseInt(a, 10));
975
+
976
+ if (timestamps.length <= maxRetention) return 0;
977
+
978
+ const staleTimestamps = timestamps.slice(maxRetention);
979
+ staleTimestamps.forEach((timestamp) => {
980
+ fs.removeSync(`${backupDir}/${timestamp}`);
981
+ });
982
+
983
+ logger.info('Pruned old backup timestamp folders', {
984
+ backupDir,
985
+ kept: maxRetention,
986
+ removed: staleTimestamps.length,
987
+ removedTimestamps: staleTimestamps,
988
+ });
989
+
990
+ return staleTimestamps.length;
991
+ } catch (error) {
992
+ logger.error('Failed to enforce backup retention', { backupDir, maxRetention, error: error.message });
993
+ return 0;
994
+ }
995
+ },
951
996
 
952
997
  /**
953
998
  * Creates cluster metadata for the specified deployment.