@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,960 @@
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.kubeCreate = kubeCreate;
37
+ exports.settleName = settleName;
38
+ exports.settleEnv = settleEnv;
39
+ exports.resolvePairing = resolvePairing;
40
+ exports.settleAddressing = settleAddressing;
41
+ exports.certifyTheDirectory = certifyTheDirectory;
42
+ exports.planClusterStep = planClusterStep;
43
+ exports.planTls = planTls;
44
+ exports.planKubeTls = planKubeTls;
45
+ exports.writeProvisionalRecord = writeProvisionalRecord;
46
+ exports.routeTheName = routeTheName;
47
+ exports.forgetTheRouteThisCreateMade = forgetTheRouteThisCreateMade;
48
+ exports.createTheWorkspace = createTheWorkspace;
49
+ exports.buildRecord = buildRecord;
50
+ exports.recordTheRequest = recordTheRequest;
51
+ exports.writeRecordStep = writeRecordStep;
52
+ exports.finish = finish;
53
+ exports.createKubernetes = createKubernetes;
54
+ /**
55
+ * Creating a workspace on Kubernetes.
56
+ *
57
+ * Tier 5. The Kubernetes half of create, split from the Compose half because the two share a
58
+ * request and almost nothing else: this one talks to a cluster that may not exist yet, has no
59
+ * compose file to write, and publishes a name through an ingress rather than a port.
60
+ *
61
+ * Like the Compose half, this is a PLAN plus named steps rather than one function. The
62
+ * order carries decisions that each cost a real defect to learn -- the write-ahead record
63
+ * before any cluster resource exists, the cluster chosen before a byte is written, the
64
+ * core tools checked before a kind cluster is built. The order is visible at the bottom.
65
+ */
66
+ const fs = __importStar(require("node:fs/promises"));
67
+ const config = __importStar(require("../../lib/config"));
68
+ const home_1 = require("../../lib/home");
69
+ const format_1 = require("../../lib/format");
70
+ const errors_1 = require("../../lib/errors");
71
+ const events_1 = require("../../lib/events");
72
+ const presets = __importStar(require("../../lib/presets/index"));
73
+ const composite_1 = require("../../lib/presets/composite");
74
+ const ldap_1 = require("../../lib/presets/ldap");
75
+ const public_1 = require("../../lib/presets/public");
76
+ const version_spec_1 = require("../../lib/version-spec");
77
+ const versions_1 = require("../../lib/versions");
78
+ const chart_1 = require("../kube/chart");
79
+ const ownership = __importStar(require("./ownership"));
80
+ const e2ee_1 = require("../../lib/presets/e2ee");
81
+ const voice_1 = require("../../lib/presets/voice");
82
+ const endpoints_1 = require("../kube/endpoints");
83
+ const forward_1 = require("../kube/forward");
84
+ const routes_1 = require("../edge/routes");
85
+ const spec_1 = require("../edge/spec");
86
+ const namespace_1 = require("../kube/namespace");
87
+ const names_1 = require("../kube/names");
88
+ const operator_1 = require("../kube/operator");
89
+ const context_1 = require("../kube/context");
90
+ const cluster_1 = require("../kube/cluster");
91
+ const reachability_1 = require("../kube/reachability");
92
+ const tools_1 = require("../kube/tools");
93
+ const probe_1 = require("../kube/probe");
94
+ const workspace_1 = require("../kube/workspace");
95
+ const record_1 = require("../runner/record");
96
+ const paths_1 = require("../runner/paths");
97
+ const exec_1 = require("../../seams/exec");
98
+ const topology = __importStar(require("../topology"));
99
+ const tls_1 = require("../tls");
100
+ const naming = __importStar(require("./naming"));
101
+ const notes = __importStar(require("./notes"));
102
+ const ports = __importStar(require("./ports"));
103
+ const preconditions = __importStar(require("./preconditions"));
104
+ const ready_1 = require("./ready");
105
+ const request = __importStar(require("./request"));
106
+ const seeding = __importStar(require("./seeding"));
107
+ const sizing = __importStar(require("./sizing"));
108
+ const types_1 = require("./types");
109
+ const tlsplan = __importStar(require("./tlsplan"));
110
+ function bag(value) {
111
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
112
+ ? value
113
+ : {};
114
+ }
115
+ function isTruthy(value) {
116
+ if (value === null || value === undefined || value === false)
117
+ return false;
118
+ if (typeof value === 'string')
119
+ return value !== '';
120
+ if (typeof value === 'number')
121
+ return value !== 0;
122
+ if (Array.isArray(value))
123
+ return value.length > 0;
124
+ if (typeof value === 'object')
125
+ return Object.keys(value).length > 0;
126
+ return true;
127
+ }
128
+ function kubeCreate(values) {
129
+ return {
130
+ reproName: '',
131
+ reused: false,
132
+ envOverrides: {},
133
+ licensed: false,
134
+ previous: { pid: 0, port: null, scenarioForwards: {} },
135
+ previousMeta: null,
136
+ namespaceIdentity: null,
137
+ presetParams: null,
138
+ resolved: null,
139
+ recorded: 0,
140
+ wasPinned: false,
141
+ hostPort: 0,
142
+ cfg: {},
143
+ regToken: '',
144
+ bindHost: '',
145
+ root: '',
146
+ microservices: false,
147
+ presetForNotes: null,
148
+ sidePorts: {},
149
+ monitoringPorts: [],
150
+ pre: null,
151
+ plan: null,
152
+ tlsspec: null,
153
+ ktls: null,
154
+ routeIntroduced: false,
155
+ adminPassword: '',
156
+ provisional: null,
157
+ out: {},
158
+ meta: null,
159
+ groups: null,
160
+ result: {},
161
+ ...values,
162
+ };
163
+ }
164
+ /**
165
+ * When the workspace was made: kept on a re-up, which keeps its data. Stamped afresh, a backup
166
+ * taken before a `down` and re-up read as one from an earlier workspace with the same name.
167
+ */
168
+ function bornAt(previous) {
169
+ return previous?.createdAt || new Date().toISOString().slice(0, 19) + '+00:00';
170
+ }
171
+ /** The longest a namespace, a DNS label, may be. */
172
+ const NAMESPACE_MAX = 63;
173
+ /** The name, whether this is a re-create, and the capacity refusal. */
174
+ async function settleName(job) {
175
+ job.reproName = naming.deriveFor(job.req);
176
+ naming.warnNameCoerced(job.req, job.emit);
177
+ naming.announceName(job.req, job.reproName, job.emit);
178
+ naming.requireValidName(job.reproName);
179
+ // NO refusal for an existing workspace. `down` tells the user "bring it back: houston up
180
+ // ...", and this raised "already exists, down first or --force" at them -- two messages
181
+ // in the same tool contradicting each other about the same workspace. The namespace and
182
+ // its PVC survived a plain `down`, which is exactly what makes bringing it back
183
+ // meaningful.
184
+ job.reused = await (0, paths_1.exists)(job.reproName);
185
+ if (job.reused) {
186
+ (0, events_1.info)(job.emit, `'${job.reproName}' already exists — bringing it back up`, { phase: 'plan' });
187
+ }
188
+ else {
189
+ // Before anything is made: a namespace is a DNS label, 63 characters, and kubectl
190
+ // refused a longer `houston-<name>` only once the create was under way.
191
+ const namespace = (0, names_1.mintNamespace)(job.reproName);
192
+ if (namespace.length > NAMESPACE_MAX) {
193
+ const max = job.reproName.length - (namespace.length - NAMESPACE_MAX);
194
+ throw new errors_1.ValidationError(`'${job.reproName}' is too long for Kubernetes: its namespace ${namespace} is ` +
195
+ `${String(namespace.length)} characters, and a namespace holds ` +
196
+ `${String(NAMESPACE_MAX)}. Give it a shorter name: ` +
197
+ `${naming.typedRoom(job.req, job.reproName, max)}.`);
198
+ }
199
+ }
200
+ await sizing.checkCapacity(job.req, job.req.preset, job.emit);
201
+ }
202
+ /**
203
+ * The env overrides, as Compose's `buildDocument` settles them: what the workspace already
204
+ * had, then anything named on THIS run. Without the carry-forward a re-up silently dropped
205
+ * them; without this step at all, `up --env` and `--setting` were ignored on Kubernetes.
206
+ * Refused here, before anything is written, if the chart owns the key.
207
+ */
208
+ async function settleEnv(job) {
209
+ job.envOverrides = {};
210
+ job.licensed = job.req.license !== '';
211
+ if (job.reused) {
212
+ let old = null;
213
+ try {
214
+ old = await (0, record_1.readMeta)(job.reproName);
215
+ }
216
+ catch {
217
+ // half-written record; nothing to carry
218
+ }
219
+ // A different set of presets is refused, not applied over the old one: the old
220
+ // presets' objects would stay in the namespace with nothing pointing at them.
221
+ const was = old?.preset || 'default';
222
+ // Compared as SETS: a record an earlier build wrote as typed (`ldap+email`) is the same
223
+ // set as the canonical `email+ldap` this run asks for.
224
+ const asked = job.req.preset || 'default';
225
+ if (old !== null &&
226
+ old.extra.incomplete !== true &&
227
+ (0, composite_1.compositeName)((0, composite_1.namesOf)(was)) !== (0, composite_1.compositeName)((0, composite_1.namesOf)(asked))) {
228
+ throw new errors_1.ValidationError(`'${job.reproName}' runs the ${was} preset${(0, composite_1.namesOf)(was).length > 1 ? 's' : ''} and ` +
229
+ `this asks for ${job.req.preset || 'default'}. Kubernetes cannot swap presets in ` +
230
+ `place: \`houston down --name ${job.reproName} --volumes\`, then \`up\` again, or ` +
231
+ 'leave out --preset to bring it back as it was.');
232
+ }
233
+ if (old !== null) {
234
+ job.previousMeta = old;
235
+ const previous = old.extra;
236
+ const owner = Object.hasOwn(previous, 'namespace_owner')
237
+ ? previous.namespace_owner
238
+ : (previous.created_by ?? '');
239
+ const uid = Object.hasOwn(previous, 'namespace_uid') ? previous.namespace_uid : '';
240
+ if (typeof owner !== 'string' || typeof uid !== 'string') {
241
+ throw new errors_1.ConflictError(`'${job.reproName}' has an invalid namespace ownership record — refusing to replace it`);
242
+ }
243
+ job.namespaceIdentity = { uid, owner };
244
+ job.envOverrides = { ...bag(previous.env) };
245
+ // The Secret stays in the namespace across a `down`, so a re-up keeps referencing it.
246
+ job.licensed || (job.licensed = previous.licensed === true);
247
+ // HERE, not after the write-ahead record: that record replaces this one, and reading
248
+ // the forwards back from it found none -- so a re-up never retired its own forward,
249
+ // which kept the port and failed the readiness wait, and `down` lost track of both
250
+ // forwards, which then outlived the workspace holding 3000-range and side ports.
251
+ job.previous = {
252
+ pid: Number(previous.port_forward_pid ?? 0) || 0,
253
+ port: Number(old.hostPort) || null,
254
+ scenarioForwards: bag(previous.scenario_forwards),
255
+ };
256
+ // MONITORING COMES BACK WITH IT, as TLS does. The record is rewritten on a re-up and
257
+ // only an attach writes `monitoring` and the Grafana forward, so a workspace brought
258
+ // back without `--monitor` lost its Grafana link -- while the stack, its Ingress and
259
+ // the namespace label were all still there.
260
+ if (isTruthy(previous.monitoring))
261
+ job.req.monitor = true;
262
+ }
263
+ }
264
+ Object.assign(job.envOverrides, job.req.env);
265
+ (0, chart_1.refuseChartOwnedEnv)(job.envOverrides);
266
+ }
267
+ /** A version recorded for a CI build (`8.10.0.dev0`), which no release carries. */
268
+ function isDevBuild(version) {
269
+ try {
270
+ return (0, version_spec_1.parseVersion)(version).dev !== null;
271
+ }
272
+ catch {
273
+ return false;
274
+ }
275
+ }
276
+ /**
277
+ * Rocket.Chat, its MongoDB and the host port -- announced before the slow part starts.
278
+ *
279
+ * SAID BEFORE IT IS DONE, not after. The live lookup and the cluster probing below are a
280
+ * dozen kubectl round trips; together they were a minute or more of complete silence
281
+ * after the opening line.
282
+ */
283
+ async function resolvePairing(job) {
284
+ (0, events_1.info)(job.emit, `resolving Rocket.Chat ${job.req.version} and its MongoDB pairing`, {
285
+ phase: 'plan',
286
+ });
287
+ // Looked up HERE, after the announcement, where the release lookup has always gone
288
+ // online -- no longer by the front door ahead of every refusal, and no longer skipped by
289
+ // the ones that had no door to do it.
290
+ const fetcher = await request.releaseFetcher(job.req.version, job.req.offline, job.versionFetcher);
291
+ try {
292
+ job.resolved = (0, versions_1.resolve)(job.req.version, {
293
+ offline: job.req.offline,
294
+ ...(fetcher === undefined ? {} : { fetcher }),
295
+ });
296
+ }
297
+ catch (error) {
298
+ throw new errors_1.ValidationError((0, errors_1.errorText)(error));
299
+ }
300
+ // A CI BUILD IS REFUSED HERE, before a namespace or a MongoDB exists. The Rocket.Chat
301
+ // chart compares its image tag as a semantic version (`semverCompare` in the stream-hub
302
+ // template, which every render evaluates), and a build's tag -- `develop`, `pr-123` -- is
303
+ // not one: helm refused it after MongoDB was up (exit 7), and no values combination pulls
304
+ // the ghcr image instead (measured on chart 7.0.0 and 7.0.2). A recorded build (`.devN`)
305
+ // fails the same way. Docker runs them.
306
+ if (job.resolved.source === versions_1.BUILD_SOURCE || isDevBuild(job.resolved.rcVersion)) {
307
+ throw new errors_1.ValidationError(`${job.req.version} is a CI build, and the Rocket.Chat chart reads its image tag as a ` +
308
+ 'semantic version, so helm refuses a build tag. Run CI builds on Docker: `--runtime docker`.');
309
+ }
310
+ // SAID BEFORE THE BUILD, not discovered after it. `resolve()` already knows when
311
+ // releases.rocket.chat answered 404 -- it stamps `source` and the create path ignored
312
+ // it, so `up --version 99.99.99` built the whole document and failed at the pull ~90
313
+ // seconds later, leaving a workspace to clean up.
314
+ if (job.resolved.source === 'map (no such release)') {
315
+ (0, events_1.warn)(job.emit, `releases.rocket.chat has no ${job.req.version} — the pairing below ` +
316
+ 'comes from the shipped map, and the image pull will fail unless ' +
317
+ `this tag really exists (\`houston versions ${job.req.version}\`).`, { phase: 'resolve' });
318
+ }
319
+ let before = null;
320
+ if (job.reused) {
321
+ try {
322
+ before = await (0, record_1.readMeta)(job.reproName);
323
+ }
324
+ catch {
325
+ before = null;
326
+ }
327
+ }
328
+ // The flag, then -- for a workspace coming back -- the image it ran, then the box-wide
329
+ // `rc_image` (config.yaml or HOUSTON_RC_IMAGE), as Compose resolves it. Only the flag was
330
+ // read here, so a box pointed at a mirror pulled Kubernetes workspaces from Docker Hub;
331
+ // and a re-up swapped `--rc-image` (or a CI build's ghcr image) for the default
332
+ // repository, where Compose reuses the file that names it.
333
+ request.chooseImage(job.resolved, job.req.rcImage || (before === null ? '' : String(before.rcImage || '')), config.loadConfig().rc_image);
334
+ // A WORKSPACE COMES BACK AS IT WAS. A re-up re-applies the chart and MongoDB from this
335
+ // request: another version helm-moved Rocket.Chat over a database a different release had
336
+ // migrated -- downwards too, which `upgrade` refuses -- and a fresh pairing swapped the
337
+ // MongoDB image under its data. A create that never finished has nothing to keep.
338
+ const kept = before !== null && before.extra.incomplete !== true ? before : null;
339
+ if (kept !== null && kept.rcVersion !== '' && job.resolved.rcVersion !== kept.rcVersion) {
340
+ throw new errors_1.ValidationError(`'${job.reproName}' runs Rocket.Chat ${kept.rcVersion}, and this asks for ` +
341
+ `${job.resolved.rcVersion}. It comes back at its own version: \`--version ` +
342
+ `${kept.rcVersion}\`. \`houston upgrade --name ${job.reproName} --to ` +
343
+ `${job.resolved.rcVersion}\` moves it, with a backup to roll back to.`);
344
+ }
345
+ if (job.req.mongo)
346
+ (0, versions_1.applyMongoOverride)(job.resolved, job.req.mongo);
347
+ else if (kept !== null && kept.mongoTag !== '')
348
+ (0, versions_1.applyMongoOverride)(job.resolved, kept.mongoTag);
349
+ // NOR UNDER ANOTHER MONGODB. The operator keeps its data in a claim of its own, so a kept
350
+ // workspace brought back with --mongo-operator (or HOUSTON_MONGO_OPERATOR set since) came up
351
+ // on an empty database, its data in a claim nothing read -- and `down --volumes` deleted it.
352
+ if (kept !== null &&
353
+ kept.extra.mongo_managed_by === 'statefulset' &&
354
+ (0, operator_1.wouldUseOperator)(job.resolved.mongoTag, job.req.mongoOperator)) {
355
+ throw new errors_1.ValidationError(`'${job.reproName}' keeps its data in a MongoDB houston runs itself, and this would bring ` +
356
+ 'it back under the MongoDB operator, on an empty volume. Bring it back without ' +
357
+ '--mongo-operator (and with HOUSTON_MONGO_OPERATOR unset). To move it to the operator: ' +
358
+ `\`houston backup --name ${job.reproName}\`, \`down --volumes\`, then \`restore --new\` ` +
359
+ 'with the operator.');
360
+ }
361
+ // A workspace that comes back must come back at the SAME address. Allocating afresh
362
+ // moved it from :3382 to :3000 on the `up` after a `down` -- so every bookmark, every
363
+ // curl in a ticket and the URL the user had just been shown all pointed at nothing.
364
+ job.recorded = before === null ? 0 : Number(before.hostPort) || 0;
365
+ job.wasPinned = before !== null && isTruthy(before.pinned);
366
+ const publicMonitoring = Boolean(job.req.https || job.req.domain || job.req.acmeEmail) ||
367
+ (job.req.monitor && (await tlsplan.tlsFromRecord(job.reproName)) !== null);
368
+ // The side UIs' forwards, and the local Grafana's: preferred first, the next free port when
369
+ // another workspace holds one. A re-up keeps what its record holds -- its own live forwards
370
+ // hold those ports -- so its manifests render the same labels and nothing rolls.
371
+ const claim = await ports.claimSidePorts(job.reproName, requestedPreset(job), (given) => requestedPreset(job, given), {
372
+ monitoring: job.req.monitor && !publicMonitoring ? ['grafana'] : [],
373
+ reserve: job.req.port ? [job.req.port] : [],
374
+ });
375
+ for (const [whose, was, now] of claim.moved) {
376
+ (0, events_1.warn)(job.emit, `${whose}'s port ${String(was)} is claimed by another workspace now, so ` +
377
+ `'${job.reproName}' forwards it on ${String(now)}`, { phase: 'plan' });
378
+ }
379
+ job.sidePorts = claim.side;
380
+ job.monitoringPorts = claim.monitoring;
381
+ const pre = claim.pre;
382
+ // CHECKED, as Compose checks it, before anything is made. A port given here was taken on
383
+ // trust: the whole workspace deployed, the forward then found the port held, and `up`
384
+ // ended exit 8 with the workspace left running. The workspace's own recorded port stays
385
+ // its own (`pickHostPort` excludes it), so a re-up is not refused by its live forward.
386
+ job.hostPort = await ports.pickHostPort(job.req.port || job.recorded, {
387
+ ...pre,
388
+ // This runtime publishes one application forward, independent of chart replicas.
389
+ instances: 1,
390
+ ports: [...pre.ports, ...job.monitoringPorts],
391
+ }, job.reproName);
392
+ }
393
+ /**
394
+ * Resolve the actual scenario once, including ports added by its parameters: on the registry's
395
+ * ports, which side ports are allocated from, until `ports` -- the ones allocated -- rebuilds it.
396
+ */
397
+ function requestedPreset(job, ports) {
398
+ if (job.presetForNotes !== null && ports === undefined)
399
+ return job.presetForNotes;
400
+ const names = (0, composite_1.namesOf)(job.req.preset || 'default');
401
+ if (names.length > 1) {
402
+ job.presetParams = request.paramsByPreset(names, job.req.params);
403
+ job.presetForNotes = presets.loadMany(names, job.presetParams, topology.KUBERNETES, new Set(Object.keys(job.envOverrides)), ports ?? {});
404
+ }
405
+ else {
406
+ job.presetForNotes = presets.resolve(job.req.preset || 'default', topology.KUBERNETES, job.req.params, ports ?? {});
407
+ request.refuseUnknownParams(job.req.params, job.presetForNotes, job.req.preset || 'default');
408
+ }
409
+ return job.presetForNotes;
410
+ }
411
+ /** How this workspace is reached and what shape it is, in Compose's own order. */
412
+ function settleAddressing(job) {
413
+ // Same resolution order Compose uses: the flag, then the box-level config, then
414
+ // loopback. This was dropped entirely on the Kubernetes path.
415
+ job.cfg = config.loadConfig();
416
+ job.regToken = job.req.regToken || (0, format_1.toText)(job.cfg.reg_token);
417
+ if (job.req.bind)
418
+ job.bindHost = String(job.req.bind);
419
+ else if (isTruthy(job.cfg.bind_host))
420
+ job.bindHost = String(job.cfg.bind_host);
421
+ else
422
+ job.bindHost = config.DEFAULT_BIND_HOST;
423
+ // Where the forward listens: loopback, unless one other address was asked for.
424
+ job.root = `http://${request.callHost(job.bindHost)}:${String(job.hostPort)}`;
425
+ job.microservices = job.req.deployment === topology.MICROSERVICES;
426
+ // Allocation, deployment and notes share the same resolved scenario.
427
+ const built = requestedPreset(job);
428
+ const names = (0, composite_1.namesOf)(job.req.preset || 'default');
429
+ const premium = request.premiumAuthWarning(built, job.resolved?.rcVersion ?? '', job.licensed, job.regToken);
430
+ if (premium !== '')
431
+ (0, events_1.warn)(job.emit, premium, { phase: 'plan' });
432
+ const voice = request.voiceLicenceWarning(names, job.licensed, job.regToken);
433
+ if (voice !== '')
434
+ (0, events_1.warn)(job.emit, voice, { phase: 'plan' });
435
+ const samlEmail = request.samlEmailWarning(job.presetForNotes, job.resolved?.rcVersion ?? '', new Set(Object.keys(job.envOverrides)));
436
+ if (samlEmail !== '')
437
+ (0, events_1.warn)(job.emit, samlEmail, { phase: 'plan' });
438
+ }
439
+ /**
440
+ * A directory served over LDAPS or StartTLS: its certificate, as a Secret beside it. (Its side
441
+ * ports were given in `resolvePairing`, which this runtime port-forwards on this machine.)
442
+ */
443
+ async function certifyTheDirectory(job) {
444
+ const pre = job.presetForNotes;
445
+ if (pre.extra.directory_tls !== undefined) {
446
+ job.presetForNotes = (0, ldap_1.withCertificate)(pre, await tlsplan.issueDirectoryCertificate((0, ldap_1.directoryHost)(pre.extra)), topology.KUBERNETES);
447
+ }
448
+ }
449
+ /**
450
+ * Which cluster, what it would cost, and whether this box has the tools to talk to it.
451
+ *
452
+ * THE CLUSTER IS CHOSEN FIRST, before a single byte is written. `planCluster` only probes,
453
+ * and it is what refuses when there is no cluster and no `kind` -- so that refusal now
454
+ * costs nothing, where before it left an `incomplete` record that `list` showed as a
455
+ * workspace and whose port `usedPorts()` went on reserving.
456
+ *
457
+ * THE CORE TOOLS FIRST, before anything is provisioned: with `kubectl` absent, `up` built
458
+ * an entire kind cluster, THEN failed, and blamed the API server.
459
+ */
460
+ async function planClusterStep(job) {
461
+ job.pre = await (0, probe_1.preflight)();
462
+ const missing = (0, tools_1.missingTools)(job.pre);
463
+ if (missing.length > 0) {
464
+ throw new errors_1.PreflightError(`${missing.join(', ')} is not installed, and a Kubernetes ` +
465
+ 'workspace cannot be created or used without it. Install it and try ' +
466
+ 'again — `houston doctor` lists what this runtime needs.');
467
+ }
468
+ job.plan = await (0, context_1.planCluster)(request.reqContext(job.req));
469
+ // A BILLABLE CLUSTER AND NO PUBLIC NAME. Warned, not refused, and the distinction
470
+ // matters: a refusal would remove the one way to reach a workspace whose ingress is
471
+ // broken, which is exactly when somebody needs it.
472
+ if (types_1.BILLABLE_DISTRIBUTIONS.includes(job.plan.distribution) && !(job.req.domain || '').trim()) {
473
+ (0, events_1.warn)(job.emit, `'${job.plan.context}' is a ${job.plan.distribution} cluster, and without --domain ` +
474
+ 'this workspace opens only in a browser on the machine running houston, through a ' +
475
+ 'port-forward that ends when its pod restarts. ' +
476
+ '`--domain <name>` gives it a publicly-trusted address instead.', { phase: 'preflight' });
477
+ }
478
+ }
479
+ /** The HTTPS name, and which of the two mechanisms will serve it. */
480
+ async function planTls(job) {
481
+ job.tlsspec = await tlsplan.resolveTls(job.req, job.reproName, job.bindHost, job.reproName, job.emit);
482
+ job.ktls = null;
483
+ if (job.plan !== null && !job.plan.create) {
484
+ // THE PREFLIGHT NEEDS A KUBECONFIG THAT KNOWS THIS CONTEXT, and on a fresh
485
+ // HOUSTON_HOME it does not have one: the cluster exists, so nothing was created, so
486
+ // nothing exported the context this is about to ask through. Idempotent, and a no-op
487
+ // for a cluster houston did not make.
488
+ await (0, cluster_1.ensureKubeconfig)(job.plan, job.emit);
489
+ // HELM'S OWN ANSWER, and this is the cheapest refusal on the path. houston drives
490
+ // kubectl AND helm, they resolve their configuration differently, and only kubectl was
491
+ // ever asked. Measured: kubectl completely happy while helm refused every call with
492
+ // `x509: certificate signed by unknown authority`, so the create built a namespace, a
493
+ // StatefulSet, a PersistentVolume and an initiated replica set, spent four minutes,
494
+ // then died at the chart and rolled all of it back.
495
+ const helmWhy = await (0, reachability_1.helmReachable)(job.plan.context);
496
+ if (helmWhy) {
497
+ throw new errors_1.ValidationError(`helm cannot reach cluster '${job.plan.context}', although kubectl can. ` +
498
+ 'The chart install would fail after MongoDB and roll the whole ' +
499
+ `workspace back. helm said: ${helmWhy} — a kubeconfig left over ` +
500
+ 'from a previous install of the same cluster does this. Regenerate ' +
501
+ 'it (k3s: `sudo cat /etc/rancher/k3s/k3s.yaml > ~/.kube/config`; ' +
502
+ 'kind: `kind export kubeconfig --name <cluster>`) and run this ' +
503
+ 'again. `houston doctor` reports the same thing.');
504
+ }
505
+ await (0, namespace_1.assertNamespaceAvailable)(job.reproName, {
506
+ context: job.plan.context,
507
+ owner: job.req.actor,
508
+ });
509
+ }
510
+ }
511
+ /** What the in-cluster ingress needs, when the edge is not the thing serving the name. */
512
+ async function planKubeTls(job) {
513
+ if (job.tlsspec !== null) {
514
+ // Named before the probing starts. `kubernetesTlsPlan` asks the cluster about its
515
+ // ingress classes, its cert-manager CRD and its ingress endpoint before it emits
516
+ // anything, which on a managed cluster is several seconds of nothing at the exact
517
+ // moment the reader is waiting to learn where HTTPS is coming from.
518
+ (0, events_1.info)(job.emit, `checking ${job.plan?.context ?? ''} for the ingress and cert-manager HTTPS ` + 'needs', { phase: 'tls' });
519
+ // AFTER `ensureKubeconfig`, because every probe in it needs a kubeconfig that knows
520
+ // the context, and BEFORE the write-ahead record, because a refusal must leave
521
+ // nothing.
522
+ job.ktls = await tlsplan.kubernetesTlsPlan(job.req, job.tlsspec, job.plan, {
523
+ emit: job.emit,
524
+ });
525
+ // Said, not dropped: with a name the chart writes ROOT_URL from it, and a second entry
526
+ // would be a server-side-apply conflict (`validateRootAddress`).
527
+ if (job.req.rootUrl) {
528
+ (0, events_1.warn)(job.emit, `--root-url ${job.req.rootUrl} is not applied: on Kubernetes with HTTPS, Rocket.Chat's ` +
529
+ `ROOT_URL is https://${job.ktls.host}, which the chart sets from the name.`, { phase: 'tls' });
530
+ }
531
+ // A preset's own UIs at paths of that name; `installChart` routes them with an Ingress.
532
+ if (job.presetForNotes !== null) {
533
+ job.presetForNotes = (0, public_1.withPublicUrl)(job.presetForNotes, `https://${job.ktls.host}`, topology.KUBERNETES);
534
+ const presigned = (0, public_1.presignedOverHttps)(job.presetForNotes);
535
+ if (presigned)
536
+ (0, events_1.warn)(job.emit, presigned, { phase: 'tls' });
537
+ }
538
+ }
539
+ }
540
+ /** A record BEFORE any cluster resource exists, so a killed create leaves something. */
541
+ async function writeProvisionalRecord(job) {
542
+ // A WRITE-AHEAD RECORD, before a single cluster resource exists. `createWorkspace`
543
+ // below builds the namespace, MongoDB, the chart release, the scenario's manifests and
544
+ // the port-forward -- minutes of work -- and only after it returned was anything written
545
+ // down. Kill the process in that window and the workspace is left fully running with NO
546
+ // record: invisible to `list`, `info` and `down`. Two such orphans were found holding
547
+ // several GB between them.
548
+ // A workspace brought back keeps its PersistentVolumeClaim, so its database's password too.
549
+ const kept = job.reused ? await (0, record_1.keptAdminPassword)(job.reproName) : null;
550
+ const reachable = preconditions.reachableBeyondLoopback({
551
+ tlsspec: job.tlsspec,
552
+ bindHost: job.bindHost,
553
+ });
554
+ job.adminPassword = kept ?? (reachable ? config.generateAdminPassword() : '');
555
+ const shared = request.keptSharedPasswordWarning(job.reproName, kept, reachable);
556
+ if (shared !== '')
557
+ (0, events_1.warn)(job.emit, shared, { phase: 'plan' });
558
+ const resolved = job.resolved;
559
+ const plan = job.plan;
560
+ job.provisional = (0, record_1.metadata)({
561
+ name: job.reproName,
562
+ project: await (0, namespace_1.namespaceFor)(job.reproName),
563
+ rcVersion: resolved.rcVersion,
564
+ rcImage: resolved.rcImage,
565
+ mongoTag: resolved.mongoTag,
566
+ mongoFlavor: resolved.mongoFlavor,
567
+ preset: job.req.preset,
568
+ rootUrl: job.root,
569
+ hostPort: job.hostPort,
570
+ versionSource: resolved.source,
571
+ pinned: job.req.pin || job.wasPinned,
572
+ adminPassword: job.adminPassword,
573
+ createdAt: bornAt(job.previousMeta),
574
+ });
575
+ topology.stamp(job.provisional.extra, topology.KUBERNETES);
576
+ job.provisional.extra[config.EXTRA_DEPLOYMENT] = job.req.deployment || topology.MICROSERVICES;
577
+ job.provisional.extra.namespace = await (0, namespace_1.namespaceFor)(job.reproName);
578
+ if (job.namespaceIdentity !== null) {
579
+ job.provisional.extra.namespace_owner = job.namespaceIdentity.owner;
580
+ if (job.namespaceIdentity.uid !== '') {
581
+ job.provisional.extra.namespace_uid = job.namespaceIdentity.uid;
582
+ }
583
+ }
584
+ // The chosen context, not a guess at it. This was `CONTEXT` unconditionally, which was
585
+ // right only while houston's own cluster was the only one it could use.
586
+ job.provisional.extra[config.EXTRA_CONTEXT] = plan.context;
587
+ job.provisional.extra.distribution = plan.distribution;
588
+ // A RE-UP OF A FINISHED WORKSPACE IS NOT A HALF-MADE ONE. Marked incomplete, a re-up that
589
+ // failed left the flag behind, and the next `up` skipped the checks that keep a workspace's
590
+ // version, MongoDB and presets -- the ones a half-made workspace has nothing to keep for.
591
+ job.provisional.extra.incomplete =
592
+ job.previousMeta === null || job.previousMeta.extra.incomplete === true;
593
+ if (job.req.actor)
594
+ job.provisional.extra.created_by = job.req.actor;
595
+ // In the write-ahead record too: a re-up after a killed create carries forward from it.
596
+ if (Object.keys(job.envOverrides).length > 0)
597
+ job.provisional.extra.env = job.envOverrides;
598
+ if (job.licensed)
599
+ job.provisional.extra.licensed = true;
600
+ // Still recorded while the create runs, so a create killed part-way leaves `down` able to
601
+ // stop them.
602
+ if (job.previous.pid !== 0)
603
+ job.provisional.extra.port_forward_pid = job.previous.pid;
604
+ if (Object.keys(job.previous.scenarioForwards).length > 0) {
605
+ job.provisional.extra.scenario_forwards = job.previous.scenarioForwards;
606
+ }
607
+ // Claimed from the write-ahead record on, so a concurrent create sees them.
608
+ const sidePorts = job.presetForNotes.ports;
609
+ if (sidePorts.length > 0)
610
+ job.provisional.extra.sidecar_ports = sidePorts;
611
+ if (Object.keys(job.sidePorts).length > 0)
612
+ job.provisional.extra.side_ports = job.sidePorts;
613
+ if (job.monitoringPorts.length > 0) {
614
+ job.provisional.extra.monitoring_ports = [...job.monitoringPorts];
615
+ }
616
+ ownership.carryOwnership(job.previousMeta, job.provisional);
617
+ // Through the runner seam, so the workspace directory is restricted to 0700 the way
618
+ // every Compose one is. This runtime is the one that also writes `kubernetes/values.yaml`
619
+ // with ADMIN_PASS in it.
620
+ await (0, record_1.writeRecord)(job.reproName, job.provisional);
621
+ }
622
+ /**
623
+ * The name on the edge, BEFORE the create, so an ACME challenge has somewhere to land the
624
+ * moment the chart's Ingress appears. Inside the create's rollback: the edge refusing to
625
+ * start (another home's edge holds :443) left the write-ahead record of a workspace that
626
+ * never existed, and the retry reused it.
627
+ */
628
+ async function routeTheName(job) {
629
+ if (job.ktls === null)
630
+ return;
631
+ job.routeIntroduced = (0, routes_1.routeHost)(job.reproName) === '';
632
+ await tlsplan.routeKubernetesName(job.reproName, job.ktls, { emit: job.emit });
633
+ }
634
+ /**
635
+ * A failed create takes back the edge route it registered, as the cluster side takes back
636
+ * the namespace. The route goes in BEFORE the create, so an ACME challenge has somewhere to
637
+ * land; left behind, it sent the name to a NodePort the rollback had already deleted
638
+ * (measured on a k3s playground, 2026-10-06). The record stays, as it always has, so
639
+ * `list` and `down` still find the workspace; a route that was there before this create --
640
+ * a workspace being re-created -- stays too.
641
+ */
642
+ function forgetTheRouteThisCreateMade(job) {
643
+ if (job.ktls === null || !job.routeIntroduced || (0, routes_1.routeHost)(job.reproName) === '')
644
+ return;
645
+ (0, routes_1.deregister)(job.reproName);
646
+ (0, events_1.warn)(job.emit, `create failed — removing the edge route for ${job.ktls.host}`, {
647
+ phase: 'teardown',
648
+ });
649
+ }
650
+ /**
651
+ * A fresh create that left no namespace leaves no record either.
652
+ *
653
+ * The rollback removes the namespace a failed or stopped create made, and the write-ahead
654
+ * record stayed: a "down" workspace that claimed its port and its preset's side ports --
655
+ * the next create wanting 8025 was refused for it -- and whose panel said its data volume
656
+ * was "still here". Nothing was. A workspace coming back keeps its record; so does one whose
657
+ * namespace survived, or could not be asked about.
658
+ */
659
+ async function forgetARecordWithNothingBehindIt(job) {
660
+ if (job.reused || job.plan === null)
661
+ return;
662
+ let labels;
663
+ try {
664
+ labels = await (0, namespace_1.namespaceLabels)(await (0, namespace_1.namespaceFor)(job.reproName), {
665
+ context: job.plan.context,
666
+ });
667
+ }
668
+ catch {
669
+ return; // could not ask: the record stays, and says what it knows
670
+ }
671
+ if (labels !== null)
672
+ return;
673
+ await (0, paths_1.remove)(job.reproName);
674
+ (0, events_1.warn)(job.emit, `nothing of '${job.reproName}' was left in the cluster, so its record goes too — ` +
675
+ 'its ports are free again', { phase: 'teardown', code: events_1.NOTHING_LEFT });
676
+ }
677
+ /** The namespace, MongoDB, the chart release and the port-forward -- the long part. */
678
+ async function createTheWorkspace(job) {
679
+ const ns = await (0, namespace_1.namespaceFor)(job.reproName);
680
+ // The preset UIs' forwards are re-made below; the old ones would keep their ports.
681
+ for (const [port, pid] of Object.entries(job.previous.scenarioForwards)) {
682
+ await (0, forward_1.stopForward)(Number(pid) || 0, { namespace: ns, hostPort: Number(port) || null });
683
+ }
684
+ const resolved = job.resolved;
685
+ job.out = await (0, workspace_1.createWorkspace)({
686
+ name: job.reproName,
687
+ resolved,
688
+ hostPort: job.hostPort,
689
+ microservices: job.microservices,
690
+ replicas: job.req.replicas || 1,
691
+ owner: job.req.actor,
692
+ bindHost: job.bindHost,
693
+ adminPassword: job.adminPassword,
694
+ previousPid: job.previous.pid,
695
+ previousPort: job.previous.port,
696
+ // PASSED AT LAST. `createWorkspace` has taken `rootUrl` since it was written and this
697
+ // call never supplied it, so `valuesFor` never set anything and the chart emitted no
698
+ // ROOT_URL -- Rocket.Chat ran on its own default while every human reached it here.
699
+ // `--root-url` is what Rocket.Chat advertises, as on Compose; houston's own calls keep
700
+ // the forward (`job.root`). It was dropped here, so Site_Url stayed on loopback.
701
+ rootUrl: job.req.rootUrl || job.root,
702
+ // With a name, the chart's own Ingress template builds the Ingress -- houston
703
+ // hand-writes none.
704
+ tlsHost: job.ktls?.host ?? '',
705
+ ingressClass: job.ktls?.ingressClass ?? '',
706
+ issuer: job.ktls?.issuer ?? null,
707
+ useOperator: job.req.mongoOperator,
708
+ // Through a Secret referenced by `valueFrom`, never as a values literal: `helm get
709
+ // values` is readable by anyone who can reach the release.
710
+ regToken: job.regToken,
711
+ // Resolved through the KUBERNETES adapter, so a scenario yields native manifests here
712
+ // and a compose service on the other runtime -- one intent, two renderings.
713
+ preset: job.presetForNotes,
714
+ envOverrides: job.envOverrides,
715
+ license: job.req.license,
716
+ licensed: job.licensed,
717
+ plan: job.plan,
718
+ emit: job.emit,
719
+ });
720
+ }
721
+ /** `repro.json` as it stands once the cluster has answered. */
722
+ async function buildRecord(job) {
723
+ const resolved = job.resolved;
724
+ const plan = job.plan;
725
+ job.meta = (0, record_1.metadata)({
726
+ name: job.reproName,
727
+ project: String(job.out.namespace ?? ''),
728
+ rcVersion: resolved.rcVersion,
729
+ rcImage: resolved.rcImage,
730
+ mongoTag: resolved.mongoTag,
731
+ // NOT `resolved.mongoFlavor`. That is a COMPOSE concept -- "official" vs
732
+ // "bitnami-legacy" -- and this runtime honours neither: `createWorkspace` records
733
+ // `mongo_managed_by` and `mongo_image` for exactly this reason.
734
+ mongoFlavor: '',
735
+ preset: job.req.preset,
736
+ rootUrl: job.root,
737
+ hostPort: job.hostPort,
738
+ versionSource: resolved.source,
739
+ pinned: job.req.pin || job.wasPinned,
740
+ adminPassword: job.adminPassword,
741
+ createdAt: bornAt(job.previousMeta),
742
+ });
743
+ // What Rocket.Chat advertises, under the key Compose records it: `externalUrl`, the notes and
744
+ // a re-up (`carryRecordedAxes`) read it. Not with a TLS name, which the chart writes itself.
745
+ if (job.ktls === null && job.req.rootUrl && job.req.rootUrl !== job.root) {
746
+ job.meta.extra.advertised_url = job.req.rootUrl;
747
+ }
748
+ // The preset's own record fields -- `mailpit_url`, which `admin.login` reads to fetch an
749
+ // email-2FA code, so without it every login to an email workspace here failed at 2FA.
750
+ // BEFORE the runtime's stamps, so a preset cannot overwrite them.
751
+ const pre = job.presetForNotes;
752
+ Object.assign(job.meta.extra, pre.extra);
753
+ if (pre.ports.length > 0)
754
+ job.meta.extra.sidecar_ports = pre.ports;
755
+ // Only what moved, in BOTH records: a re-up reads it back to render the same labels.
756
+ if (Object.keys(job.sidePorts).length > 0)
757
+ job.meta.extra.side_ports = job.sidePorts;
758
+ if (job.monitoringPorts.length > 0) {
759
+ job.meta.extra.monitoring_ports = [...job.monitoringPorts];
760
+ }
761
+ topology.stamp(job.meta.extra, topology.KUBERNETES);
762
+ job.meta.extra[config.EXTRA_DEPLOYMENT] = job.req.deployment || topology.MICROSERVICES;
763
+ for (const [key, value] of Object.entries(job.out)) {
764
+ if (key !== 'microservices')
765
+ job.meta.extra[key] = value;
766
+ }
767
+ // WHAT kind of cluster this workspace lives in. A label, never a branch -- it is what
768
+ // lets `doctor`, the notes and a support case say "k3s" instead of leaving a reader to
769
+ // infer it from a context name.
770
+ job.meta.extra.distribution = plan.distribution;
771
+ if (job.ktls !== null) {
772
+ // The SAME three fields the Compose path records, so `list`, `info`, `reproLinks`, the
773
+ // GUI grid and `tls-status` all work on a Kubernetes workspace for free. `rootUrl`
774
+ // deliberately stays the plain http port-forward URL; `publicUrl` is what a human opens.
775
+ job.meta.publicUrl = `https://${job.ktls.host}`;
776
+ job.meta.extra.tls = job.ktls.issuer?.mode === 'acme' ? tls_1.MODE_ACME : 'local';
777
+ if (job.ktls.issuer?.mode === 'acme') {
778
+ job.meta.extra.tls_staging = Boolean(job.ktls.issuer.acmeStaging);
779
+ job.meta.extra.tls_email = job.ktls.issuer.acmeEmail ?? '';
780
+ }
781
+ // `edge` means "a route file speaks for this name". It is what `noteGroupsOf` keys the
782
+ // HTTPS card on, and it is false in the topology where the cluster holds :443 itself
783
+ // and no edge is involved at all.
784
+ job.meta.extra.edge = (0, spec_1.installed)();
785
+ // Where TLS actually terminates, which is the one thing genuinely different from
786
+ // Compose: the certificate is a cluster Secret issued by cert-manager, not a file the
787
+ // edge loaded.
788
+ job.meta.extra.tls_terminates = 'cluster';
789
+ job.meta.extra.ingress_endpoint = (0, endpoints_1.endpointString)(job.ktls.endpoint);
790
+ job.meta.extra.ingress_class = job.ktls.ingressClass;
791
+ // `certificate_ready` decides how a fallback certificate is EXPLAINED. It was computed
792
+ // here all along and thrown away, so the check that reports the result did not know
793
+ // whether one had ever been issued.
794
+ await tlsplan.publishKubernetesName(job.reproName, job.ktls, {
795
+ certReady: Boolean(job.out.certificate_ready),
796
+ emit: job.emit,
797
+ });
798
+ }
799
+ // A re-up that moves the address keeps the database's Site_Url, which `ready` moves once.
800
+ const was = job.previousMeta;
801
+ if (was !== null && (0, record_1.externalUrl)(was) !== (0, record_1.externalUrl)(job.meta)) {
802
+ job.meta.extra.site_url_moved_from = (0, record_1.externalUrl)(was);
803
+ }
804
+ }
805
+ /** What was ASKED for, so the workspace can be rebuilt exactly as it was. */
806
+ function recordTheRequest(job) {
807
+ const meta = job.meta;
808
+ if (job.req.replicas > 1)
809
+ meta.extra.instances = job.req.replicas;
810
+ if (job.req.actor)
811
+ meta.extra.created_by = job.req.actor;
812
+ // Recorded so the notes can be REBUILT from the record rather than read back out of it
813
+ // -- a dynamic scenario's prose is a function of its params, and nothing was keeping them.
814
+ if (job.presetParams !== null) {
815
+ // As Compose records a composed workspace: one preset string, the list and its params.
816
+ meta.extra.presets = (0, composite_1.namesOf)(job.req.preset);
817
+ meta.extra.preset_params = structuredClone(job.presetParams);
818
+ }
819
+ else if (Object.keys(job.req.params).length > 0) {
820
+ meta.extra.params = { ...job.req.params };
821
+ }
822
+ // The same key Compose records them under, so re-up, `backup` and `restore --new` carry them.
823
+ if (Object.keys(job.envOverrides).length > 0)
824
+ meta.extra.env = job.envOverrides;
825
+ if (job.licensed)
826
+ meta.extra.licensed = true;
827
+ // A token, never its text: the notes stop asking for a licence a registration may bring.
828
+ if (job.regToken)
829
+ meta.extra.registered = true;
830
+ // A preset's self-configuration actions, recorded exactly as the Compose path records
831
+ // them. Without this the OIDC preset would create no OAuth provider and the SAML preset
832
+ // no provider settings -- both recorded and neither applied.
833
+ const postReady = job.presetForNotes?.postReady;
834
+ if (postReady !== undefined && postReady.length > 0)
835
+ meta.extra.post_ready = postReady;
836
+ ownership.carryOwnership(job.provisional ?? job.previousMeta, meta);
837
+ }
838
+ /** The notes a reader needs, then the record -- and no compose file, because it is not one. */
839
+ async function writeRecordStep(job) {
840
+ const meta = job.meta;
841
+ job.groups = await notes.noteGroupsOf(meta);
842
+ // THE GROUPS ARE NOT PERSISTED. They are rendered presentation -- roughly 5.5 KB of a
843
+ // 6.4 KB Kubernetes record, the same content as `notes` a second time, and including an
844
+ // absolute `export KUBECONFIG=<home>/clients/kubernetes/config` that is wrong the moment
845
+ // the home moves.
846
+ delete meta.extra.note_groups;
847
+ // Derived, never written twice: the CLI and every workspace record made before groups
848
+ // existed read this.
849
+ meta.extra.notes = notes.flattenNotes(job.groups);
850
+ // No compose document, so an empty one rather than a fake: a file that looks like a
851
+ // compose project but is not would be worse than none.
852
+ const ws = (0, paths_1.workspace)(job.reproName);
853
+ await fs.mkdir(ws, { recursive: true });
854
+ // `serialise(meta)`, as every record is written: the record's one spelling, not
855
+ // JSON.stringify's.
856
+ await (0, paths_1.atomicWrite)((0, home_1.joinPath)(ws, 'repro.json'), (0, record_1.serialise)(meta));
857
+ }
858
+ /** Waiting, seeding, monitoring, and the line the caller reads at the end. */
859
+ async function finish(job) {
860
+ const meta = job.meta;
861
+ job.result = {
862
+ name: job.reproName,
863
+ meta: (0, record_1.toDocument)(meta),
864
+ url: job.root,
865
+ // The two a caller opens, as the Compose create's summary names them: the GUI's create
866
+ // dialog offered no address at all for a Kubernetes workspace, and `up --json` none to
867
+ // a script.
868
+ root_url: meta.rootUrl,
869
+ public_url: meta.publicUrl,
870
+ open_url: (0, record_1.externalUrl)(meta),
871
+ reused: job.reused,
872
+ runtime: topology.KUBERNETES,
873
+ };
874
+ // A preset with post_ready actions MUST wait, or there is nothing to configure against.
875
+ if (job.req.wait || job.req.seed || isTruthy(meta.extra.post_ready)) {
876
+ // waitAndFinalize, not bare waitServing: it also finalizes the setup wizard over REST
877
+ // and runs the preset's post_ready actions. Waiting and stopping there left every
878
+ // self-configuring preset half-applied.
879
+ Object.assign(job.result, await (0, ready_1.waitAndFinalize)(meta, job.emit, 600.0, false));
880
+ job.result.ready = true;
881
+ }
882
+ // NOT when the caller seeds. `seedHere` means the CLI runs it after this returns, so
883
+ // seeding here as well would seed the workspace twice.
884
+ if (job.req.seed && !job.req.seedHere) {
885
+ job.result.seed = await seeding.runSeedInline(meta, job.req.seedProfile, job.req.stats, job.emit, { scenarios: job.req.seedScenarios, historyDays: job.req.seedHistoryDays });
886
+ }
887
+ // `--monitor` last, and only once the workspace is serving: attaching turns on RC's own
888
+ // Prometheus_Enabled over REST, which needs a workspace that answers.
889
+ if (job.req.monitor) {
890
+ if (!(job.req.wait || job.req.seed)) {
891
+ await (0, ready_1.waitServing)(meta, job.emit, 600.0);
892
+ }
893
+ // An add-on failing does not un-create the workspace. The first live run of this
894
+ // failed on the monitoring chart and exited 7 with the workspace up, serving, and
895
+ // listed as running -- a create reported as failed while its result was sitting there
896
+ // working.
897
+ try {
898
+ job.result.monitoring = await job.monitorAttach(job.reproName, job.emit);
899
+ }
900
+ catch (error) {
901
+ if (!(error instanceof errors_1.ReproError))
902
+ throw error;
903
+ (0, events_1.warn)(job.emit, `the workspace is up, but monitoring did not attach: ${error.message}`, {
904
+ phase: 'monitor',
905
+ });
906
+ (0, events_1.warn)(job.emit, `retry it with: houston monitor --name ${job.reproName}`, {
907
+ phase: 'monitor',
908
+ });
909
+ job.result.monitoring = { monitoring: false, error: error.message };
910
+ }
911
+ }
912
+ (0, events_1.info)(job.emit, `${job.root} admin / ${(0, record_1.adminPass)(meta)}`, { phase: 'done', pct: 100 });
913
+ return job.result;
914
+ }
915
+ /**
916
+ * The Kubernetes half of `createReproLocked`.
917
+ *
918
+ * Shares everything that is not runtime-specific -- name derivation, version resolution,
919
+ * the capacity refusal, host-port allocation, repro.json -- and delegates only the
920
+ * sequence that differs. A workspace created here is a workspace like any other: `list`,
921
+ * `info`, `logs` and `down` find it because it has a repro.json.
922
+ */
923
+ async function createKubernetes(req, emit = events_1.nullEmit, { monitorAttach = request.missingMonitorAttach, versionFetcher, } = {}) {
924
+ const job = kubeCreate({
925
+ req,
926
+ emit,
927
+ monitorAttach,
928
+ ...(versionFetcher === undefined ? {} : { versionFetcher }),
929
+ });
930
+ await settleName(job);
931
+ await settleEnv(job);
932
+ await ports.withPortPublication(async () => {
933
+ await resolvePairing(job);
934
+ settleAddressing(job);
935
+ // Before the cluster is probed or anything is written.
936
+ (0, e2ee_1.refuseEnforcedBefore880)(requestedPreset(job), job.resolved.rcVersion);
937
+ (0, voice_1.refuseVoiceBefore800)(requestedPreset(job), job.resolved.rcVersion);
938
+ await certifyTheDirectory(job);
939
+ await planClusterStep(job);
940
+ await planTls(job);
941
+ await planKubeTls(job);
942
+ await writeProvisionalRecord(job);
943
+ });
944
+ try {
945
+ await routeTheName(job);
946
+ await createTheWorkspace(job);
947
+ }
948
+ catch (error) {
949
+ forgetTheRouteThisCreateMade(job);
950
+ // As cleanup, so a stopped job's unwind runs it to the end, as the rollback does.
951
+ await (0, exec_1.cleanup)(async () => {
952
+ await forgetARecordWithNothingBehindIt(job);
953
+ });
954
+ throw error;
955
+ }
956
+ await buildRecord(job);
957
+ recordTheRequest(job);
958
+ await writeRecordStep(job);
959
+ return await finish(job);
960
+ }