cyberia 2.8.885

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 (525) hide show
  1. package/.dockerignore +15 -0
  2. package/.env.development +45 -0
  3. package/.env.production +50 -0
  4. package/.env.test +45 -0
  5. package/.github/workflows/engine-cyberia.cd.yml +31 -0
  6. package/.github/workflows/engine-cyberia.ci.yml +60 -0
  7. package/.github/workflows/ghpkg.ci.yml +87 -0
  8. package/.github/workflows/npmpkg.ci.yml +72 -0
  9. package/.github/workflows/publish.ci.yml +84 -0
  10. package/.github/workflows/publish.cyberia.ci.yml +84 -0
  11. package/.github/workflows/pwa-microservices-template-page.cd.yml +72 -0
  12. package/.github/workflows/pwa-microservices-template-test.ci.yml +33 -0
  13. package/.github/workflows/release.cd.yml +37 -0
  14. package/.nycrc +9 -0
  15. package/.prettierignore +13 -0
  16. package/.prettierrc +9 -0
  17. package/.vscode/extensions.json +51 -0
  18. package/.vscode/settings.json +87 -0
  19. package/AUTHORS.md +21 -0
  20. package/CHANGELOG.md +205 -0
  21. package/Dockerfile +28 -0
  22. package/LICENSE +21 -0
  23. package/README.md +85 -0
  24. package/bin/build.js +209 -0
  25. package/bin/cron.js +47 -0
  26. package/bin/cyberia.js +145 -0
  27. package/bin/db.js +199 -0
  28. package/bin/deploy.js +1293 -0
  29. package/bin/file.js +197 -0
  30. package/bin/hwt.js +49 -0
  31. package/bin/index.js +145 -0
  32. package/bin/ssl.js +63 -0
  33. package/bin/util.js +80 -0
  34. package/bin/vs.js +74 -0
  35. package/cli.md +714 -0
  36. package/conf.js +204 -0
  37. package/deployment.yaml +138 -0
  38. package/jsconfig.json +7 -0
  39. package/jsdoc.json +32 -0
  40. package/manifests/deployment/adminer/deployment.yaml +32 -0
  41. package/manifests/deployment/adminer/kustomization.yaml +7 -0
  42. package/manifests/deployment/adminer/service.yaml +13 -0
  43. package/manifests/deployment/dd-default-development/deployment.yaml +167 -0
  44. package/manifests/deployment/dd-default-development/proxy.yaml +46 -0
  45. package/manifests/deployment/dd-test-development/deployment.yaml +174 -0
  46. package/manifests/deployment/dd-test-development/proxy.yaml +51 -0
  47. package/manifests/deployment/fastapi/backend-deployment.yml +120 -0
  48. package/manifests/deployment/fastapi/backend-service.yml +19 -0
  49. package/manifests/deployment/fastapi/frontend-deployment.yml +54 -0
  50. package/manifests/deployment/fastapi/frontend-service.yml +15 -0
  51. package/manifests/deployment/fastapi/initial_data.sh +56 -0
  52. package/manifests/deployment/kafka/deployment.yaml +69 -0
  53. package/manifests/deployment/mongo-express/deployment.yaml +60 -0
  54. package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
  55. package/manifests/deployment/spark/spark-pi-py.yaml +21 -0
  56. package/manifests/deployment/tensorflow/tf-gpu-test.yaml +65 -0
  57. package/manifests/envoy-service-nodeport.yaml +23 -0
  58. package/manifests/grafana/deployment.yaml +57 -0
  59. package/manifests/grafana/kustomization.yaml +7 -0
  60. package/manifests/grafana/pvc.yaml +12 -0
  61. package/manifests/grafana/service.yaml +14 -0
  62. package/manifests/kind-config-dev.yaml +12 -0
  63. package/manifests/kind-config.yaml +12 -0
  64. package/manifests/kubeadm-calico-config.yaml +119 -0
  65. package/manifests/kubelet-config.yaml +65 -0
  66. package/manifests/letsencrypt-prod.yaml +15 -0
  67. package/manifests/lxd/lxd-admin-profile.yaml +17 -0
  68. package/manifests/lxd/lxd-preseed.yaml +30 -0
  69. package/manifests/lxd/underpost-setup.sh +163 -0
  70. package/manifests/mariadb/config.yaml +10 -0
  71. package/manifests/mariadb/kustomization.yaml +9 -0
  72. package/manifests/mariadb/pv.yaml +12 -0
  73. package/manifests/mariadb/pvc.yaml +10 -0
  74. package/manifests/mariadb/secret.yaml +8 -0
  75. package/manifests/mariadb/service.yaml +10 -0
  76. package/manifests/mariadb/statefulset.yaml +56 -0
  77. package/manifests/mariadb/storage-class.yaml +10 -0
  78. package/manifests/mongodb/backup-access.yaml +16 -0
  79. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  80. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  81. package/manifests/mongodb/configmap.yaml +26 -0
  82. package/manifests/mongodb/headless-service.yaml +10 -0
  83. package/manifests/mongodb/kustomization.yaml +11 -0
  84. package/manifests/mongodb/pv-pvc.yaml +23 -0
  85. package/manifests/mongodb/statefulset.yaml +126 -0
  86. package/manifests/mongodb/storage-class.yaml +9 -0
  87. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  88. package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
  89. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  90. package/manifests/mysql/kustomization.yaml +7 -0
  91. package/manifests/mysql/pv-pvc.yaml +27 -0
  92. package/manifests/mysql/statefulset.yaml +55 -0
  93. package/manifests/postgresql/configmap.yaml +9 -0
  94. package/manifests/postgresql/kustomization.yaml +10 -0
  95. package/manifests/postgresql/pv.yaml +15 -0
  96. package/manifests/postgresql/pvc.yaml +13 -0
  97. package/manifests/postgresql/service.yaml +10 -0
  98. package/manifests/postgresql/statefulset.yaml +37 -0
  99. package/manifests/prometheus/deployment.yaml +82 -0
  100. package/manifests/valkey/kustomization.yaml +7 -0
  101. package/manifests/valkey/service.yaml +11 -0
  102. package/manifests/valkey/statefulset.yaml +38 -0
  103. package/nodemon.json +6 -0
  104. package/package.json +118 -0
  105. package/proxy.yaml +35 -0
  106. package/scripts/device-scan.sh +43 -0
  107. package/scripts/gpu-diag.sh +19 -0
  108. package/scripts/maas-setup.sh +120 -0
  109. package/scripts/nat-iptables.sh +26 -0
  110. package/scripts/nvim.sh +91 -0
  111. package/scripts/snap-clean.sh +26 -0
  112. package/scripts/ssh-cluster-info.sh +14 -0
  113. package/scripts/ssl.sh +164 -0
  114. package/src/api/blockchain/blockchain.controller.js +51 -0
  115. package/src/api/blockchain/blockchain.model.js +90 -0
  116. package/src/api/blockchain/blockchain.router.js +21 -0
  117. package/src/api/blockchain/blockchain.service.js +24 -0
  118. package/src/api/core/core.controller.js +69 -0
  119. package/src/api/core/core.model.js +11 -0
  120. package/src/api/core/core.router.js +24 -0
  121. package/src/api/core/core.service.js +35 -0
  122. package/src/api/crypto/crypto.controller.js +51 -0
  123. package/src/api/crypto/crypto.model.js +23 -0
  124. package/src/api/crypto/crypto.router.js +20 -0
  125. package/src/api/crypto/crypto.service.js +64 -0
  126. package/src/api/default/default.controller.js +74 -0
  127. package/src/api/default/default.model.js +20 -0
  128. package/src/api/default/default.router.js +27 -0
  129. package/src/api/default/default.service.js +40 -0
  130. package/src/api/document/document.controller.js +66 -0
  131. package/src/api/document/document.model.js +51 -0
  132. package/src/api/document/document.router.js +24 -0
  133. package/src/api/document/document.service.js +133 -0
  134. package/src/api/file/file.controller.js +67 -0
  135. package/src/api/file/file.model.js +19 -0
  136. package/src/api/file/file.router.js +22 -0
  137. package/src/api/file/file.service.js +100 -0
  138. package/src/api/instance/instance.controller.js +69 -0
  139. package/src/api/instance/instance.model.js +40 -0
  140. package/src/api/instance/instance.router.js +34 -0
  141. package/src/api/instance/instance.service.js +70 -0
  142. package/src/api/ipfs/ipfs.controller.js +51 -0
  143. package/src/api/ipfs/ipfs.model.js +17 -0
  144. package/src/api/ipfs/ipfs.router.js +20 -0
  145. package/src/api/ipfs/ipfs.service.js +25 -0
  146. package/src/api/object-layer/README.md +85 -0
  147. package/src/api/object-layer/object-layer.controller.js +69 -0
  148. package/src/api/object-layer/object-layer.model.js +181 -0
  149. package/src/api/object-layer/object-layer.router.js +29 -0
  150. package/src/api/object-layer/object-layer.service.js +49 -0
  151. package/src/api/test/test.controller.js +59 -0
  152. package/src/api/test/test.model.js +14 -0
  153. package/src/api/test/test.router.js +21 -0
  154. package/src/api/test/test.service.js +35 -0
  155. package/src/api/user/postman_collection.json +216 -0
  156. package/src/api/user/user.build.js +16 -0
  157. package/src/api/user/user.controller.js +35 -0
  158. package/src/api/user/user.model.js +100 -0
  159. package/src/api/user/user.router.js +400 -0
  160. package/src/api/user/user.service.js +500 -0
  161. package/src/api.js +23 -0
  162. package/src/cli/baremetal.js +1310 -0
  163. package/src/cli/cloud-init.js +548 -0
  164. package/src/cli/cluster.js +834 -0
  165. package/src/cli/cron.js +95 -0
  166. package/src/cli/db.js +414 -0
  167. package/src/cli/deploy.js +661 -0
  168. package/src/cli/env.js +101 -0
  169. package/src/cli/fs.js +256 -0
  170. package/src/cli/image.js +156 -0
  171. package/src/cli/index.js +436 -0
  172. package/src/cli/lxd.js +402 -0
  173. package/src/cli/monitor.js +260 -0
  174. package/src/cli/repository.js +274 -0
  175. package/src/cli/run.js +728 -0
  176. package/src/cli/script.js +85 -0
  177. package/src/cli/secrets.js +71 -0
  178. package/src/cli/ssh.js +46 -0
  179. package/src/cli/test.js +159 -0
  180. package/src/client/Cyberia.index.js +50 -0
  181. package/src/client/CyberiaAdmin.index.js +34 -0
  182. package/src/client/CyberiaPortal.index.js +36 -0
  183. package/src/client/Default.index.js +84 -0
  184. package/src/client/components/core/404.js +20 -0
  185. package/src/client/components/core/500.js +20 -0
  186. package/src/client/components/core/Account.js +326 -0
  187. package/src/client/components/core/AgGrid.js +191 -0
  188. package/src/client/components/core/Alert.js +77 -0
  189. package/src/client/components/core/Auth.js +342 -0
  190. package/src/client/components/core/Badge.js +32 -0
  191. package/src/client/components/core/Blockchain.js +41 -0
  192. package/src/client/components/core/Blog.js +9 -0
  193. package/src/client/components/core/BtnIcon.js +111 -0
  194. package/src/client/components/core/CalendarCore.js +464 -0
  195. package/src/client/components/core/Chat.js +64 -0
  196. package/src/client/components/core/ColorPalette.js +5267 -0
  197. package/src/client/components/core/CommonJs.js +1010 -0
  198. package/src/client/components/core/Content.js +196 -0
  199. package/src/client/components/core/Css.js +1099 -0
  200. package/src/client/components/core/CssCore.js +882 -0
  201. package/src/client/components/core/D3Chart.js +44 -0
  202. package/src/client/components/core/Docs.js +376 -0
  203. package/src/client/components/core/DropDown.js +223 -0
  204. package/src/client/components/core/EventsUI.js +133 -0
  205. package/src/client/components/core/FileExplorer.js +707 -0
  206. package/src/client/components/core/FullScreen.js +36 -0
  207. package/src/client/components/core/Input.js +383 -0
  208. package/src/client/components/core/JoyStick.js +80 -0
  209. package/src/client/components/core/Keyboard.js +73 -0
  210. package/src/client/components/core/LoadingAnimation.js +159 -0
  211. package/src/client/components/core/LogIn.js +190 -0
  212. package/src/client/components/core/LogOut.js +63 -0
  213. package/src/client/components/core/Logger.js +29 -0
  214. package/src/client/components/core/Modal.js +2494 -0
  215. package/src/client/components/core/NotificationManager.js +84 -0
  216. package/src/client/components/core/ObjectLayerEngine.js +1229 -0
  217. package/src/client/components/core/ObjectLayerEngineModal.js +443 -0
  218. package/src/client/components/core/Pagination.js +207 -0
  219. package/src/client/components/core/Panel.js +772 -0
  220. package/src/client/components/core/PanelForm.js +627 -0
  221. package/src/client/components/core/Polyhedron.js +162 -0
  222. package/src/client/components/core/Recover.js +207 -0
  223. package/src/client/components/core/Responsive.js +82 -0
  224. package/src/client/components/core/RichText.js +43 -0
  225. package/src/client/components/core/Router.js +317 -0
  226. package/src/client/components/core/Scroll.js +76 -0
  227. package/src/client/components/core/SignUp.js +125 -0
  228. package/src/client/components/core/SocketIo.js +74 -0
  229. package/src/client/components/core/Stream.js +113 -0
  230. package/src/client/components/core/ToggleSwitch.js +101 -0
  231. package/src/client/components/core/ToolTip.js +90 -0
  232. package/src/client/components/core/Translate.js +522 -0
  233. package/src/client/components/core/Validator.js +115 -0
  234. package/src/client/components/core/VanillaJs.js +423 -0
  235. package/src/client/components/core/Wallet.js +106 -0
  236. package/src/client/components/core/WebComponent.js +44 -0
  237. package/src/client/components/core/Webhook.js +25 -0
  238. package/src/client/components/core/Worker.js +371 -0
  239. package/src/client/components/core/windowGetDimensions.js +269 -0
  240. package/src/client/components/cyberia/BagCyberia.js +1253 -0
  241. package/src/client/components/cyberia/BiomeCyberia.js +130 -0
  242. package/src/client/components/cyberia/CharacterCyberia.js +321 -0
  243. package/src/client/components/cyberia/CommonCyberia.js +1834 -0
  244. package/src/client/components/cyberia/CssCyberia.js +816 -0
  245. package/src/client/components/cyberia/ElementPreviewCyberia.js +183 -0
  246. package/src/client/components/cyberia/ElementsCyberia.js +146 -0
  247. package/src/client/components/cyberia/InteractionPanelCyberia.js +1043 -0
  248. package/src/client/components/cyberia/JoyStickCyberia.js +53 -0
  249. package/src/client/components/cyberia/LogInCyberia.js +68 -0
  250. package/src/client/components/cyberia/LogOutCyberia.js +24 -0
  251. package/src/client/components/cyberia/MainUserCyberia.js +424 -0
  252. package/src/client/components/cyberia/MapCyberia.js +160 -0
  253. package/src/client/components/cyberia/MatrixCyberia.js +147 -0
  254. package/src/client/components/cyberia/MenuCyberia.js +575 -0
  255. package/src/client/components/cyberia/PixiCyberia.js +1639 -0
  256. package/src/client/components/cyberia/PointAndClickMovementCyberia.js +146 -0
  257. package/src/client/components/cyberia/QuestCyberia.js +1420 -0
  258. package/src/client/components/cyberia/RoutesCyberia.js +47 -0
  259. package/src/client/components/cyberia/SettingsCyberia.js +16 -0
  260. package/src/client/components/cyberia/SignUpCyberia.js +14 -0
  261. package/src/client/components/cyberia/SkillCyberia.js +124 -0
  262. package/src/client/components/cyberia/SocketIoCyberia.js +211 -0
  263. package/src/client/components/cyberia/TileCyberia.js +685 -0
  264. package/src/client/components/cyberia/TranslateCyberia.js +96 -0
  265. package/src/client/components/cyberia/UniverseCyberia.js +14 -0
  266. package/src/client/components/cyberia/WebhookCyberia.js +13 -0
  267. package/src/client/components/cyberia/WikiCyberia.js +144 -0
  268. package/src/client/components/cyberia/WorldCyberia.js +680 -0
  269. package/src/client/components/cyberia-admin/BiomeCyberiaAdmin.js +978 -0
  270. package/src/client/components/cyberia-admin/CommonCyberiaAdmin.js +29 -0
  271. package/src/client/components/cyberia-admin/CssCyberiaAdmin.js +15 -0
  272. package/src/client/components/cyberia-admin/ElementsCyberiaAdmin.js +38 -0
  273. package/src/client/components/cyberia-admin/InstanceEngineCyberiaAdmin.js +180 -0
  274. package/src/client/components/cyberia-admin/LogInCyberiaAdmin.js +34 -0
  275. package/src/client/components/cyberia-admin/LogOutCyberiaAdmin.js +24 -0
  276. package/src/client/components/cyberia-admin/MenuCyberiaAdmin.js +660 -0
  277. package/src/client/components/cyberia-admin/RoutesCyberiaAdmin.js +57 -0
  278. package/src/client/components/cyberia-admin/ServerCyberiaAdmin.js +129 -0
  279. package/src/client/components/cyberia-admin/SettingsCyberiaAdmin.js +16 -0
  280. package/src/client/components/cyberia-admin/SignUpCyberiaAdmin.js +11 -0
  281. package/src/client/components/cyberia-admin/SocketIoCyberiaAdmin.js +53 -0
  282. package/src/client/components/cyberia-admin/TranslateCyberiaAdmin.js +7 -0
  283. package/src/client/components/cyberia-biome/CityCyberiaBiome.js +209 -0
  284. package/src/client/components/cyberia-biome/CityInteriorCyberiaBiome.js +253 -0
  285. package/src/client/components/cyberia-biome/ColorChaosCyberiaBiome.js +26 -0
  286. package/src/client/components/cyberia-biome/ForestCyberiaBiome.js +191 -0
  287. package/src/client/components/cyberia-biome/GridBaseCyberiaBiome.js +364 -0
  288. package/src/client/components/cyberia-biome/SeedCityCyberiaBiome.js +347 -0
  289. package/src/client/components/cyberia-biome/ShopCyberiaBiome.js +12 -0
  290. package/src/client/components/cyberia-biome/SpaceCyberiaBiome.js +58 -0
  291. package/src/client/components/cyberia-portal/CommonCyberiaPortal.js +29 -0
  292. package/src/client/components/cyberia-portal/CssCyberiaPortal.js +132 -0
  293. package/src/client/components/cyberia-portal/ElementsCyberiaPortal.js +38 -0
  294. package/src/client/components/cyberia-portal/LogInCyberiaPortal.js +18 -0
  295. package/src/client/components/cyberia-portal/LogOutCyberiaPortal.js +12 -0
  296. package/src/client/components/cyberia-portal/MenuCyberiaPortal.js +487 -0
  297. package/src/client/components/cyberia-portal/RoutesCyberiaPortal.js +45 -0
  298. package/src/client/components/cyberia-portal/ServerCyberiaPortal.js +136 -0
  299. package/src/client/components/cyberia-portal/SettingsCyberiaPortal.js +16 -0
  300. package/src/client/components/cyberia-portal/SignUpCyberiaPortal.js +11 -0
  301. package/src/client/components/cyberia-portal/SocketIoCyberiaPortal.js +52 -0
  302. package/src/client/components/cyberia-portal/TranslateCyberiaPortal.js +12 -0
  303. package/src/client/components/default/CommonDefault.js +29 -0
  304. package/src/client/components/default/CssDefault.js +27 -0
  305. package/src/client/components/default/ElementsDefault.js +38 -0
  306. package/src/client/components/default/LogInDefault.js +14 -0
  307. package/src/client/components/default/LogOutDefault.js +10 -0
  308. package/src/client/components/default/MenuDefault.js +743 -0
  309. package/src/client/components/default/RoutesDefault.js +48 -0
  310. package/src/client/components/default/SettingsDefault.js +16 -0
  311. package/src/client/components/default/SignUpDefault.js +9 -0
  312. package/src/client/components/default/SocketIoDefault.js +54 -0
  313. package/src/client/components/default/TranslateDefault.js +7 -0
  314. package/src/client/public/default/android-chrome-144x144.png +0 -0
  315. package/src/client/public/default/android-chrome-192x192.png +0 -0
  316. package/src/client/public/default/android-chrome-256x256.png +0 -0
  317. package/src/client/public/default/android-chrome-36x36.png +0 -0
  318. package/src/client/public/default/android-chrome-384x384.png +0 -0
  319. package/src/client/public/default/android-chrome-48x48.png +0 -0
  320. package/src/client/public/default/android-chrome-512x512.png +0 -0
  321. package/src/client/public/default/android-chrome-72x72.png +0 -0
  322. package/src/client/public/default/android-chrome-96x96.png +0 -0
  323. package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
  324. package/src/client/public/default/apple-touch-icon-114x114-precomposed.png +0 -0
  325. package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
  326. package/src/client/public/default/apple-touch-icon-120x120-precomposed.png +0 -0
  327. package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
  328. package/src/client/public/default/apple-touch-icon-144x144-precomposed.png +0 -0
  329. package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
  330. package/src/client/public/default/apple-touch-icon-152x152-precomposed.png +0 -0
  331. package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
  332. package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
  333. package/src/client/public/default/apple-touch-icon-180x180-precomposed.png +0 -0
  334. package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
  335. package/src/client/public/default/apple-touch-icon-57x57-precomposed.png +0 -0
  336. package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
  337. package/src/client/public/default/apple-touch-icon-60x60-precomposed.png +0 -0
  338. package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
  339. package/src/client/public/default/apple-touch-icon-72x72-precomposed.png +0 -0
  340. package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
  341. package/src/client/public/default/apple-touch-icon-76x76-precomposed.png +0 -0
  342. package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
  343. package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
  344. package/src/client/public/default/apple-touch-icon.png +0 -0
  345. package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
  346. package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
  347. package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
  348. package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
  349. package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
  350. package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
  351. package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
  352. package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
  353. package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
  354. package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
  355. package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
  356. package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
  357. package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
  358. package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
  359. package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
  360. package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
  361. package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
  362. package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
  363. package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
  364. package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
  365. package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
  366. package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
  367. package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
  368. package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
  369. package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
  370. package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
  371. package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
  372. package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
  373. package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
  374. package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
  375. package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
  376. package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
  377. package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
  378. package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
  379. package/src/client/public/default/assets/background/dark.jpg +0 -0
  380. package/src/client/public/default/assets/background/dark.svg +557 -0
  381. package/src/client/public/default/assets/background/white.jpg +0 -0
  382. package/src/client/public/default/assets/background/white0-min.jpg +0 -0
  383. package/src/client/public/default/assets/background/white0.jpg +0 -0
  384. package/src/client/public/default/assets/logo/base-icon.png +0 -0
  385. package/src/client/public/default/assets/logo/underpost.gif +0 -0
  386. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  387. package/src/client/public/default/assets/mailer/api-user-default-avatar.png +0 -0
  388. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  389. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  390. package/src/client/public/default/browserconfig.xml +12 -0
  391. package/src/client/public/default/favicon-16x16.png +0 -0
  392. package/src/client/public/default/favicon-32x32.png +0 -0
  393. package/src/client/public/default/favicon-48x48.png +0 -0
  394. package/src/client/public/default/favicon.ico +0 -0
  395. package/src/client/public/default/manifest.webmanifest +69 -0
  396. package/src/client/public/default/mstile-144x144.png +0 -0
  397. package/src/client/public/default/mstile-150x150.png +0 -0
  398. package/src/client/public/default/mstile-310x150.png +0 -0
  399. package/src/client/public/default/mstile-310x310.png +0 -0
  400. package/src/client/public/default/mstile-70x70.png +0 -0
  401. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  402. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  403. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  404. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  405. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  406. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  407. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  408. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  409. package/src/client/public/default/safari-pinned-tab.svg +24 -0
  410. package/src/client/public/default/site.webmanifest +69 -0
  411. package/src/client/public/default/sitemap +148 -0
  412. package/src/client/public/default/yandex-browser-50x50.png +0 -0
  413. package/src/client/public/default/yandex-browser-manifest.json +9 -0
  414. package/src/client/public/doc/favicon.ico +0 -0
  415. package/src/client/public/doc/sitemap +148 -0
  416. package/src/client/public/test/favicon.ico +0 -0
  417. package/src/client/public/test/sitemap +148 -0
  418. package/src/client/services/blockchain/blockchain.service.js +73 -0
  419. package/src/client/services/core/core.service.js +165 -0
  420. package/src/client/services/crypto/crypto.service.js +73 -0
  421. package/src/client/services/default/default.management.js +450 -0
  422. package/src/client/services/default/default.service.js +98 -0
  423. package/src/client/services/document/document.service.js +97 -0
  424. package/src/client/services/file/file.service.js +72 -0
  425. package/src/client/services/instance/instance.management.js +78 -0
  426. package/src/client/services/instance/instance.service.js +97 -0
  427. package/src/client/services/ipfs/ipfs.service.js +73 -0
  428. package/src/client/services/object-layer/object-layer.service.js +93 -0
  429. package/src/client/services/test/test.service.js +73 -0
  430. package/src/client/services/user/user.management.js +56 -0
  431. package/src/client/services/user/user.service.js +108 -0
  432. package/src/client/ssr/Render.js +237 -0
  433. package/src/client/ssr/body/404.js +73 -0
  434. package/src/client/ssr/body/500.js +72 -0
  435. package/src/client/ssr/body/CacheControl.js +114 -0
  436. package/src/client/ssr/body/CyberiaDefaultSplashScreen.js +90 -0
  437. package/src/client/ssr/body/CyberiaSplashScreenLore.js +424 -0
  438. package/src/client/ssr/body/DefaultSplashScreen.js +90 -0
  439. package/src/client/ssr/email/DefaultRecoverEmail.js +21 -0
  440. package/src/client/ssr/email/DefaultVerifyEmail.js +17 -0
  441. package/src/client/ssr/head/Css.js +241 -0
  442. package/src/client/ssr/head/CyberiaAdminScripts.js +6 -0
  443. package/src/client/ssr/head/CyberiaPortalScripts.js +6 -0
  444. package/src/client/ssr/head/CyberiaScripts.js +6 -0
  445. package/src/client/ssr/head/DefaultScripts.js +6 -0
  446. package/src/client/ssr/head/Microdata.js +11 -0
  447. package/src/client/ssr/head/Production.js +1 -0
  448. package/src/client/ssr/head/Pwa.js +146 -0
  449. package/src/client/ssr/head/Seo.js +15 -0
  450. package/src/client/ssr/mailer/DefaultRecoverEmail.js +21 -0
  451. package/src/client/ssr/mailer/DefaultVerifyEmail.js +17 -0
  452. package/src/client/ssr/offline/Maintenance.js +63 -0
  453. package/src/client/ssr/offline/NoNetworkConnection.js +67 -0
  454. package/src/client/ssr/pages/404.js +12 -0
  455. package/src/client/ssr/pages/500.js +12 -0
  456. package/src/client/ssr/pages/Test.js +198 -0
  457. package/src/client/ssr/pages/maintenance.js +14 -0
  458. package/src/client/ssr/pages/offline.js +21 -0
  459. package/src/client/sw/default.sw.js +108 -0
  460. package/src/client/sw/template.sw.js +84 -0
  461. package/src/client.build.js +22 -0
  462. package/src/client.dev.js +24 -0
  463. package/src/db/DataBaseProvider.js +98 -0
  464. package/src/db/mariadb/MariaDB.js +66 -0
  465. package/src/db/mongo/MongooseDB.js +70 -0
  466. package/src/index.js +198 -0
  467. package/src/mailer/EmailRender.js +116 -0
  468. package/src/mailer/MailerProvider.js +213 -0
  469. package/src/monitor.js +24 -0
  470. package/src/proxy.js +22 -0
  471. package/src/runtime/express/Express.js +256 -0
  472. package/src/runtime/lampp/Dockerfile +50 -0
  473. package/src/runtime/lampp/Lampp.js +343 -0
  474. package/src/server/auth.js +689 -0
  475. package/src/server/backup.js +96 -0
  476. package/src/server/client-build-docs.js +205 -0
  477. package/src/server/client-build-live.js +109 -0
  478. package/src/server/client-build.js +690 -0
  479. package/src/server/client-dev-server.js +87 -0
  480. package/src/server/client-formatted.js +87 -0
  481. package/src/server/client-icons.js +108 -0
  482. package/src/server/conf.js +1071 -0
  483. package/src/server/crypto.js +210 -0
  484. package/src/server/dns.js +276 -0
  485. package/src/server/downloader.js +74 -0
  486. package/src/server/json-schema.js +77 -0
  487. package/src/server/logger.js +197 -0
  488. package/src/server/network.js +72 -0
  489. package/src/server/object-layer.js +294 -0
  490. package/src/server/peer.js +69 -0
  491. package/src/server/process.js +171 -0
  492. package/src/server/proxy.js +110 -0
  493. package/src/server/runtime.js +170 -0
  494. package/src/server/ssr.js +127 -0
  495. package/src/server/start.js +161 -0
  496. package/src/server/tls.js +251 -0
  497. package/src/server/valkey.js +293 -0
  498. package/src/server.js +25 -0
  499. package/src/ws/IoInterface.js +139 -0
  500. package/src/ws/IoServer.js +88 -0
  501. package/src/ws/core/channels/core.ws.chat.js +23 -0
  502. package/src/ws/core/channels/core.ws.mailer.js +35 -0
  503. package/src/ws/core/channels/core.ws.stream.js +31 -0
  504. package/src/ws/core/core.ws.connection.js +62 -0
  505. package/src/ws/core/core.ws.emit.js +53 -0
  506. package/src/ws/core/core.ws.server.js +76 -0
  507. package/src/ws/core/management/core.ws.chat.js +8 -0
  508. package/src/ws/core/management/core.ws.mailer.js +16 -0
  509. package/src/ws/core/management/core.ws.stream.js +8 -0
  510. package/src/ws/cyberia/channels/cyberia.ws.bot.js +56 -0
  511. package/src/ws/cyberia/channels/cyberia.ws.skill.js +51 -0
  512. package/src/ws/cyberia/channels/cyberia.ws.user.js +437 -0
  513. package/src/ws/cyberia/cyberia.ws.connection.js +36 -0
  514. package/src/ws/cyberia/cyberia.ws.emit.js +14 -0
  515. package/src/ws/cyberia/cyberia.ws.server.js +67 -0
  516. package/src/ws/cyberia/management/cyberia.ws.bot.js +669 -0
  517. package/src/ws/cyberia/management/cyberia.ws.skill.js +441 -0
  518. package/src/ws/cyberia/management/cyberia.ws.user.js +188 -0
  519. package/src/ws/default/channels/default.ws.main.js +16 -0
  520. package/src/ws/default/default.ws.connection.js +22 -0
  521. package/src/ws/default/default.ws.emit.js +14 -0
  522. package/src/ws/default/default.ws.server.js +20 -0
  523. package/src/ws/default/management/default.ws.main.js +8 -0
  524. package/test/api.test.js +53 -0
  525. package/test/crypto.test.js +117 -0
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Cluster module for managing Kubernetes cluster initialization, configuration, and component deployment.
3
+ * @module src/cli/cluster.js
4
+ * @namespace UnderpostCluster
5
+ */
6
+
7
+ import { getNpmRootPath } from '../server/conf.js';
8
+ import { loggerFactory } from '../server/logger.js';
9
+ import { shellExec } from '../server/process.js';
10
+ import UnderpostBaremetal from './baremetal.js';
11
+ import UnderpostDeploy from './deploy.js';
12
+ import UnderpostTest from './test.js';
13
+ import os from 'os';
14
+ import fs from 'fs-extra';
15
+
16
+ const logger = loggerFactory(import.meta);
17
+
18
+ /**
19
+ * @class UnderpostCluster
20
+ * @description Manages Kubernetes cluster initialization, configuration, and component deployment.
21
+ * This class provides a set of static methods to handle cluster initialization, configuration,
22
+ * and optional component deployments.
23
+ * @memberof UnderpostCluster
24
+ */
25
+ class UnderpostCluster {
26
+ static API = {
27
+ /**
28
+ * @method init
29
+ * @description Initializes and configures the Kubernetes cluster based on provided options.
30
+ * This method handles host prerequisites, cluster initialization (Kind, Kubeadm, or K3s),
31
+ * and optional component deployments.
32
+ * @param {string} [podName] - Optional name of a pod for specific operations (e.g., listing).
33
+ * @param {object} [options] - Configuration options for cluster initialization.
34
+ * @param {boolean} [options.mongodb=false] - Deploy MongoDB.
35
+ * @param {boolean} [options.mongodb4=false] - Deploy MongoDB 4.4.
36
+ * @param {String} [options.mongoDbHost=''] - Set custom mongo db host
37
+ * @param {boolean} [options.mariadb=false] - Deploy MariaDB.
38
+ * @param {boolean} [options.mysql=false] - Deploy MySQL.
39
+ * @param {boolean} [options.postgresql=false] - Deploy PostgreSQL.
40
+ * @param {boolean} [options.valkey=false] - Deploy Valkey.
41
+ * @param {boolean} [options.full=false] - Deploy a full set of common components.
42
+ * @param {boolean} [options.info=false] - Display extensive Kubernetes cluster information.
43
+ * @param {boolean} [options.certManager=false] - Deploy Cert-Manager for certificate management.
44
+ * @param {boolean} [options.listPods=false] - List Kubernetes pods.
45
+ * @param {boolean} [options.reset=false] - Perform a comprehensive reset of Kubernetes and container environments.
46
+ * @param {boolean} [options.dev=false] - Run in development mode (adjusts paths).
47
+ * @param {string} [options.nsUse=''] - Set the current kubectl namespace.
48
+ * @param {boolean} [options.infoCapacity=false] - Display resource capacity information for the cluster.
49
+ * @param {boolean} [options.infoCapacityPod=false] - Display resource capacity information for pods.
50
+ * @param {boolean} [options.pullImage=false] - Pull necessary Docker images before deployment.
51
+ * @param {boolean} [options.dedicatedGpu=false] - Configure for dedicated GPU usage (e.g., NVIDIA GPU Operator).
52
+ * @param {boolean} [options.kubeadm=false] - Initialize the cluster using Kubeadm.
53
+ * @param {boolean} [options.k3s=false] - Initialize the cluster using K3s.
54
+ * @param {boolean} [options.initHost=false] - Perform initial host setup (install Docker, Podman, Kind, Kubeadm, Helm).
55
+ * @param {boolean} [options.grafana=false] - Initialize the cluster with a Grafana deployment.
56
+ * @param {string} [options.prom=''] - Initialize the cluster with a Prometheus Operator deployment and monitor scrap for specified hosts.
57
+ * @param {boolean} [options.uninstallHost=false] - Uninstall all host components.
58
+ * @param {boolean} [options.config=false] - Apply general host configuration (SELinux, containerd, sysctl, firewalld).
59
+ * @param {boolean} [options.worker=false] - Configure as a worker node (for Kubeadm or K3s join).
60
+ * @param {boolean} [options.chown=false] - Set up kubectl configuration for the current user.
61
+ * @memberof UnderpostCluster
62
+ */
63
+ async init(
64
+ podName,
65
+ options = {
66
+ mongodb: false,
67
+ mongodb4: false,
68
+ mongoDbHost: '',
69
+ mariadb: false,
70
+ mysql: false,
71
+ postgresql: false,
72
+ valkey: false,
73
+ full: false,
74
+ info: false,
75
+ certManager: false,
76
+ listPods: false,
77
+ reset: false,
78
+ dev: false,
79
+ nsUse: '',
80
+ infoCapacity: false,
81
+ infoCapacityPod: false,
82
+ pullImage: false,
83
+ dedicatedGpu: false,
84
+ kubeadm: false,
85
+ k3s: false,
86
+ initHost: false,
87
+ grafana: false,
88
+ prom: '',
89
+ uninstallHost: false,
90
+ config: false,
91
+ worker: false,
92
+ chown: false,
93
+ },
94
+ ) {
95
+ // Handles initial host setup (installing docker, podman, kind, kubeadm, helm)
96
+ if (options.initHost === true) return UnderpostCluster.API.initHost();
97
+
98
+ // Handles initial host setup (installing docker, podman, kind, kubeadm, helm)
99
+ if (options.uninstallHost === true) return UnderpostCluster.API.uninstallHost();
100
+
101
+ // Applies general host configuration (SELinux, containerd, sysctl)
102
+ if (options.config === true) return UnderpostCluster.API.config();
103
+
104
+ // Sets up kubectl configuration for the current user
105
+ if (options.chown === true) return UnderpostCluster.API.chown();
106
+
107
+ const npmRoot = getNpmRootPath();
108
+ const underpostRoot = options?.dev === true ? '.' : `${npmRoot}/underpost`;
109
+
110
+ // Information gathering options
111
+ if (options.infoCapacityPod === true) return logger.info('', UnderpostDeploy.API.resourcesFactory());
112
+ if (options.infoCapacity === true)
113
+ return logger.info('', UnderpostCluster.API.getResourcesCapacity(options.kubeadm || options.k3s)); // Adjust for k3s
114
+ if (options.listPods === true) return console.table(UnderpostDeploy.API.get(podName ?? undefined));
115
+ if (options.nsUse && typeof options.nsUse === 'string') {
116
+ shellExec(`kubectl config set-context --current --namespace=${options.nsUse}`);
117
+ return;
118
+ }
119
+ if (options.info === true) {
120
+ shellExec(`kubectl config get-contexts`);
121
+ shellExec(`kubectl config get-clusters`);
122
+ shellExec(`kubectl get nodes -o wide`);
123
+ shellExec(`kubectl config view | grep namespace`);
124
+ shellExec(`kubectl get ns -o wide`);
125
+ shellExec(`kubectl get pvc --all-namespaces -o wide`);
126
+ shellExec(`kubectl get pv --all-namespaces -o wide`);
127
+ shellExec(`kubectl get cronjob --all-namespaces -o wide`);
128
+ shellExec(`kubectl get svc --all-namespaces -o wide`);
129
+ shellExec(`kubectl get statefulsets --all-namespaces -o wide`);
130
+ shellExec(`kubectl get deployments --all-namespaces -o wide`);
131
+ shellExec(`kubectl get configmap --all-namespaces -o wide`);
132
+ shellExec(`kubectl get pods --all-namespaces -o wide`);
133
+ shellExec(
134
+ `kubectl get pod --all-namespaces -o="custom-columns=NAME:.metadata.name,INIT-CONTAINERS:.spec.initContainers[*].name,CONTAINERS:.spec.containers[*].name"`,
135
+ );
136
+ shellExec(
137
+ `kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\\n"}{.metadata.name}{":\\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'`,
138
+ );
139
+ shellExec(`sudo crictl images`);
140
+ console.log();
141
+ logger.info('contour -------------------------------------------------');
142
+ for (const _k of ['Cluster', 'HTTPProxy', 'ClusterIssuer', 'Certificate']) {
143
+ shellExec(`kubectl get ${_k} --all-namespaces -o wide`);
144
+ }
145
+ logger.info('----------------------------------------------------------------');
146
+ shellExec(`kubectl get secrets --all-namespaces -o wide`);
147
+ shellExec(`docker secret ls`);
148
+ shellExec(`kubectl get crd --all-namespaces -o wide`);
149
+ shellExec(`sudo kubectl api-resources`);
150
+ return;
151
+ }
152
+
153
+ // Reset Kubernetes cluster components (Kind/Kubeadm/K3s) and container runtimes
154
+ if (options.reset === true) return await UnderpostCluster.API.safeReset({ underpostRoot });
155
+
156
+ // Check if a cluster (Kind, Kubeadm, or K3s) is already initialized
157
+ const alreadyKubeadmCluster = UnderpostDeploy.API.get('calico-kube-controllers')[0];
158
+ const alreadyKindCluster = UnderpostDeploy.API.get('kube-apiserver-kind-control-plane')[0];
159
+ // K3s pods often contain 'svclb-traefik' in the kube-system namespace
160
+ const alreadyK3sCluster = UnderpostDeploy.API.get('svclb-traefik')[0];
161
+
162
+ // --- Kubeadm/Kind/K3s Cluster Initialization ---
163
+ // This block handles the initial setup of the Kubernetes cluster (control plane or worker).
164
+ // It prevents re-initialization if a cluster is already detected.
165
+ if (!options.worker && !alreadyKubeadmCluster && !alreadyKindCluster && !alreadyK3sCluster) {
166
+ UnderpostCluster.API.config();
167
+ if (options.k3s === true) {
168
+ logger.info('Initializing K3s control plane...');
169
+ // Install K3s
170
+ console.log('Installing K3s...');
171
+ shellExec(`curl -sfL https://get.k3s.io | sh -`);
172
+ console.log('K3s installation completed.');
173
+
174
+ // Move k3s binary to /bin/k3s and make it executable
175
+ shellExec(`sudo mv /usr/local/bin/k3s /bin/k3s`);
176
+ shellExec(`sudo chmod +x /bin/k3s`);
177
+ console.log('K3s binary moved to /bin/k3s and made executable.');
178
+
179
+ // Configure kubectl for the current user for K3s *before* checking readiness
180
+ // This ensures kubectl can find the K3s kubeconfig immediately after K3s installation.
181
+ UnderpostCluster.API.chown('k3s');
182
+
183
+ // Wait for K3s to be ready
184
+ logger.info('Waiting for K3s to be ready...');
185
+ let k3sReady = false;
186
+ let retries = 0;
187
+ const maxRetries = 20; // Increased retries for K3s startup
188
+ const delayMs = 5000; // 5 seconds
189
+
190
+ while (!k3sReady && retries < maxRetries) {
191
+ try {
192
+ // Explicitly use KUBECONFIG for kubectl commands to ensure it points to K3s config
193
+ const nodes = shellExec(`KUBECONFIG=/etc/rancher/k3s/k3s.yaml kubectl get nodes -o json`, {
194
+ stdout: true,
195
+ silent: true,
196
+ });
197
+ const parsedNodes = JSON.parse(nodes);
198
+ if (
199
+ parsedNodes.items.some((node) =>
200
+ node.status.conditions.some((cond) => cond.type === 'Ready' && cond.status === 'True'),
201
+ )
202
+ ) {
203
+ k3sReady = true;
204
+ logger.info('K3s cluster is ready.');
205
+ } else {
206
+ logger.info(`K3s not yet ready. Retrying in ${delayMs / 1000} seconds...`);
207
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
208
+ }
209
+ } catch (error) {
210
+ logger.info(`Error checking K3s status: ${error.message}. Retrying in ${delayMs / 1000} seconds...`);
211
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
212
+ }
213
+ retries++;
214
+ }
215
+
216
+ if (!k3sReady) {
217
+ logger.error('K3s cluster did not become ready in time. Please check the K3s logs.');
218
+ return;
219
+ }
220
+
221
+ // K3s includes local-path-provisioner by default, so no need to install explicitly.
222
+ logger.info('K3s comes with local-path-provisioner by default. Skipping explicit installation.');
223
+ } else if (options.kubeadm === true) {
224
+ logger.info('Initializing Kubeadm control plane...');
225
+ // Initialize kubeadm control plane
226
+ shellExec(
227
+ `sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --control-plane-endpoint="${os.hostname()}:6443"`,
228
+ );
229
+ // Configure kubectl for the current user
230
+ UnderpostCluster.API.chown('kubeadm'); // Pass 'kubeadm' to chown
231
+
232
+ // Install Calico CNI
233
+ logger.info('Installing Calico CNI...');
234
+ shellExec(
235
+ `sudo kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.3/manifests/tigera-operator.yaml`,
236
+ );
237
+ shellExec(`sudo kubectl apply -f ${underpostRoot}/manifests/kubeadm-calico-config.yaml`);
238
+ // Untaint control plane node to allow scheduling pods
239
+ const nodeName = os.hostname();
240
+ shellExec(`kubectl taint nodes ${nodeName} node-role.kubernetes.io/control-plane:NoSchedule-`);
241
+ // Install local-path-provisioner for dynamic PVCs (optional but recommended)
242
+ logger.info('Installing local-path-provisioner...');
243
+ shellExec(
244
+ `kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml`,
245
+ );
246
+ } else {
247
+ // Kind cluster initialization (if not using kubeadm or k3s)
248
+ logger.info('Initializing Kind cluster...');
249
+ if (options.full === true || options.dedicatedGpu === true) {
250
+ shellExec(`cd ${underpostRoot}/manifests && kind create cluster --config kind-config-cuda.yaml`);
251
+ } else {
252
+ shellExec(
253
+ `cd ${underpostRoot}/manifests && kind create cluster --config kind-config${
254
+ options?.dev === true ? '-dev' : ''
255
+ }.yaml`,
256
+ );
257
+ }
258
+ UnderpostCluster.API.chown('kind'); // Pass 'kind' to chown
259
+ }
260
+ } else if (options.worker === true) {
261
+ // Worker node specific configuration (kubeadm join command needs to be executed separately)
262
+ logger.info('Worker node configuration applied. Awaiting join command...');
263
+ // No direct cluster initialization here for workers. The `kubeadm join` or `k3s agent` command
264
+ // needs to be run on the worker after the control plane is up and a token is created.
265
+ // This part of the script is for general worker setup, not the join itself.
266
+ } else {
267
+ logger.warn('Cluster already initialized or worker flag not set for worker node.');
268
+ }
269
+
270
+ // --- Optional Component Deployments (Databases, Ingress, Cert-Manager) ---
271
+ // These deployments happen after the base cluster is up.
272
+
273
+ if (options.full === true || options.dedicatedGpu === true) {
274
+ shellExec(`node ${underpostRoot}/bin/deploy nvidia-gpu-operator`);
275
+ shellExec(
276
+ `node ${underpostRoot}/bin/deploy kubeflow-spark-operator${options.kubeadm === true ? ' kubeadm' : ''}`,
277
+ );
278
+ }
279
+
280
+ if (options.grafana === true) {
281
+ shellExec(`kubectl delete deployment grafana --ignore-not-found`);
282
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/grafana`);
283
+ }
284
+
285
+ if (options.prom && typeof options.prom === 'string') {
286
+ shellExec(`kubectl delete deployment prometheus --ignore-not-found`);
287
+ shellExec(`kubectl delete configmap prometheus-config --ignore-not-found`);
288
+ shellExec(`kubectl delete service prometheus --ignore-not-found`);
289
+ // Prometheus server host: http://<prometheus-cluster-ip>:9090
290
+ const yaml = `${fs.readFileSync(`${underpostRoot}/manifests/prometheus/deployment.yaml`, 'utf8').replace(
291
+ '- targets: []',
292
+ `- targets: [${options.prom
293
+ .split(',')
294
+ .map((host) => `'${host}'`)
295
+ .join(',')}]`,
296
+ )}`;
297
+ console.log(yaml);
298
+ shellExec(`kubectl apply -f - <<EOF
299
+ ${yaml}
300
+ EOF
301
+ `);
302
+
303
+ // https://grafana.com/docs/grafana-cloud/monitor-infrastructure/kubernetes-monitoring/configuration/config-other-methods/prometheus/prometheus-operator/
304
+ // shellExec(
305
+ // `kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/bundle.yaml`,
306
+ // );
307
+ // shellExec(`kubectl apply -f ${underpostRoot}/manifests/prometheus/prometheus-cr.yaml`);
308
+ // shellExec(`kubectl rollout status sts prometheus-prometheus -n default`);
309
+ // shellExec(`kubectl apply -f ${underpostRoot}/manifests/prometheus/prometheus-server.yaml`);
310
+ // shellExec(`helm repo add prometheus-community https://prometheus-community.github.io/helm-charts`);
311
+ // shellExec(`helm repo update`);
312
+ // shellExec(`helm install prometheus prometheus-community/prometheus`);
313
+ // shellExec(`kubectl rollout status deployment prometheus-server -n default`);
314
+ }
315
+
316
+ if (options.full === true || options.valkey === true) {
317
+ if (options.pullImage === true) {
318
+ // shellExec(`sudo podman pull valkey/valkey:latest`);
319
+ if (!options.kubeadm && !options.k3s) {
320
+ // Only load if not kubeadm/k3s (Kind needs it)
321
+ shellExec(`docker pull valkey/valkey:latest`);
322
+ shellExec(`sudo kind load docker-image valkey/valkey:latest`);
323
+ } else if (options.kubeadm || options.k3s)
324
+ // For kubeadm/k3s, ensure it's available for containerd
325
+ shellExec(`sudo crictl pull valkey/valkey:latest`);
326
+ }
327
+ shellExec(`kubectl delete statefulset valkey-service --ignore-not-found`);
328
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/valkey`);
329
+ await UnderpostTest.API.statusMonitor('valkey-service', 'Running', 'pods', 1000, 60);
330
+ }
331
+ if (options.full === true || options.mariadb === true) {
332
+ shellExec(
333
+ `sudo kubectl create secret generic mariadb-secret --from-file=username=/home/dd/engine/engine-private/mariadb-username --from-file=password=/home/dd/engine/engine-private/mariadb-password --dry-run=client -o yaml | kubectl apply -f -`,
334
+ );
335
+ shellExec(`kubectl delete statefulset mariadb-statefulset --ignore-not-found`);
336
+
337
+ if (options.pullImage === true) {
338
+ // shellExec(`sudo podman pull mariadb:latest`);
339
+ if (!options.kubeadm && !options.k3s) {
340
+ // Only load if not kubeadm/k3s (Kind needs it)
341
+ shellExec(`docker pull mariadb:latest`);
342
+ shellExec(`sudo kind load docker-image mariadb:latest`);
343
+ } else if (options.kubeadm || options.k3s)
344
+ // For kubeadm/k3s, ensure it's available for containerd
345
+ shellExec(`sudo crictl pull mariadb:latest`);
346
+ }
347
+ shellExec(`kubectl apply -f ${underpostRoot}/manifests/mariadb/storage-class.yaml`);
348
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/mariadb`);
349
+ }
350
+ if (options.full === true || options.mysql === true) {
351
+ shellExec(
352
+ `sudo kubectl create secret generic mysql-secret --from-file=username=/home/dd/engine/engine-private/mysql-username --from-file=password=/home/dd/engine/engine-private/mysql-password --dry-run=client -o yaml | kubectl apply -f -`,
353
+ );
354
+ shellExec(`sudo mkdir -p /mnt/data`);
355
+ shellExec(`sudo chmod 777 /mnt/data`);
356
+ shellExec(`sudo chown -R root:root /mnt/data`);
357
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/mysql`);
358
+ }
359
+ if (options.full === true || options.postgresql === true) {
360
+ if (options.pullImage === true) {
361
+ if (!options.kubeadm && !options.k3s) {
362
+ // Only load if not kubeadm/k3s (Kind needs it)
363
+ shellExec(`docker pull postgres:latest`);
364
+ shellExec(`sudo kind load docker-image postgres:latest`);
365
+ } else if (options.kubeadm || options.k3s)
366
+ // For kubeadm/k3s, ensure it's available for containerd
367
+ shellExec(`sudo crictl pull postgres:latest`);
368
+ }
369
+ shellExec(
370
+ `sudo kubectl create secret generic postgres-secret --from-file=password=/home/dd/engine/engine-private/postgresql-password --dry-run=client -o yaml | kubectl apply -f -`,
371
+ );
372
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/postgresql`);
373
+ }
374
+ if (options.mongodb4 === true) {
375
+ if (options.pullImage === true) {
376
+ if (!options.kubeadm && !options.k3s) {
377
+ // Only load if not kubeadm/k3s (Kind needs it)
378
+ shellExec(`docker pull mongo:4.4`);
379
+ shellExec(`sudo kind load docker-image mongo:4.4`);
380
+ } else if (options.kubeadm || options.k3s)
381
+ // For kubeadm/k3s, ensure it's available for containerd
382
+ shellExec(`sudo crictl pull mongo:4.4`);
383
+ }
384
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/mongodb-4.4`);
385
+
386
+ const deploymentName = 'mongodb-deployment';
387
+
388
+ const successInstance = await UnderpostTest.API.statusMonitor(deploymentName);
389
+
390
+ if (successInstance) {
391
+ if (!options.mongoDbHost) options.mongoDbHost = 'mongodb-service';
392
+ const mongoConfig = {
393
+ _id: 'rs0',
394
+ members: [{ _id: 0, host: `${options.mongoDbHost}:27017` }],
395
+ };
396
+
397
+ const [pod] = UnderpostDeploy.API.get(deploymentName);
398
+
399
+ shellExec(
400
+ `sudo kubectl exec -i ${pod.NAME} -- mongo --quiet \
401
+ --eval 'rs.initiate(${JSON.stringify(mongoConfig)})'`,
402
+ );
403
+ }
404
+ } else if (options.full === true || options.mongodb === true) {
405
+ if (options.pullImage === true) {
406
+ if (!options.kubeadm && !options.k3s) {
407
+ // Only load if not kubeadm/k3s (Kind needs it)
408
+ shellExec(`docker pull mongo:latest`);
409
+ shellExec(`sudo kind load docker-image mongo:latest`);
410
+ } else if (options.kubeadm || options.k3s)
411
+ // For kubeadm/k3s, ensure it's available for containerd
412
+ shellExec(`sudo crictl pull mongo:latest`);
413
+ }
414
+ shellExec(
415
+ `sudo kubectl create secret generic mongodb-keyfile --from-file=/home/dd/engine/engine-private/mongodb-keyfile --dry-run=client -o yaml | kubectl apply -f -`,
416
+ );
417
+ shellExec(
418
+ `sudo kubectl create secret generic mongodb-secret --from-file=username=/home/dd/engine/engine-private/mongodb-username --from-file=password=/home/dd/engine/engine-private/mongodb-password --dry-run=client -o yaml | kubectl apply -f -`,
419
+ );
420
+ shellExec(`kubectl delete statefulset mongodb --ignore-not-found`);
421
+ shellExec(`kubectl apply -f ${underpostRoot}/manifests/mongodb/storage-class.yaml`);
422
+ shellExec(`kubectl apply -k ${underpostRoot}/manifests/mongodb`);
423
+
424
+ const successInstance = await UnderpostTest.API.statusMonitor('mongodb-0', 'Running', 'pods', 1000, 60 * 10);
425
+
426
+ if (successInstance) {
427
+ if (!options.mongoDbHost) options.mongoDbHost = 'mongodb-0.mongodb-service';
428
+ const mongoConfig = {
429
+ _id: 'rs0',
430
+ members: options.mongoDbHost.split(',').map((host, index) => ({ _id: index, host: `${host}:27017` })),
431
+ };
432
+
433
+ shellExec(
434
+ `sudo kubectl exec -i mongodb-0 -- mongosh --quiet --json=relaxed \
435
+ --eval 'use admin' \
436
+ --eval 'rs.initiate(${JSON.stringify(mongoConfig)})' \
437
+ --eval 'rs.status()'`,
438
+ );
439
+ }
440
+ }
441
+
442
+ if (options.full === true || options.contour === true) {
443
+ shellExec(`kubectl apply -f https://projectcontour.io/quickstart/contour.yaml`);
444
+ if (options.kubeadm === true) {
445
+ // Envoy service might need NodePort for kubeadm
446
+ shellExec(`sudo kubectl apply -f ${underpostRoot}/manifests/envoy-service-nodeport.yaml`);
447
+ }
448
+ // K3s has a built-in LoadBalancer (Klipper-lb) that can expose services,
449
+ // so a specific NodePort service might not be needed or can be configured differently.
450
+ }
451
+
452
+ if (options.full === true || options.certManager === true) {
453
+ if (!UnderpostDeploy.API.get('cert-manager').find((p) => p.STATUS === 'Running')) {
454
+ shellExec(`helm repo add jetstack https://charts.jetstack.io --force-update`);
455
+ shellExec(
456
+ `helm install cert-manager jetstack/cert-manager \
457
+ --namespace cert-manager \
458
+ --create-namespace \
459
+ --version v1.17.0 \
460
+ --set crds.enabled=true`,
461
+ );
462
+ }
463
+
464
+ const letsEncName = 'letsencrypt-prod';
465
+ shellExec(`sudo kubectl delete ClusterIssuer ${letsEncName} --ignore-not-found`);
466
+ shellExec(`sudo kubectl apply -f ${underpostRoot}/manifests/${letsEncName}.yaml`);
467
+ }
468
+ },
469
+
470
+ /**
471
+ * @method config
472
+ * @description Configures host-level settings required for Kubernetes.
473
+ * This method ensures proper SELinux, Docker, Containerd, and Sysctl settings
474
+ * are applied for a healthy Kubernetes environment. It explicitly avoids
475
+ * iptables flushing commands to prevent conflicts with Kubernetes' own network management.
476
+ * @param {string} underpostRoot - The root directory of the underpost project.
477
+ * @memberof UnderpostCluster
478
+ */
479
+ config(options = { underpostRoot: '.' }) {
480
+ const { underpostRoot } = options;
481
+ console.log('Applying host configuration: SELinux, Docker, Containerd, and Sysctl settings.');
482
+ // Disable SELinux (permissive mode)
483
+ shellExec(`sudo setenforce 0`);
484
+ shellExec(`sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config`);
485
+
486
+ // Enable and start Docker and Kubelet services
487
+ shellExec(`sudo systemctl enable --now docker || true`); // Docker might not be needed for K3s
488
+ shellExec(`sudo systemctl enable --now kubelet || true`); // Kubelet might not be needed for K3s (K3s uses its own agent)
489
+
490
+ // Configure containerd for SystemdCgroup and explicitly disable SELinux
491
+ // This is crucial for kubelet/k3s to interact correctly with containerd
492
+ shellExec(`containerd config default | sudo tee /etc/containerd/config.toml > /dev/null`);
493
+ shellExec(`sudo sed -i -e "s/SystemdCgroup = false/SystemdCgroup = true/g" /etc/containerd/config.toml`);
494
+ // Add a new line to disable SELinux for the runc runtime
495
+ // shellExec(
496
+ // `sudo sed -i '/SystemdCgroup = true/a selinux_disabled = true' /etc/containerd/config.toml || true`,
497
+ // );
498
+ shellExec(`sudo service docker restart || true`); // Restart docker after containerd config changes
499
+ shellExec(`sudo systemctl enable --now containerd.service`);
500
+ shellExec(`sudo systemctl restart containerd`); // Restart containerd to apply changes
501
+
502
+ // Disable swap (required by Kubernetes)
503
+ shellExec(`sudo swapoff -a; sudo sed -i '/swap/d' /etc/fstab`);
504
+
505
+ // Reload systemd daemon to pick up new unit files/changes
506
+ shellExec(`sudo systemctl daemon-reload`);
507
+
508
+ // Enable bridge-nf-call-iptables for Kubernetes networking
509
+ // This ensures traffic through Linux bridges is processed by iptables (crucial for CNI)
510
+ for (const iptableConfPath of [
511
+ `/etc/sysctl.d/k8s.conf`,
512
+ `/etc/sysctl.d/99-k8s-ipforward.conf`,
513
+ `/etc/sysctl.d/99-k8s.conf`,
514
+ ])
515
+ shellExec(
516
+ `echo 'net.bridge.bridge-nf-call-iptables = 1
517
+ net.bridge.bridge-nf-call-ip6tables = 1
518
+ net.bridge.bridge-nf-call-arptables = 1
519
+ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
520
+ { silent: true },
521
+ );
522
+
523
+ // Increase inotify limits
524
+ shellExec(`sudo sysctl -w fs.inotify.max_user_watches=2099999999`);
525
+ shellExec(`sudo sysctl -w fs.inotify.max_user_instances=2099999999`);
526
+ shellExec(`sudo sysctl -w fs.inotify.max_queued_events=2099999999`);
527
+
528
+ // shellExec(`sudo sysctl --system`); // Apply sysctl changes immediately
529
+ // Apply NAT iptables rules.
530
+ shellExec(`${underpostRoot}/scripts/nat-iptables.sh`, { silent: true });
531
+
532
+ // Disable firewalld (common cause of network issues in Kubernetes)
533
+ shellExec(`sudo systemctl stop firewalld || true`); // Stop if running
534
+ shellExec(`sudo systemctl disable firewalld || true`); // Disable from starting on boot
535
+ },
536
+
537
+ /**
538
+ * @method chown
539
+ * @description Sets up kubectl configuration for the current user based on the cluster type.
540
+ * @param {string} clusterType - The type of Kubernetes cluster ('kubeadm', 'k3s', or 'kind').
541
+ * @memberof UnderpostCluster
542
+ */
543
+ chown(clusterType) {
544
+ console.log(`Setting up kubectl configuration for ${clusterType} cluster...`);
545
+ shellExec(`mkdir -p ~/.kube`);
546
+
547
+ let kubeconfigPath;
548
+ if (clusterType === 'k3s') {
549
+ kubeconfigPath = '/etc/rancher/k3s/k3s.yaml';
550
+ } else if (clusterType === 'kubeadm') {
551
+ kubeconfigPath = '/etc/kubernetes/admin.conf';
552
+ } else {
553
+ // Default to kind if not specified or unknown
554
+ kubeconfigPath = ''; // Kind's kubeconfig is usually managed by kind itself, or merged
555
+ }
556
+
557
+ if (kubeconfigPath) {
558
+ shellExec(`sudo -E cp -i ${kubeconfigPath} ~/.kube/config`);
559
+ shellExec(`sudo -E chown $(id -u):$(id -g) ~/.kube/config`);
560
+ } else if (clusterType === 'kind') {
561
+ // For Kind, the kubeconfig is usually merged automatically or can be explicitly exported
562
+ // This command ensures it's merged into the default kubeconfig
563
+ shellExec(`kind get kubeconfig > ~/.kube/config || true`);
564
+ shellExec(`sudo -E chown $(id -u):$(id -g) ~/.kube/config`);
565
+ } else {
566
+ logger.warn('No specific kubeconfig path defined for this cluster type, or it is managed automatically.');
567
+ }
568
+ console.log('kubectl config set up successfully.');
569
+ },
570
+
571
+ /**
572
+ * @method safeReset
573
+ * @description Performs a complete reset of the Kubernetes cluster and its container environments.
574
+ * This version focuses on correcting persistent permission errors (such as 'permission denied'
575
+ * in coredns) by restoring SELinux security contexts and safely cleaning up cluster artifacts.
576
+ * @param {object} [options] - Configuration options for the reset.
577
+ * @param {string} [options.underpostRoot] - The root path of the underpost project.
578
+ * @memberof UnderpostCluster
579
+ */
580
+ async safeReset(options = { underpostRoot: '.' }) {
581
+ logger.info('Starting a safe and comprehensive reset of Kubernetes and container environments...');
582
+
583
+ try {
584
+ // Phase 0: Truncate large logs under /var/log to free up immediate space
585
+ logger.info('Phase 0/7: Truncating large log files under /var/log...');
586
+ try {
587
+ const cleanPath = `/var/log/`;
588
+ const largeLogsFiles = shellExec(
589
+ `sudo du -sh ${cleanPath}* | awk '{if ($1 ~ /G$/ && ($1+0) > 1) print}' | sort -rh`,
590
+ {
591
+ stdout: true,
592
+ },
593
+ );
594
+ for (const pathLog of largeLogsFiles
595
+ .split(`\n`)
596
+ .map((p) => p.split(cleanPath)[1])
597
+ .filter((p) => p)) {
598
+ shellExec(`sudo rm -rf ${cleanPath}${pathLog}`);
599
+ }
600
+ } catch (err) {
601
+ logger.warn(` -> Error truncating log files: ${err.message}. Continuing with reset.`);
602
+ }
603
+
604
+ // Phase 1: Clean up Persistent Volumes with hostPath
605
+ // This targets data created by Kubernetes Persistent Volumes that use hostPath.
606
+ logger.info('Phase 1/7: Cleaning Kubernetes hostPath volumes...');
607
+ try {
608
+ const pvListJson = shellExec(`kubectl get pv -o json || echo '{"items":[]}'`, { stdout: true, silent: true });
609
+ const pvList = JSON.parse(pvListJson);
610
+
611
+ if (pvList.items && pvList.items.length > 0) {
612
+ for (const pv of pvList.items) {
613
+ // Check if the PV uses hostPath and delete its contents
614
+ if (pv.spec.hostPath && pv.spec.hostPath.path) {
615
+ const hostPath = pv.spec.hostPath.path;
616
+ logger.info(`Removing data from host path for PV '${pv.metadata.name}': ${hostPath}`);
617
+ shellExec(`sudo rm -rf ${hostPath}/* || true`);
618
+ }
619
+ }
620
+ } else {
621
+ logger.info('No Persistent Volumes found with hostPath to clean up.');
622
+ }
623
+ } catch (error) {
624
+ logger.error('Failed to clean up Persistent Volumes:', error);
625
+ }
626
+ // Phase 2: Restore SELinux and stop services
627
+ // This is critical for fixing the 'permission denied' error you experienced.
628
+ // Enable SELinux permissive mode and restore file contexts.
629
+ logger.info('Phase 2/7: Stopping services and fixing SELinux...');
630
+ logger.info(' -> Ensuring SELinux is in permissive mode...');
631
+ shellExec(`sudo setenforce 0 || true`);
632
+ shellExec(`sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config || true`);
633
+ logger.info(' -> Restoring SELinux contexts for container data directories...');
634
+ // The 'restorecon' command corrects file system security contexts.
635
+ shellExec(`sudo restorecon -Rv /var/lib/containerd || true`);
636
+ shellExec(`sudo restorecon -Rv /var/lib/kubelet || true`);
637
+
638
+ logger.info(' -> Stopping kubelet, docker, and podman services...');
639
+ shellExec('sudo systemctl stop kubelet || true');
640
+ shellExec('sudo systemctl stop docker || true');
641
+ shellExec('sudo systemctl stop podman || true');
642
+ // Safely unmount pod filesystems to avoid errors.
643
+ shellExec('sudo umount -f /var/lib/kubelet/pods/*/* || true');
644
+
645
+ // Phase 3: Execute official uninstallation commands
646
+ logger.info('Phase 3/7: Executing official reset and uninstallation commands...');
647
+ logger.info(' -> Executing kubeadm reset...');
648
+ shellExec('sudo kubeadm reset --force || true');
649
+ logger.info(' -> Executing K3s uninstallation script if it exists...');
650
+ shellExec('sudo /usr/local/bin/k3s-uninstall.sh || true');
651
+ logger.info(' -> Deleting Kind clusters...');
652
+ shellExec('kind get clusters | xargs -r -t -n1 kind delete cluster || true');
653
+
654
+ // Phase 4: File system cleanup
655
+ logger.info('Phase 4/7: Cleaning up remaining file system artifacts...');
656
+ // Remove any leftover configurations and data.
657
+ shellExec('sudo rm -rf /etc/kubernetes/* || true');
658
+ shellExec('sudo rm -rf /etc/cni/net.d/* || true');
659
+ shellExec('sudo rm -rf /var/lib/kubelet/* || true');
660
+ shellExec('sudo rm -rf /var/lib/cni/* || true');
661
+ shellExec('sudo rm -rf /var/lib/docker/* || true');
662
+ shellExec('sudo rm -rf /var/lib/containerd/* || true');
663
+ shellExec('sudo rm -rf /var/lib/containers/storage/* || true');
664
+ // Clean up the current user's kubeconfig.
665
+ shellExec('rm -rf $HOME/.kube || true');
666
+
667
+ // Phase 5: Host network cleanup
668
+ logger.info('Phase 5/7: Cleaning up host network configurations...');
669
+ // Remove iptables rules and CNI network interfaces.
670
+ shellExec('sudo iptables -F || true');
671
+ shellExec('sudo iptables -t nat -F || true');
672
+ // Restore iptables rules
673
+ shellExec(`chmod +x ${options.underpostRoot}/scripts/nat-iptables.sh`);
674
+ shellExec(`${options.underpostRoot}/scripts/nat-iptables.sh`, { silent: true });
675
+ shellExec('sudo ip link del cni0 || true');
676
+ shellExec('sudo ip link del flannel.1 || true');
677
+
678
+ logger.info('Phase 6/7: Clean up images');
679
+ shellExec(`podman rmi $(podman images -qa) --force`);
680
+
681
+ // Phase 6: Reload daemon and finalize
682
+ logger.info('Phase 7/7: Reloading the system daemon and finalizing...');
683
+ // shellExec('sudo systemctl daemon-reload');
684
+ UnderpostCluster.API.config();
685
+ logger.info('Safe and complete reset finished. The system is ready for a new cluster initialization.');
686
+ } catch (error) {
687
+ logger.error(`Error during reset: ${error.message}`);
688
+ console.error(error);
689
+ }
690
+ },
691
+
692
+ /**
693
+ * @method getResourcesCapacity
694
+ * @description Retrieves the capacity of resources (CPU and memory) for a specific node in the cluster.
695
+ * @param {string} [node=os.hostname()] - The node to query. Defaults to the current host.
696
+ * @returns {object} An object containing the CPU and memory capacity of the node.
697
+ * @memberof UnderpostCluster
698
+ */
699
+ getResourcesCapacity(node) {
700
+ const resources = {};
701
+ const nodeName = node ?? os.hostname();
702
+ const info = shellExec(`kubectl describe node ${nodeName} | grep -E '(Allocatable:|Capacity:)' -A 6`, {
703
+ stdout: true,
704
+ silent: true,
705
+ });
706
+ info
707
+ .split('Allocatable:')[1]
708
+ .split('\n')
709
+ .filter((row) => row.match('cpu') || row.match('memory'))
710
+ .map((row) => {
711
+ if (row.match('cpu'))
712
+ resources.cpu = {
713
+ value: parseInt(row.split(':')[1].trim()) * 1000,
714
+ unit: 'm',
715
+ };
716
+ if (row.match('memory'))
717
+ resources.memory = {
718
+ value: parseInt(row.split(':')[1].split('Ki')[0].trim()),
719
+ unit: 'Ki',
720
+ };
721
+ });
722
+
723
+ return resources;
724
+ },
725
+
726
+ /**
727
+ * @method initHost
728
+ * @description Installs essential host-level prerequisites for Kubernetes (Docker, Podman, Kind, Kubeadm, Helm).
729
+ * @memberof UnderpostCluster
730
+ */
731
+ initHost() {
732
+ const archData = UnderpostBaremetal.API.getHostArch();
733
+ logger.info('Installing essential host-level prerequisites for Kubernetes...', archData);
734
+ // Install Docker and its dependencies
735
+ shellExec(`sudo dnf -y install dnf-plugins-core dbus-x11`);
736
+ shellExec(`sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo`);
737
+ shellExec(`sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin`);
738
+
739
+ // Install Podman
740
+ shellExec(`sudo dnf -y install podman`);
741
+
742
+ // Install Kind (Kubernetes in Docker)
743
+ shellExec(`[ $(uname -m) = ${archData.name} ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-${archData.alias}
744
+ chmod +x ./kind
745
+ sudo mv ./kind /bin/kind`);
746
+ // Install Kubernetes tools: Kubeadm, Kubelet, and Kubectl
747
+ shellExec(`cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
748
+ [kubernetes]
749
+ name=Kubernetes
750
+ baseurl=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/
751
+ enabled=1
752
+ gpgcheck=1
753
+ gpgkey=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key
754
+ exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
755
+ EOF`);
756
+ shellExec(`sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes`);
757
+
758
+ // Install Helm
759
+ shellExec(`curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3`);
760
+ shellExec(`chmod 700 get_helm.sh`);
761
+ shellExec(`./get_helm.sh`);
762
+ shellExec(`chmod +x /usr/local/bin/helm`);
763
+ shellExec(`sudo mv /usr/local/bin/helm /bin/helm`);
764
+ shellExec(`sudo rm -rf get_helm.sh`);
765
+ console.log('Host prerequisites installed successfully.');
766
+ },
767
+
768
+ /**
769
+ * @method uninstallHost
770
+ * @description Uninstalls all host components installed by initHost.
771
+ * This includes Docker, Podman, Kind, Kubeadm, Kubelet, Kubectl, and Helm.
772
+ * @memberof UnderpostCluster
773
+ */
774
+ uninstallHost() {
775
+ console.log('Uninstalling host components: Docker, Podman, Kind, Kubeadm, Kubelet, Kubectl, Helm.');
776
+
777
+ // Remove Kind
778
+ console.log('Removing Kind...');
779
+ shellExec(`sudo rm -f /bin/kind || true`);
780
+
781
+ // Remove Helm
782
+ console.log('Removing Helm...');
783
+ shellExec(`sudo rm -f /usr/local/bin/helm || true`);
784
+ shellExec(`sudo rm -f /usr/local/bin/helm.sh || true`); // clean up the install script if it exists
785
+
786
+ // Remove Docker and its dependencies
787
+ console.log('Removing Docker, containerd, and related packages...');
788
+ shellExec(
789
+ `sudo dnf -y remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || true`,
790
+ );
791
+
792
+ // Remove Podman
793
+ console.log('Removing Podman...');
794
+ shellExec(`sudo dnf -y remove podman || true`);
795
+
796
+ // Remove Kubeadm, Kubelet, and Kubectl
797
+ console.log('Removing Kubernetes tools...');
798
+ shellExec(`sudo yum remove -y kubelet kubeadm kubectl || true`);
799
+
800
+ // Remove Kubernetes repo file
801
+ console.log('Removing Kubernetes repository configuration...');
802
+ shellExec(`sudo rm -f /etc/yum.repos.d/kubernetes.repo || true`);
803
+
804
+ // Clean up Kubeadm config and data directories
805
+ console.log('Cleaning up Kubernetes configuration directories...');
806
+ shellExec(`sudo rm -rf /etc/kubernetes/pki || true`);
807
+ shellExec(`sudo rm -rf ~/.kube || true`);
808
+
809
+ // Stop and disable services
810
+ console.log('Stopping and disabling services...');
811
+ shellExec(`sudo systemctl stop docker.service || true`);
812
+ shellExec(`sudo systemctl disable docker.service || true`);
813
+ shellExec(`sudo systemctl stop containerd.service || true`);
814
+ shellExec(`sudo systemctl disable containerd.service || true`);
815
+ shellExec(`sudo systemctl stop kubelet.service || true`);
816
+ shellExec(`sudo systemctl disable kubelet.service || true`);
817
+
818
+ // Clean up config files
819
+ console.log('Removing host configuration files...');
820
+ shellExec(`sudo rm -f /etc/containerd/config.toml || true`);
821
+ shellExec(`sudo rm -f /etc/sysctl.d/k8s.conf || true`);
822
+ shellExec(`sudo rm -f /etc/sysctl.d/99-k8s-ipforward.conf || true`);
823
+ shellExec(`sudo rm -f /etc/sysctl.d/99-k8s.conf || true`);
824
+
825
+ // Restore SELinux to enforcing
826
+ console.log('Restoring SELinux to enforcing mode...');
827
+ // shellExec(`sudo setenforce 1`);
828
+ // shellExec(`sudo sed -i 's/^SELINUX=permissive$/SELINUX=enforcing/' /etc/selinux/config`);
829
+
830
+ console.log('Uninstall process completed.');
831
+ },
832
+ };
833
+ }
834
+ export default UnderpostCluster;