@rocket.chat/houston 0.27.0-next.3 → 2.1.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 (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.removeTheClusterSide = removeTheClusterSide;
37
+ exports.stopTheForwards = stopTheForwards;
38
+ exports.dropTheEdgeRoute = dropTheEdgeRoute;
39
+ exports.teardownKubernetes = teardownKubernetes;
40
+ exports.teardownCompose = teardownCompose;
41
+ exports.teardown = teardown;
42
+ /**
43
+ * Removing a workspace: its containers or its namespace, and its record.
44
+ *
45
+ * Tier 4, and named `destroy` rather than `teardown` because the module also exports a
46
+ * function called `teardown`, and a module that shadows a symbol it has to export is
47
+ * unreachable from the façade the moment anything imports it.
48
+ */
49
+ const fs = __importStar(require("node:fs/promises"));
50
+ const config = __importStar(require("../../lib/config"));
51
+ const errors_1 = require("../../lib/errors");
52
+ const format_1 = require("../../lib/format");
53
+ const events_1 = require("../../lib/events");
54
+ const audit_1 = require("../audit");
55
+ const networks_1 = require("../edge/networks");
56
+ const routes_1 = require("../edge/routes");
57
+ const journal_1 = require("../journal");
58
+ const namespace_1 = require("../kube/namespace");
59
+ const monitoring_1 = require("../kube/monitoring");
60
+ const operator_1 = require("../kube/operator");
61
+ const names_1 = require("../kube/names");
62
+ const engine = __importStar(require("../runner/engine"));
63
+ const locks_1 = require("../runner/locks");
64
+ const paths = __importStar(require("../runner/paths"));
65
+ const record_1 = require("../runner/record");
66
+ const topology = __importStar(require("../topology"));
67
+ const naming = __importStar(require("./naming"));
68
+ const ownership = __importStar(require("./ownership"));
69
+ const preconditions = __importStar(require("./preconditions"));
70
+ const ready_1 = require("./ready");
71
+ const state_1 = require("./state");
72
+ const types_1 = require("./types");
73
+ function bag(value) {
74
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
75
+ ? value
76
+ : {};
77
+ }
78
+ function isTruthy(value) {
79
+ if (value === null || value === undefined || value === false)
80
+ return false;
81
+ if (typeof value === 'string')
82
+ return value !== '';
83
+ if (typeof value === 'number')
84
+ return value !== 0;
85
+ if (Array.isArray(value))
86
+ return value.length > 0;
87
+ if (typeof value === 'object')
88
+ return Object.keys(value).length > 0;
89
+ return true;
90
+ }
91
+ /**
92
+ * Everything the namespace held that outlives it: the chart release, the operator, and
93
+ * the cluster itself when houston made it.
94
+ */
95
+ async function removeTheClusterSide(context, emit, meta, target, volumes) {
96
+ if (!volumes)
97
+ return;
98
+ // Its namespace is gone by now, so a Grafana route that cannot be removed -- its cluster
99
+ // deleted outside houston -- is said, and does not keep a record whose data is gone from
100
+ // ever being removed.
101
+ if (isTruthy(bag(meta.extra).tls)) {
102
+ try {
103
+ await (0, monitoring_1.removeGrafanaIngress)(target, { context, emit });
104
+ }
105
+ catch (error) {
106
+ (0, events_1.warn)(emit, `could not remove '${target}''s Grafana route from cluster '${context}' ` +
107
+ `(${error instanceof Error ? error.message : String(error)}) — if the cluster is still ` +
108
+ 'there, remove it with `kubectl -n houston-system delete ingress -l ' +
109
+ `houston.io/workspace=${target}\``, { phase: 'teardown' });
110
+ }
111
+ }
112
+ // AFTER the namespace, never before: deleting it took this workspace's
113
+ // MongoDBCommunity with it while the operator was still there to clear the finalizer.
114
+ const ns = await (0, namespace_1.namespaceFor)(target);
115
+ // RETURN DELIBERATELY NOT READ, and this is the one place on this path where that is
116
+ // right. `removeOperator` returns false for THREE reasons -- not installed, still wanted
117
+ // by another workspace, and a failed uninstall -- and the first two are the normal
118
+ // outcome of a shared resource being shared.
119
+ await (0, operator_1.removeOperator)({ context, excluding: ns, emit });
120
+ // AND the monitoring stack, which had the same hole and is far more expensive: ten pods
121
+ // and ~840 MB left running after the workspace that asked for them was destroyed.
122
+ // And its namespace, when the operator was the last thing in it. Not again after
123
+ // `removeMonitoring` removed the stack: it released the namespace itself, and a second ask
124
+ // found it Terminating and said "removed" twice.
125
+ if (!(await (0, monitoring_1.removeMonitoring)({ context, excluding: ns, emit }))) {
126
+ await (0, monitoring_1.releaseSystemNamespace)(context, emit);
127
+ }
128
+ // CHECKED, not assumed. Ignoring errors means a record that could not be removed -- a
129
+ // permission problem, a file held open -- is silently left behind, and the success line
130
+ // then says "and the local record".
131
+ //
132
+ // SWALLOWED, because the removal forgives EVERY failure, not just a missing
133
+ // directory: `force: true` forgives ENOENT alone, and a rejection from a container's
134
+ // root-owned file (EACCES) or a held-open one (EBUSY) made the warning below, the
135
+ // default clear and `dropTheEdgeRoute` unreachable -- leaving the edge registered for a
136
+ // namespace that is gone, which is what `dropTheEdgeRoute` exists to prevent.
137
+ try {
138
+ await fs.rm(paths.workspace(target), { recursive: true, force: true });
139
+ }
140
+ catch {
141
+ // reported by the `exists` check and the warning below
142
+ }
143
+ if (await paths.exists(target)) {
144
+ (0, events_1.warn)(emit, `the namespace is gone but ${paths.workspace(target)} ` +
145
+ `could not be removed, so \`list\` will still show ` +
146
+ `'${target}'. Remove that directory by hand.`, { phase: 'teardown' });
147
+ }
148
+ // Its repair notes go too, whether or not the directory did: what they repair went with
149
+ // the namespace, and a record removed by hand would strand them.
150
+ (0, journal_1.clearWorkspace)(target);
151
+ await (0, state_1.clearDefaultIf)(target);
152
+ }
153
+ /**
154
+ * The port-forwards this workspace was published on. They outlive the namespace because
155
+ * they are processes on THIS box, not cluster objects.
156
+ */
157
+ async function stopTheForwards(meta, target) {
158
+ const extra = bag(meta.extra);
159
+ const ns = isTruthy(extra.namespace) ? String(extra.namespace) : await (0, namespace_1.namespaceFor)(target);
160
+ const pid = extra.port_forward_pid;
161
+ if (isTruthy(pid)) {
162
+ await (0, ready_1.stopPortForward)(Number(pid), { namespace: ns });
163
+ }
164
+ // The GRAFANA forward, which `monitor --off` stops and `down --volumes` did. It targets a
165
+ // deployment in `houston-system`, so unlike the workspace's own forward it survives the
166
+ // workspace -- it held :5050 after the workspace was destroyed -- and a PLAIN `down`
167
+ // left it running: the re-up's record no longer named it, so nothing ever stopped it.
168
+ const gpid = extra.grafana_pid;
169
+ if (isTruthy(gpid)) {
170
+ await (0, ready_1.stopPortForward)(Number(gpid), { namespace: monitoring_1.MONITORING_NAMESPACE });
171
+ }
172
+ // A preset's UI forwards too, or `down` leaves 8082 bound to a namespace that no longer
173
+ // exists -- and the NEXT workspace using that preset finds the port taken by a corpse.
174
+ const forwards = bag(extra.scenario_forwards);
175
+ for (const uiPid of Object.values(forwards)) {
176
+ try {
177
+ await (0, ready_1.stopPortForward)(Number(uiPid), { namespace: ns });
178
+ }
179
+ catch {
180
+ // A malformed recorded pid: nothing to stop.
181
+ }
182
+ }
183
+ }
184
+ /**
185
+ * A route left behind points at something that is gone, so the hostname 502s instead of
186
+ * 404ing and nobody can reuse the name. After the cluster work, because a teardown that
187
+ * could not confirm the namespace is gone has not torn the workspace down.
188
+ */
189
+ async function dropTheEdgeRoute(emit, target, volumes) {
190
+ // No `detach`: that disconnects a Docker network a Kubernetes workspace does not have.
191
+ // Deregistering is the whole of it.
192
+ (0, routes_1.deregister)(target);
193
+ const ns = await (0, namespace_1.namespaceFor)(target);
194
+ // Docker's nouns are wrong here. "containers, data volume, and record" for a workspace
195
+ // that has a namespace and a PVC says nothing about what actually went away -- and
196
+ // `helm uninstall` does NOT delete a PVC.
197
+ if (volumes) {
198
+ (0, events_1.info)(emit, `'${target}' removed — namespace ${ns}, its ` + 'PersistentVolumeClaim and the local record', { phase: 'done' });
199
+ }
200
+ else {
201
+ (0, events_1.info)(emit, `'${target}' down — the ${names_1.RELEASE} release is ` +
202
+ `uninstalled; namespace ${ns} ` +
203
+ 'and its PersistentVolumeClaim are KEPT, so `up` again ' +
204
+ 'reuses the data. `down --volumes` deletes it.', { phase: 'done' });
205
+ }
206
+ }
207
+ /** Remove the namespace, or just stop what is in it. */
208
+ async function teardownKubernetes(target, volumes, emit) {
209
+ // Deliberately BELOW the confirmation, the ownership gate and the audit record: all
210
+ // three are about whose data is being destroyed, which does not depend on the runtime.
211
+ // SAID FIRST: the namespace's identity is asked before anything is reported, and the
212
+ // whole teardown was measured at 48-61 s.
213
+ (0, events_1.info)(emit, `removing '${target}' from its cluster, which can take a minute`, {
214
+ phase: 'teardown',
215
+ });
216
+ const meta = await (0, record_1.readMeta)(target);
217
+ const extra = bag(meta.extra);
218
+ const context = isTruthy(extra[config.EXTRA_CONTEXT])
219
+ ? String(extra[config.EXTRA_CONTEXT])
220
+ : names_1.CONTEXT;
221
+ await stopTheForwards(meta, target);
222
+ const found = await (0, namespace_1.deleteNamespace)(target, { context, volumes, emit });
223
+ // BRANCHED ON, at last. This value was returned to the caller as `{"found": ...}` and
224
+ // read by nobody -- so `--volumes` deleted the local record, the shared operator and
225
+ // the monitoring stack whatever it said.
226
+ if (volumes && !found) {
227
+ (0, events_1.warn)(emit, `'${target}': the namespace is not confirmed gone, so the ` +
228
+ 'local record is KEPT. Nothing else was removed -- the ' +
229
+ 'operator and any monitoring stack are untouched. Re-run ' +
230
+ `\`houston down --name ${target} --volumes\` once ` +
231
+ `\`kubectl get ns ${await (0, namespace_1.namespaceFor)(target)}\` says it is ` +
232
+ 'absent.', { phase: 'teardown' });
233
+ return { name: target, removed: false, found, runtime: topology.KUBERNETES, context };
234
+ }
235
+ await removeTheClusterSide(context, emit, meta, target, volumes);
236
+ await dropTheEdgeRoute(emit, target, volumes);
237
+ // ON PURPOSE (`uninstallWorkspaceWorkloads` keeps a preset's Services stable for the re-up),
238
+ // but unsaid: after a plain `down` the preset's pods ran on while `list` said "down".
239
+ // `teardown`, not `done`: the CLI prints no informational `done` line. Only a preset that
240
+ // runs services, which is one that publishes a console (e2ee is settings and users only).
241
+ const services = Array.isArray(extra.sidecar_ports) && extra.sidecar_ports.length > 0;
242
+ if (!volumes && services && (meta.preset || 'default') !== 'default') {
243
+ (0, events_1.info)(emit, `its ${meta.preset} services keep running in ${await (0, namespace_1.namespaceFor)(target)} until ` +
244
+ '`down --volumes`', { phase: 'teardown' });
245
+ }
246
+ // `context` rides along so the CLI can say what a kept disk costs on a cloud cluster.
247
+ return { name: target, removed: volumes, found, runtime: topology.KUBERNETES, context };
248
+ }
249
+ /** Stop the project, detach from the edge, bring it down, and forget the name. */
250
+ async function teardownCompose(target, volumes, emit = events_1.nullEmit, streamOutput = false) {
251
+ // docker's own lines, streamed into a GUI job; the terminal keeps docker's output.
252
+ const echo = (line) => (0, events_1.info)(emit, line, { phase: 'teardown', data: { echo: 'docker' } });
253
+ // Stop while the edge is still attached, so its pooled upstream connections receive
254
+ // the backend's close. Disconnecting first strands those sockets on Podman; when a
255
+ // kept workspace gets a new network/IP, the first HTTPS request can reuse one and hang.
256
+ // Each slow step SAID before it runs: a `down` emitted nothing until its final line, so the
257
+ // GUI's job dialog stayed empty through the whole stop and removal (12 s on a voice lab).
258
+ (0, events_1.info)(emit, `stopping '${target}': each service closes cleanly first, which can take several seconds`, { phase: 'teardown' });
259
+ if ((await (streamOutput ? engine.stop(target, echo) : engine.stop(target))) !== 0) {
260
+ throw new errors_1.DockerError(`\`docker compose stop\` failed for '${target}'`);
261
+ }
262
+ // BEFORE `down`, not after: compose cannot remove a network that still has an active
263
+ // endpoint, and the edge attached to it is exactly that.
264
+ await (0, networks_1.detach)(target);
265
+ (0, events_1.info)(emit, `removing '${target}'s containers and network${volumes ? ', data volume and record' : ' (data kept)'}`, { phase: 'teardown' });
266
+ if ((await engine.down(target, { volumes, ...(streamOutput ? { onLine: echo } : {}) })) !== 0) {
267
+ throw new errors_1.DockerError(`\`docker compose down\` failed for '${target}'`);
268
+ }
269
+ // A route left behind points the edge at a container that no longer exists, so that
270
+ // hostname would 502 instead of 404 -- and the name could never be reused by anyone else.
271
+ (0, routes_1.deregister)(target);
272
+ if (volumes) {
273
+ await paths.remove(target);
274
+ // SAID, as the Kubernetes path says it: the containers and volume are gone, and a record
275
+ // that could not be removed would otherwise go on being listed with nothing behind it.
276
+ if (await paths.exists(target)) {
277
+ (0, events_1.warn)(emit, `the containers and data volume are gone but ${paths.workspace(target)} could not be ` +
278
+ `removed, so \`list\` will still show '${target}'. Remove that directory by hand.`, { phase: 'teardown' });
279
+ }
280
+ // A note about a workspace that is gone advises work nobody can do: `doctor` kept
281
+ // telling people to `houston ready` a workspace this had just deleted.
282
+ (0, journal_1.clearWorkspace)(target);
283
+ await (0, state_1.clearDefaultIf)(target);
284
+ }
285
+ }
286
+ async function teardown(name, { volumes = false, confirm = false, emit = events_1.nullEmit, streamOutput = false } = {}) {
287
+ const target = await naming.resolveName(name);
288
+ await preconditions.requireEngine(target);
289
+ if (volumes && !confirm) {
290
+ throw new errors_1.ValidationError(`deleting ${(0, format_1.quotedText)(target)}'s data volume and record is irreversible - pass confirm=true`);
291
+ }
292
+ const refuseUnlessAllowed = async () => {
293
+ if (!volumes)
294
+ return;
295
+ const [allowed, why] = await ownership.mayDestroy(target, (0, audit_1.actor)());
296
+ if (!allowed) {
297
+ (0, audit_1.record)('down-volumes', target, { outcome: 'denied' });
298
+ throw new errors_1.ConflictError(why);
299
+ }
300
+ };
301
+ await refuseUnlessAllowed();
302
+ // Locked: `down` during a create races `docker compose up` and leaves orphaned
303
+ // containers behind.
304
+ const body = async () => {
305
+ // AGAIN UNDER THE LOCK: handed over while this waited, it is somebody else's data now.
306
+ await refuseUnlessAllowed();
307
+ // Recorded BEFORE the work, not after: a teardown that dies half way through has still
308
+ // destroyed containers, and that is exactly the event someone will come looking for.
309
+ // After the check, so a refusal is not also written down as done.
310
+ (0, audit_1.record)(volumes ? 'down-volumes' : 'down', target);
311
+ // The two runtimes answer DIFFERENTLY, and always did: the Kubernetes path reports
312
+ // `found` and its own `runtime`, and says its own "done" line.
313
+ if ((await topology.ofRepro(target)) === topology.KUBERNETES) {
314
+ await (0, state_1.downComposeLeftovers)(target, volumes, emit);
315
+ return await teardownKubernetes(target, volumes, emit);
316
+ }
317
+ await teardownCompose(target, volumes, emit, streamOutput);
318
+ return null;
319
+ };
320
+ // ASKED FIRST WITHOUT WAITING, so a wait is SAID: `down --volumes` behind a running
321
+ // `backup` sat silent for its whole duration. Only the lock's own refusal waits; any other
322
+ // conflict from the teardown is the answer.
323
+ let result;
324
+ try {
325
+ result = await (0, locks_1.reproLock)(target, body, { timeoutMs: 0 });
326
+ }
327
+ catch (error) {
328
+ if (!(error instanceof errors_1.ConflictError && error.message.startsWith('another houston'))) {
329
+ throw error;
330
+ }
331
+ (0, events_1.info)(emit, `another houston command is working on '${target}' (a backup, restore or upgrade?) — ` +
332
+ `waiting up to ${String(types_1.INTERACTIVE_LOCK_WAIT)}s for it to finish`, { phase: 'teardown' });
333
+ result = await (0, locks_1.reproLock)(target, body, { timeoutMs: types_1.INTERACTIVE_LOCK_WAIT * 1000 });
334
+ }
335
+ if (result !== null)
336
+ return result;
337
+ (0, events_1.info)(emit, `'${target}' ${volumes ? 'removed' : 'down (data kept)'}`, { phase: 'done' });
338
+ return { name: target, removed: volumes };
339
+ }