@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,413 @@
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.CHART_OWNED_ENV = exports.CHART_CONDITIONAL_ENV = exports.OLDEST_CHART_SERIES = void 0;
37
+ exports.ensureRepo = ensureRepo;
38
+ exports.bestChartAtOrBelow = bestChartAtOrBelow;
39
+ exports.resolveChartVersion = resolveChartVersion;
40
+ exports.refuseChartOwnedEnv = refuseChartOwnedEnv;
41
+ exports.chartEnv = chartEnv;
42
+ exports.validateRootAddress = validateRootAddress;
43
+ exports.valuesFor = valuesFor;
44
+ /**
45
+ * Which chart version, and the values houston hands it.
46
+ *
47
+ * `valuesFor` is the one place those values are built, and the conformance harness asks the
48
+ * REAL published chart whether they are valid -- a key the chart ships commented out is
49
+ * invisible to a YAML parse and silently ignored by helm, which surfaces as "the setting had
50
+ * no effect" and never as an error.
51
+ */
52
+ const config = __importStar(require("../../lib/config"));
53
+ const errors_1 = require("../../lib/errors");
54
+ const events_1 = require("../../lib/events");
55
+ const format_1 = require("../../lib/format");
56
+ const versions_1 = require("../../lib/versions");
57
+ const ask_1 = require("./ask");
58
+ const exec_1 = require("./exec");
59
+ const manifests_1 = require("./manifests");
60
+ const names_1 = require("./names");
61
+ const operator_1 = require("./operator");
62
+ const tools_1 = require("./tools");
63
+ /**
64
+ * Add and refresh the Rocket.Chat chart repo in houston's own Helm home.
65
+ *
66
+ * `own: true` UNCONDITIONALLY, and that is correct rather than an oversight -- it has been
67
+ * read as a bug twice, so: every helm call that needs this repo reads it through `helmEnv`,
68
+ * which always points HELM_* at houston's directories whatever cluster is targeted. Writer
69
+ * and readers therefore agree by construction.
70
+ *
71
+ * The obvious-looking alternative would fix the older mismatch by writing `rocketchat` into
72
+ * the USER's repositories.yaml -- mutating their Helm configuration as a side effect of
73
+ * running a repro tool, which is the one thing `ownedEnv` exists to prevent.
74
+ *
75
+ * No context is threaded in because none is needed: `repo add`, `repo update` and `search
76
+ * repo` contact no cluster at all.
77
+ */
78
+ async function ensureRepo(_emit = events_1.nullEmit) {
79
+ await exec_1.kube.run(['helm', 'repo', 'add', names_1.HELM_REPO, names_1.HELM_REPO_URL, '--force-update'], {
80
+ timeout: names_1.APPLY_TIMEOUT,
81
+ own: true,
82
+ });
83
+ const res = await exec_1.kube.run(['helm', 'repo', 'update', names_1.HELM_REPO], {
84
+ timeout: names_1.APPLY_TIMEOUT,
85
+ own: true,
86
+ });
87
+ if (res.returncode !== 0) {
88
+ throw new errors_1.CreateFailedError(`could not read the Rocket.Chat chart repository (${names_1.HELM_REPO_URL}): ${(0, ask_1.why)(res)}`);
89
+ }
90
+ }
91
+ /**
92
+ * The oldest chart series whose values schema is the one `valuesFor` emits.
93
+ *
94
+ * MEASURED against the live index: it holds 96 chart versions, and below 3.0.0 there is
95
+ * exactly ONE -- 0.1.0, appVersion 1.16.0 -- with nothing in between. So the floor rule
96
+ * ("newest chart whose appVersion is at or below the request"), which is correct everywhere
97
+ * else, drops any request below chart 3.0.0's appVersion straight onto a 1.16-era chart.
98
+ * That chart predates every values key houston sets, so it would render something, and not a
99
+ * working workspace.
100
+ *
101
+ * Refusing is better than that, because the tool HAS an answer for these versions: the
102
+ * Docker runtime handles them natively.
103
+ */
104
+ exports.OLDEST_CHART_SERIES = 3;
105
+ function atOrBelow(left, right) {
106
+ for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
107
+ const a = left[index] ?? 0;
108
+ const b = right[index] ?? 0;
109
+ if (a !== b)
110
+ return a < b;
111
+ }
112
+ return true;
113
+ }
114
+ /** Strictly greater, so an equal pair keeps the FIRST maximal entry, as `max` does. */
115
+ function greater(left, right) {
116
+ for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
117
+ const a = left[index] ?? 0;
118
+ const b = right[index] ?? 0;
119
+ if (a !== b)
120
+ return a > b;
121
+ }
122
+ return false;
123
+ }
124
+ /** The newest chart whose app version does not run ahead of Rocket.Chat's. */
125
+ function bestChartAtOrBelow(entries, rcVersion) {
126
+ const want = (0, tools_1.versionKey)(rcVersion);
127
+ const exact = entries.find((entry) => String(entry.app_version ?? '') === rcVersion);
128
+ if (exact !== undefined)
129
+ return String(exact.version);
130
+ const candidates = entries.filter((entry) => atOrBelow((0, tools_1.versionKey)(String(entry.app_version ?? '0')), want));
131
+ // OLDER THAN EVERY CHART. There is no floor left to stand on, and the branch that used to
132
+ // catch this fell back to the NEWEST chart -- the furthest possible thing from what was
133
+ // asked. Measured: RC 1.0.0 resolved to chart 7.0.2, which deploys 8.6.1.
134
+ if (candidates.length === 0) {
135
+ let oldest = entries[0];
136
+ for (const entry of entries) {
137
+ if (greater((0, tools_1.versionKey)(String(oldest.app_version ?? '0')), (0, tools_1.versionKey)(String(entry.app_version ?? '0')))) {
138
+ oldest = entry;
139
+ }
140
+ }
141
+ throw new errors_1.ValidationError(`the Kubernetes runtime cannot reproduce Rocket.Chat ${rcVersion}: no chart deploys ` +
142
+ `it or anything older — the oldest is ${String(oldest.version)} (appVersion ` +
143
+ `${String(oldest.app_version)}). Use the Docker runtime for this version by ` +
144
+ 'leaving `--runtime` off.');
145
+ }
146
+ let best = candidates[0];
147
+ for (const entry of candidates) {
148
+ if (greater((0, tools_1.versionKey)(String(entry.version)), (0, tools_1.versionKey)(String(best.version)))) {
149
+ best = entry;
150
+ }
151
+ }
152
+ const chosen = String(best.version);
153
+ // A CHART FROM ANOTHER ERA IS NOT A MATCH, it is the floor rule running out of charts at
154
+ // the old end. See OLDEST_CHART_SERIES for the measurement.
155
+ if (((0, tools_1.versionKey)(chosen)[0] ?? -1) < exports.OLDEST_CHART_SERIES) {
156
+ throw new errors_1.ValidationError(`the Kubernetes runtime cannot reproduce Rocket.Chat ${rcVersion}: the oldest chart ` +
157
+ `that deploys it is ${chosen} (appVersion ${String(best.app_version)}), which ` +
158
+ 'predates every values key houston sets, so it would install something other than ' +
159
+ 'what you asked for. Use the Docker runtime for this version — it supports it ' +
160
+ 'natively — by leaving `--runtime` off.');
161
+ }
162
+ // DELIBERATELY SILENT WHEN THE CHART IS MERELY BEHIND THE APP. That is the normal case,
163
+ // and a line saying so fired on essentially every create immediately before `chart X for
164
+ // Rocket.Chat Y` said the same thing more clearly.
165
+ return chosen;
166
+ }
167
+ /**
168
+ * Pin a chart version for a Rocket.Chat version.
169
+ *
170
+ * Most Rocket.Chat releases have no chart with a matching appVersion, so an exact match
171
+ * cannot be required. Exact match if one exists, else the newest chart whose appVersion is
172
+ * at or BELOW the request -- a floor, so the chart is never newer than the app it deploys.
173
+ *
174
+ * An unreadable index is terminal rather than falling back to an unpinned chart. For a tool
175
+ * whose whole job is version-matching, `helm install` without `--version` deploys different
176
+ * software after the next chart release.
177
+ */
178
+ async function resolveChartVersion(rcVersion, _emit = events_1.nullEmit) {
179
+ // `own: true` for the same reason as `ensureRepo`, which is what populated this index: the
180
+ // chart index lives in houston's Helm home, and reading it touches no cluster.
181
+ const res = await exec_1.kube.run(['helm', 'search', 'repo', names_1.CHART, '--versions', '-o', 'json'], {
182
+ timeout: names_1.APPLY_TIMEOUT,
183
+ own: true,
184
+ });
185
+ if (res.returncode !== 0) {
186
+ throw new errors_1.CreateFailedError(`could not read the Rocket.Chat chart index: ${(0, ask_1.why)(res)}`);
187
+ }
188
+ let entries;
189
+ try {
190
+ entries = JSON.parse(res.stdout || '[]');
191
+ }
192
+ catch {
193
+ throw new errors_1.CreateFailedError('the Rocket.Chat chart index was not valid JSON');
194
+ }
195
+ if (!Array.isArray(entries) || entries.length === 0) {
196
+ throw new errors_1.CreateFailedError(`no versions found for the chart '${names_1.CHART}'`);
197
+ }
198
+ return bestChartAtOrBelow(entries, rcVersion);
199
+ }
200
+ /**
201
+ * Values that make the CHART emit an env var houston also puts in `extraEnv`.
202
+ *
203
+ * Keyed by the value, named by the variable, because the collision is one-to-one and the
204
+ * next one to be added will be too.
205
+ */
206
+ exports.CHART_CONDITIONAL_ENV = Object.freeze({
207
+ license: 'OVERWRITE_SETTING_Show_Setup_Wizard',
208
+ registrationToken: 'REG_TOKEN',
209
+ });
210
+ /**
211
+ * Env the chart's Rocket.Chat Deployment writes ITSELF, always or under a value houston sets
212
+ * or leaves at its default. Measured from chart 7.0.2's `chat-deployment.yaml`, the only
213
+ * template that renders `extraEnv`. One of these in `extraEnv` is a duplicate key, which
214
+ * server-side apply refuses -- after MongoDB is already up, rolling the whole create back.
215
+ */
216
+ exports.CHART_OWNED_ENV = Object.freeze({
217
+ ROOT_URL: 'use --root-url, or --domain for a public name',
218
+ MONGO_URL: 'the chart reads it from the workspace Secret',
219
+ REG_TOKEN: 'use --reg-token',
220
+ MAIL_URL: 'the chart owns it',
221
+ INSTANCE_IP: 'the chart sets it to the pod IP',
222
+ DEPLOY_PLATFORM: 'the chart owns it',
223
+ ROCKETCHAT_LICENSE: 'the chart owns it',
224
+ LICENSE_DEBUG: 'the chart owns it',
225
+ OVERWRITE_SETTING_Prometheus_Enabled: 'the chart sets it (prometheusScraping)',
226
+ OVERWRITE_SETTING_Prometheus_Port: 'the chart sets it (prometheusScraping)',
227
+ MS_METRICS: 'the chart owns it',
228
+ MS_METRICS_PORT: 'the chart owns it',
229
+ DB_WATCHERS: 'the chart owns it',
230
+ MOLECULER_LOG_LEVEL: 'the chart owns it',
231
+ HEARTBEAT_INTERVAL: 'the chart owns it',
232
+ HEARTBEAT_TIMEOUT: 'the chart owns it',
233
+ RETRY_ENABLED: 'the chart owns it',
234
+ });
235
+ /** Refuse an override the chart would duplicate, before anything is created. */
236
+ function refuseChartOwnedEnv(overrides) {
237
+ for (const key of Object.keys(overrides)) {
238
+ const reason = exports.CHART_OWNED_ENV[key] ?? (key.startsWith('DEPLOY_') ? 'the chart owns it' : undefined);
239
+ if (reason === undefined)
240
+ continue;
241
+ throw new errors_1.ValidationError(`${key} cannot be set with --env or --setting on Kubernetes: ${reason}. A second ` +
242
+ 'entry for a variable the chart writes is a server-side-apply conflict, not an ' +
243
+ 'override.');
244
+ }
245
+ }
246
+ /**
247
+ * The environment the chart passes to Rocket.Chat, registration token included.
248
+ *
249
+ * A MAP, in the order base < preset < `overrides`, as Compose builds it: a key set twice
250
+ * replaces the earlier value in place. Appending put a second entry for the same name in
251
+ * `extraEnv`, which server-side apply refuses. A null override removes the key.
252
+ */
253
+ function chartEnv(adminPassword, host, presetEnv, regTokenSecret, rootUrl, overrides = {}, licensed = false) {
254
+ // THE WORKSPACE HAS TO BE USABLE ON ARRIVAL, which is what these give and what Kubernetes
255
+ // was missing entirely. `up` printed "Login admin / admin123" for a workspace where that
256
+ // user had never been created and the setup wizard was still waiting.
257
+ //
258
+ // DEPLOY_METHOD and DEPLOY_PLATFORM are NOT here, and were, for one commit. The chart sets
259
+ // them itself, and a second entry for the same key is not an override but a conflict:
260
+ // "server-side apply failed ... duplicate entries for key [name=DEPLOY_PLATFORM]". So
261
+ // anything the chart already provides must not be repeated here.
262
+ const env = [
263
+ { name: 'OVERWRITE_SETTING_Show_Setup_Wizard', value: 'completed' },
264
+ { name: 'ADMIN_USERNAME', value: config.ADMIN_USERNAME },
265
+ { name: 'ADMIN_NAME', value: config.ADMIN_NAME },
266
+ { name: 'ADMIN_EMAIL', value: config.ADMIN_EMAIL },
267
+ { name: 'ADMIN_PASS', value: adminPassword || config.ADMIN_PASSWORD },
268
+ { name: 'ALLOW_UNSAFE_QUERY_AND_FIELDS_API_PARAMS', value: 'false' },
269
+ ];
270
+ // ROOT_URL, WHICH THIS RUNTIME HAD NEVER SET. The chart emits one only from
271
+ // `.Values.host`, and nothing passed that -- so Rocket.Chat ran on its built-in default
272
+ // while every human reached it on an allocated port. ROOT_URL is what absolute links,
273
+ // OAuth callbacks and CORS derive from.
274
+ //
275
+ // Only when there is no `host`: with one, the chart writes ROOT_URL itself and a second
276
+ // entry here would be a duplicate-key apply failure rather than a win.
277
+ if (rootUrl !== '' && host === '')
278
+ env.push({ name: 'ROOT_URL', value: rootUrl });
279
+ // A scenario's Rocket.Chat settings are the SHARED half of the Scenario contract, so they
280
+ // ride extraEnv here exactly as they ride the service environment on Compose. AFTER the
281
+ // base list, so a preset can override a default rather than being overridden by one.
282
+ // `toTextYaml` of the value the preset's YAML holds, as compose.ts writes it.
283
+ const byName = new Map(env.map((entry) => [entry.name, entry]));
284
+ for (const [key, value] of Object.entries(presetEnv ?? {})) {
285
+ byName.set(String(key), { name: String(key), value: (0, format_1.toTextYaml)(value, config.yamlDateText) });
286
+ }
287
+ for (const [key, value] of Object.entries(overrides)) {
288
+ if (value === null)
289
+ byName.delete(key);
290
+ else
291
+ byName.set(key, { name: key, value: String(value) });
292
+ }
293
+ env.splice(0, env.length, ...byName.values());
294
+ if (regTokenSecret !== '') {
295
+ // By REFERENCE, so the token is never a value in this document. The chart renders
296
+ // extraEnv verbatim, so valueFrom survives -- verified against the published chart.
297
+ env.push({
298
+ name: 'REG_TOKEN',
299
+ valueFrom: { secretKeyRef: { name: regTokenSecret, key: operator_1.REG_TOKEN_KEY } },
300
+ });
301
+ }
302
+ if (licensed) {
303
+ env.push({
304
+ name: 'ROCKETCHAT_LICENSE',
305
+ valueFrom: { secretKeyRef: { name: operator_1.LICENSE_SECRET, key: operator_1.LICENSE_KEY } },
306
+ });
307
+ }
308
+ return env;
309
+ }
310
+ /** Refuse the two URL shapes the chart cannot render safely. */
311
+ function validateRootAddress(rootUrl, host) {
312
+ // REFUSED, not normalised. A caller that hands a URL where a hostname belongs has a bug,
313
+ // and quietly stripping the scheme would hide it -- the whole point of this guard is that
314
+ // `https://http://...` was shippable once. `:` catches a port, which the chart would
315
+ // concatenate just as happily.
316
+ if (host !== '' && (host.includes('/') || host.includes(':'))) {
317
+ throw new errors_1.ValidationError(`chart value \`host\` must be a bare hostname, not '${host}' — the chart renders it ` +
318
+ 'as `ROOT_URL: https://{host}` and as the Ingress rule host, so a scheme or a port ' +
319
+ 'corrupts both. Pass a full URL as `root_url` instead.');
320
+ }
321
+ if (host !== '' && rootUrl !== '') {
322
+ throw new errors_1.ValidationError('pass `host` or `root_url`, never both: `host` makes the chart emit its own ROOT_URL ' +
323
+ 'and `root_url` puts one in extraEnv, and two entries for the same variable is a ' +
324
+ 'server-side-apply conflict, not an override.');
325
+ }
326
+ }
327
+ /** Values shared by every Rocket.Chat chart deployment. */
328
+ function baseChartValues(repo, tag, microservices, replicas, env) {
329
+ // A CI BUILD moves under the same tag, so it is pulled every time, and its microservice
330
+ // images live beside it on ghcr (Docker Hub has releases only). stream-hub is not built
331
+ // for pull requests or FIPS (measured), so it stays off.
332
+ const build = repo === versions_1.BUILD_IMAGE;
333
+ const ghcr = (service) => ({
334
+ image: { repository: `ghcr.io/rocketchat/${service}`, pullPolicy: 'Always' },
335
+ });
336
+ return {
337
+ // pullPolicy and the NATS cluster name are the guide's own values.yaml. IfNotPresent
338
+ // also matters here specifically: a repro box re-creates workspaces on the same
339
+ // versions constantly, and Always would re-pull 1.6 GB each time.
340
+ image: { repository: repo, tag, pullPolicy: build ? 'Always' : 'IfNotPresent' },
341
+ // `enabled` FOLLOWS microservices, because NATS is what the microservices talk over and
342
+ // a monolith never opens a connection to it. The chart defaults it on independently, so
343
+ // `--deployment monolith` ran a 3-pod NATS cluster that nothing used -- three more pods
344
+ // to schedule, to wait for, and to tear down.
345
+ nats: { enabled: microservices, cluster: { name: 'rocketchat-nats-cluster' } },
346
+ replicaCount: Math.max(1, Math.trunc(replicas) || 1),
347
+ microservices: build
348
+ ? {
349
+ enabled: microservices,
350
+ presence: ghcr('presence-service'),
351
+ ddpStreamer: ghcr('ddp-streamer-service'),
352
+ account: ghcr('account-service'),
353
+ authorization: ghcr('authorization-service'),
354
+ streamHub: { enabled: false },
355
+ }
356
+ : { enabled: microservices },
357
+ mongodb: { enabled: false },
358
+ extraEnv: env,
359
+ };
360
+ }
361
+ /** The parts of the values file that only appear when something asked for them. */
362
+ function applyOptionalValues(host, mongoSecret, mongoUrl, oplog, oplogUrl, values) {
363
+ if (mongoSecret !== '') {
364
+ // The URL goes in a Secret and its NAME goes in the values, so `helm get values
365
+ // rocketchat` no longer prints the password to anyone who can read the release.
366
+ values.existingMongodbSecret = mongoSecret;
367
+ }
368
+ else {
369
+ values.externalMongodbUrl = mongoUrl || names_1.MONGO_URL;
370
+ // Rocket.Chat below 8.x still wants the oplog URL; 8.x deprecates it.
371
+ if (oplog)
372
+ values.externalMongodbOplogUrl = oplogUrl || names_1.MONGO_OPLOG_URL;
373
+ }
374
+ // The chart's own `host:` -- the Ingress rule host AND the source of its ROOT_URL. A bare
375
+ // hostname, guarded by `validateRootAddress`.
376
+ if (host !== '')
377
+ values.host = host;
378
+ // THE CHART SETS SOME OF THESE ITSELF, CONDITIONALLY, and a second entry for one env key
379
+ // is not an override -- it is a server-side-apply failure. Chart 7.0.2 emits the wizard
380
+ // key under `{{- if .Values.license }}` and REG_TOKEN under a registrationToken guard.
381
+ // Nothing sets `license` today, so this is latent rather than broken -- which is exactly
382
+ // when it is cheap to fix.
383
+ for (const [valueKey, envName] of Object.entries(exports.CHART_CONDITIONAL_ENV)) {
384
+ const present = values[valueKey];
385
+ if (present !== undefined && present !== null && present !== '' && present !== false) {
386
+ values.extraEnv = values.extraEnv.filter((entry) => entry.name !== envName);
387
+ }
388
+ }
389
+ }
390
+ /**
391
+ * Chart values for one workspace.
392
+ *
393
+ * `rootUrl` and `host` are TWO DIFFERENT SHAPES and only one may be given. `host` is a BARE
394
+ * HOSTNAME, because that is what the chart's own values.yaml documents and what its template
395
+ * does with it -- `value: https://{{ .Values.host }}`. So the chart CONCATENATES. An earlier
396
+ * version assigned a full URL to `host`, which rendered `ROOT_URL =
397
+ * https://http://localhost:32812`, verified by `helm template` against chart 7.0.2. It never
398
+ * fired only because nothing passed it -- and that was its own defect: with `.Values.host`
399
+ * unset the chart emits NO ROOT_URL at all.
400
+ *
401
+ * MongoDB is ALWAYS external, never the chart's bundled subchart: the bundled path is
402
+ * Bitnami, which publishes amd64-only images so it cannot work on arm64 at all, and chart
403
+ * 7.0.2 declares appVersion 8.6.1 while defaulting MongoDB to 6.0.10, which Rocket.Chat
404
+ * 8.6.1 rejects outright.
405
+ */
406
+ function valuesFor({ rcVersion, rcImage, microservices, replicas = 1, rootUrl = '', host = '', oplog = false, mongoUrl = '', oplogUrl = '', mongoSecret = '', regTokenSecret = '', adminPassword = '', presetEnv, envOverrides = {}, licensed = false, }) {
407
+ validateRootAddress(rootUrl, host);
408
+ const [repo, tag] = (0, manifests_1.splitImage)(rcImage, rcVersion);
409
+ const env = chartEnv(adminPassword, host, presetEnv, regTokenSecret, rootUrl, envOverrides, licensed);
410
+ const values = baseChartValues(repo, tag, microservices, replicas, env);
411
+ applyOptionalValues(host, mongoSecret, mongoUrl, oplog, oplogUrl, values);
412
+ return values;
413
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DELETE_TIMEOUT = exports.CREATE_TIMEOUT = exports.CLUSTER_LOCK = void 0;
4
+ exports.ensureCluster = ensureCluster;
5
+ exports.ensureKubeconfig = ensureKubeconfig;
6
+ exports.clusterReclaimable = clusterReclaimable;
7
+ exports.deleteCluster = deleteCluster;
8
+ /**
9
+ * Bringing houston's OWN cluster into existence, and taking it away.
10
+ *
11
+ * Tier k3. The only cluster this package may create is the local one; everything else is
12
+ * adopted. `deleteCluster` takes NO cluster parameter at all, deliberately -- it can only
13
+ * ever mean ours, and a parameter would be an invitation to pass somebody else's.
14
+ */
15
+ const errors_1 = require("../../lib/errors");
16
+ const events_1 = require("../../lib/events");
17
+ const locks_1 = require("../runner/locks");
18
+ const ask_1 = require("./ask");
19
+ const capabilities_1 = require("./capabilities");
20
+ const context_1 = require("./context");
21
+ const exec_1 = require("./exec");
22
+ const names_1 = require("./names");
23
+ const reachability_1 = require("./reachability");
24
+ const tools_1 = require("./tools");
25
+ /**
26
+ * Lock name for cluster creation. Not a valid repro name (sanitisation strips the
27
+ * underscores), so it can never collide with a workspace's own lock.
28
+ */
29
+ exports.CLUSTER_LOCK = '__cluster__';
30
+ /**
31
+ * Creating a cluster pulls a node image on first use and waits for the control plane.
32
+ * Nothing like the 8 s a probe gets.
33
+ */
34
+ exports.CREATE_TIMEOUT = 600.0;
35
+ exports.DELETE_TIMEOUT = 120.0;
36
+ /** Create the shared kind cluster, with one process doing it at a time. */
37
+ async function createUnderLock(emit, kubeconfig) {
38
+ await (0, locks_1.reproLock)(exports.CLUSTER_LOCK, async () => {
39
+ if ((await (0, context_1.clusters)())[0].includes(names_1.CLUSTER_NAME)) {
40
+ (0, events_1.info)(emit, `reusing cluster ${names_1.CLUSTER_NAME}`, { phase: 'provision' });
41
+ return;
42
+ }
43
+ (0, events_1.info)(emit, `creating cluster ${names_1.CLUSTER_NAME} — first time on this machine, so this pulls a ` +
44
+ 'node image', { phase: 'provision', pct: 5 });
45
+ (0, exec_1.ownedEnv)(); // make the directories before kind writes into them
46
+ const res = await exec_1.kube.run(['kind', 'create', 'cluster', '--name', names_1.CLUSTER_NAME, '--kubeconfig', kubeconfig], { timeout: exports.CREATE_TIMEOUT, own: true });
47
+ if (res.returncode !== 0) {
48
+ const combined = `${res.stdout}\n${res.stderr}`.toLowerCase();
49
+ // A create that lost a race to something not holding this lock (a manual `kind
50
+ // create`) is success, not failure.
51
+ if (!combined.includes('already exist')) {
52
+ throw new errors_1.CreateFailedError(`could not create the cluster ${names_1.CLUSTER_NAME}: ${(0, ask_1.why)(res)}`);
53
+ }
54
+ }
55
+ }, { timeoutMs: exports.CREATE_TIMEOUT * 1000 });
56
+ }
57
+ /**
58
+ * Create houston's cluster if it is not there, and return its context.
59
+ *
60
+ * Serialised with the SAME lock every other mutating operation uses, rather than a second
61
+ * lock of its own. Two simultaneous `up`s would otherwise both see no cluster and both run
62
+ * `kind create`, and the second fails with "node(s) already exist". The re-check inside
63
+ * the lock means the loser of the race reuses rather than retries.
64
+ *
65
+ * Nothing about this touches `~/.kube/config`: `--kubeconfig` is passed explicitly AND the
66
+ * environment is redirected, because kind writes the file it is given and also honours
67
+ * KUBECONFIG for the context switch.
68
+ */
69
+ async function ensureCluster(emit = events_1.nullEmit) {
70
+ if ((0, tools_1.which)('kind') === '') {
71
+ throw new errors_1.PreflightError('kind is not installed, so houston cannot create a cluster. Install kind, or point ' +
72
+ 'kubectl at a cluster you already have.');
73
+ }
74
+ const kubeconfig = (0, exec_1.ownedKubeconfig)();
75
+ await createUnderLock(emit, kubeconfig);
76
+ // ALWAYS export, not only after creating. `kind get clusters` reads Docker, so it sees a
77
+ // cluster that houston's OWN kubeconfig knows nothing about -- which happens whenever
78
+ // the cluster outlives the kubeconfig: a different or fresh HOUSTON_HOME, a deleted
79
+ // config, or a cluster someone made by hand. Then "reusing cluster" is followed by every
80
+ // kubectl call going to localhost:8080 and the create failing with "the API server is
81
+ // not answering" about a cluster that is perfectly healthy.
82
+ const exported = await exec_1.kube.run(['kind', 'export', 'kubeconfig', '--name', names_1.CLUSTER_NAME, '--kubeconfig', kubeconfig], { timeout: names_1.APPLY_TIMEOUT, own: true });
83
+ if (exported.returncode !== 0) {
84
+ throw new errors_1.CreateFailedError(`cluster ${names_1.CLUSTER_NAME} exists but its kubeconfig could not be read: ${(0, ask_1.why)(exported)}`);
85
+ }
86
+ const context = await (0, context_1.clusterContext)();
87
+ if (!(await (0, reachability_1.reachable)(context))) {
88
+ throw new errors_1.CreateFailedError(`cluster ${names_1.CLUSTER_NAME} was created but its API server is not answering at ` +
89
+ `'${context}'. \`kind delete cluster --name ${names_1.CLUSTER_NAME}\` and try again.`);
90
+ }
91
+ (0, events_1.info)(emit, `cluster ${names_1.CLUSTER_NAME} ready at ${context}`, { phase: 'provision' });
92
+ return context;
93
+ }
94
+ /**
95
+ * The context to use, with houston's OWN kubeconfig guaranteed to know it.
96
+ *
97
+ * `ensureCluster` was called only when a cluster had to be created -- and the export must
98
+ * happen either way. With a kind cluster already up and a fresh home, every command failed
99
+ * with `context was not found for specified context: kind-houston-local` and could not
100
+ * self-heal, because the only thing that writes that context ran later, or never.
101
+ *
102
+ * `CLAUDE.md` tells anyone writing a script to `export HOUSTON_HOME=$(mktemp -d)`, so this
103
+ * was reachable by following our own instructions once a cluster existed.
104
+ *
105
+ * For a cluster houston did not create there is nothing to export: the user's own
106
+ * kubeconfig already names it, and rewriting it is not ours to do.
107
+ */
108
+ async function ensureKubeconfig(plan, emit = events_1.nullEmit) {
109
+ if (plan.create || plan.context === names_1.CONTEXT) {
110
+ // ALREADY DONE IS DONE. Two call sites reach this per create, so the banner appeared
111
+ // twice and, worse, the cluster lock was taken twice, doubling the window a concurrent
112
+ // create waits on provisioning. A fresh HOUSTON_HOME fails both halves and still
113
+ // exports, which is the case that made this function necessary.
114
+ if (!plan.create &&
115
+ (await (0, context_1.clusterContext)()) === plan.context &&
116
+ (await (0, reachability_1.reachable)(plan.context))) {
117
+ return plan.context;
118
+ }
119
+ return await ensureCluster(emit);
120
+ }
121
+ return plan.context;
122
+ }
123
+ /**
124
+ * Whether houston's own cluster exists and holds nothing of ours.
125
+ *
126
+ * UNREACHABLE IS NOT EMPTY. This used to return true for a cluster that exists and does not
127
+ * answer, reasoning that `kind delete` talks to Docker rather than to the API server so
128
+ * nothing stops it. That is true and it is the wrong conclusion: a control plane that
129
+ * cannot be reached is the case where houston knows LEAST about what it would destroy. A
130
+ * paused container, a Docker restart or a laptop resuming all produce it, and `prune` then
131
+ * stated the cluster was "empty" and deleted it -- measured, with five Running pods and an
132
+ * 8 Gi Bound PVC in it.
133
+ */
134
+ async function clusterReclaimable() {
135
+ if ((0, tools_1.which)('kind') === '' || !(await (0, context_1.clusters)())[0].includes(names_1.CLUSTER_NAME))
136
+ return false;
137
+ const ctx = await (0, context_1.clusterContext)();
138
+ if (!(await (0, reachability_1.reachable)(ctx)))
139
+ return false;
140
+ // null (could not ask) must NOT read as "empty and therefore reclaimable".
141
+ const held = await (0, capabilities_1.workspaceNamespaces)(ctx);
142
+ return held !== null && held.length === 0;
143
+ }
144
+ /**
145
+ * Delete houston's own cluster. Returns false if there was nothing to delete.
146
+ *
147
+ * Refuses while any workspace namespace is still in it, unless forced. On a shared box the
148
+ * cluster holds other people's workspaces, and `prune` reclaiming the cluster out from
149
+ * under a colleague mid-ticket is the failure this guards -- the namespaces carry
150
+ * `houston.io/owner`, so the refusal can say whose.
151
+ *
152
+ * Only ever CLUSTER_NAME. There is no parameter for which cluster to delete, because a
153
+ * delete that can be pointed anywhere eventually is.
154
+ */
155
+ async function deleteCluster({ force = false, emit = events_1.nullEmit, } = {}) {
156
+ if ((0, tools_1.which)('kind') === '')
157
+ return false;
158
+ return await (0, locks_1.reproLock)(exports.CLUSTER_LOCK, async () => {
159
+ if (!(await (0, context_1.clusters)())[0].includes(names_1.CLUSTER_NAME))
160
+ return false;
161
+ const context = await (0, context_1.clusterContext)();
162
+ // THE GUARD IS NOT INSIDE `reachable()`. It used to be, so an unreachable cluster
163
+ // skipped the whole ownership check -- including the "could not read" refusal
164
+ // directly below, which exists for exactly this case and could never fire in it.
165
+ // `kind delete` talks to Docker, so unreachability was no obstacle: a paused control
166
+ // plane holding live workspaces was deleted with one `prune --yes`.
167
+ if (!force) {
168
+ if (!(await (0, reachability_1.reachable)(context))) {
169
+ throw new errors_1.ConflictError(`cluster ${names_1.CLUSTER_NAME} exists but is not answering, so what it holds cannot ` +
170
+ "be read — it may hold workspaces, including somebody else's. Start it " +
171
+ `(\`docker start ${names_1.CLUSTER_NAME}-control-plane\`) and try again, or pass ` +
172
+ '--force to delete it and everything in it unread.');
173
+ }
174
+ const live = await (0, capabilities_1.workspaceNamespaces)(context);
175
+ if (live === null) {
176
+ throw new errors_1.ConflictError(`cannot tell what cluster ${names_1.CLUSTER_NAME} still holds: the namespace list ` +
177
+ "could not be read. Refusing to delete a cluster that may hold somebody's " +
178
+ 'workspace — check the cluster, or pass --force to take it and everything in it.');
179
+ }
180
+ if (live.length > 0) {
181
+ throw new errors_1.ConflictError(`cluster ${names_1.CLUSTER_NAME} still holds ${String(live.length)} workspace ` +
182
+ `namespace(s): ${[...live].sort().slice(0, 5).join(', ')}. Remove those ` +
183
+ 'workspaces first, or pass --force to take the cluster and everything in it.');
184
+ }
185
+ }
186
+ (0, events_1.info)(emit, `deleting cluster ${names_1.CLUSTER_NAME}`, { phase: 'teardown' });
187
+ const res = await exec_1.kube.run(['kind', 'delete', 'cluster', '--name', names_1.CLUSTER_NAME], {
188
+ timeout: exports.DELETE_TIMEOUT,
189
+ own: true,
190
+ });
191
+ if (res.returncode !== 0) {
192
+ throw new errors_1.DockerError(`could not delete the cluster ${names_1.CLUSTER_NAME}: ${(0, ask_1.why)(res)}`);
193
+ }
194
+ return true;
195
+ }, { timeoutMs: exports.DELETE_TIMEOUT * 1000 });
196
+ }