@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,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRESENT = exports.ABSENT = exports.REFUSED = void 0;
4
+ exports.answer = answer;
5
+ exports.present = present;
6
+ exports.absent = absent;
7
+ exports.refused = refused;
8
+ exports.items = items;
9
+ exports.why = why;
10
+ exports.answerWhy = answerWhy;
11
+ exports.require_ = require_;
12
+ exports.classify = classify;
13
+ exports.askObject = askObject;
14
+ exports.askList = askList;
15
+ /**
16
+ * A three-valued answer, because a refused read is not an empty one.
17
+ *
18
+ * Tier k1. `Answer` is PRESENT, ABSENT or REFUSED, and the whole module exists so a caller
19
+ * cannot write `if (askObject(...))` and silently treat "the cluster would not say" as "it is
20
+ * not there". That conflation is the defect `namespaceLabels` was fixed for in v0.70.9 and
21
+ * the one this vocabulary exists to make unwritable.
22
+ *
23
+ * ## Why this is a discriminated union and not a class
24
+ *
25
+ * The previous implementation's `Answer` refuses a truth test with a `TypeError`, which
26
+ * makes `if answer:` a runtime error at the moment it is written. TypeScript has no
27
+ * equivalent: EVERY object is truthy in a condition, a phantom brand does not change that,
28
+ * and removing `valueOf` and `toString` does not either -- so the failure mode here is a
29
+ * silent `true` rather than a raise. The collapse that deleted a live cluster happened at a
30
+ * CONSUMER, which is exactly where a silent `true` would land.
31
+ *
32
+ * Two things replace the raise, and they are both needed:
33
+ *
34
+ * 1. `Answer<T>` is a discriminated union on `state`, so a consumer that wants a
35
+ * document has to narrow before it can read one. That is the type system doing what
36
+ * it can.
37
+ * 2. `@typescript-eslint/strict-boolean-expressions` with objects disallowed makes
38
+ * `if (answer)` an ERROR rather than a silent always-true. That is the part a type
39
+ * cannot do, and `yarn lint:truthiness` plants the misuse in a real consumer OUTSIDE
40
+ * this package, requires lint to reject that exact line, and restores the tree --
41
+ * because a rule nobody has tried to break is a rule nobody knows is on.
42
+ *
43
+ * Consumers switch on `answer.state` or use the `present`/`absent`/`refused` guards.
44
+ */
45
+ const errors_1 = require("../../lib/errors");
46
+ const exec_1 = require("./exec");
47
+ const names_1 = require("./names");
48
+ /**
49
+ * The three answers an external tool can give about a thing, and the reason this module
50
+ * has a type for them at all. `namespaceLabels` has said it since it was written -- "'I
51
+ * could not ask' and 'it is not there' are different answers and only one of them is
52
+ * safe to act on" -- and it was the ONLY function that implemented it. Five others
53
+ * collapsed the three back to two, each by reading a non-zero exit as a negative answer,
54
+ * and that one habit produced a `down --volumes` that deleted a workspace's record while
55
+ * its namespace was still there, a `prune` that reported namespaces reclaimed that were
56
+ * still Terminating, and a `doctor` that reported "0 nodes, no StorageClass, no ingress"
57
+ * for a cluster with all three.
58
+ *
59
+ * MEASURED, not assumed: kubectl exits 1 for BOTH "namespace absent" and "context does
60
+ * not exist", so no threshold on the exit code can separate them.
61
+ */
62
+ exports.REFUSED = 'refused';
63
+ exports.ABSENT = 'absent';
64
+ exports.PRESENT = 'present';
65
+ function answer(state, doc = null, res) {
66
+ const base = res === undefined ? {} : { res };
67
+ if (state === exports.PRESENT)
68
+ return { state: exports.PRESENT, doc: doc ?? {}, ...base };
69
+ if (state === exports.ABSENT)
70
+ return { state: exports.ABSENT, doc: null, ...base };
71
+ return { state: exports.REFUSED, doc: null, ...base };
72
+ }
73
+ function present(value) {
74
+ return value.state === exports.PRESENT;
75
+ }
76
+ function absent(value) {
77
+ return value.state === exports.ABSENT;
78
+ }
79
+ function refused(value) {
80
+ return value.state === exports.REFUSED;
81
+ }
82
+ /**
83
+ * The objects of a list read; empty for a list that legitimately holds none.
84
+ *
85
+ * Empty is only ever "the cluster has none of these" -- a refused read never reaches
86
+ * here, because `refused` is a separate state and not an empty list. That equivalence is
87
+ * exactly what made `doctor` report "0 nodes".
88
+ */
89
+ function items(value) {
90
+ const raw = value.doc?.items;
91
+ return Array.isArray(raw) ? raw : [];
92
+ }
93
+ /**
94
+ * The line that explains a failure, not the first 400 characters of noise.
95
+ *
96
+ * Written after a `helm install` failure reported two harmless warnings and hid its own
97
+ * reason. Every tool here puts its diagnostics FIRST and its error LAST -- helm emits
98
+ * klog warnings then `Error: ...`, kubectl emits deprecation notices then the message --
99
+ * so taking a prefix reliably shows the least useful part.
100
+ */
101
+ function why(res, { limit = 400 } = {}) {
102
+ const text = `${res?.stderr ?? ''}\n${res?.stdout ?? ''}`;
103
+ const raw = text.split('\n').filter((line) => line.trim() !== '');
104
+ const lines = raw.map((line) => line.trim());
105
+ if (lines.length === 0)
106
+ return 'no reason given';
107
+ let named = [];
108
+ for (const [index, line] of lines.entries()) {
109
+ if (/^(error|Error|ERROR|fatal|Fatal)\b/u.test(line) || line.toLowerCase().includes('error:')) {
110
+ named.push(index);
111
+ }
112
+ }
113
+ // Warnings are not errors, however loudly they are printed. klog prefixes them with
114
+ // I/W and a timestamp, and helm's install failure sits after them.
115
+ named = named.filter((index) => !/^[IWD]\d{4} /u.test(lines[index] ?? ''));
116
+ const at = named.length > 0 ? named[named.length - 1] : lines.length - 1;
117
+ // THE CONTINUATION LINES ARE THE REASON, and they were being thrown away. The premise
118
+ // above -- diagnostics first, error last -- holds for klog and inverts for a Helm
119
+ // TEMPLATE error, which announces the location on the `Error:` line and puts the cause
120
+ // on the indented lines after it. So the file and line survived and "nil pointer" did
121
+ // not. Indentation is the signal helm itself uses, and a line that starts a new
122
+ // diagnostic is never indented.
123
+ const chosen = [lines[at] ?? ''];
124
+ for (let next = at + 1; next < raw.length; next += 1) {
125
+ const line = raw[next] ?? '';
126
+ if (!/^\s/u.test(line))
127
+ break;
128
+ chosen.push(lines[next] ?? '');
129
+ }
130
+ return chosen.join(' ').slice(0, limit);
131
+ }
132
+ /** The reason a particular answer came back, or '' when there is no process behind it. */
133
+ function answerWhy(value, { limit = 400 } = {}) {
134
+ return value.res === undefined ? '' : why(value.res, { limit });
135
+ }
136
+ /**
137
+ * Raise unless the cluster actually answered. For paths that must not guess.
138
+ *
139
+ * The wording is `namespaceLabels`' own, because it was right: it names the cluster,
140
+ * quotes the tool, and says why a guess is not on offer.
141
+ */
142
+ function require_(value, what, { context }) {
143
+ if (refused(value)) {
144
+ throw new errors_1.DockerError(`could not ask cluster '${context}' about ${what}: ${answerWhy(value)}` +
145
+ " — refusing to guess, because 'I cannot ask' and 'it is not there' are " +
146
+ 'different answers and only one of them is safe to act on');
147
+ }
148
+ return value;
149
+ }
150
+ /**
151
+ * Turn a finished kubectl into one of the three answers.
152
+ *
153
+ * The rule, and the only rule: a zero exit means the API server answered. Absence is
154
+ * then read from the PAYLOAD -- empty for a single object fetched with
155
+ * `--ignore-not-found` -- and never from the exit code.
156
+ */
157
+ function classify(res, { single }) {
158
+ if (res.returncode !== 0) {
159
+ // SECONDARY, AND ONLY EVER SECONDARY: the API server's own reason code.
160
+ // `--ignore-not-found` makes an absent object exit 0 with an empty payload, so
161
+ // reaching here at all means either a kubectl older than the flag or a call site
162
+ // that did not pass it -- and in both cases the server's `(NotFound)` is still a
163
+ // real assertion of absence, so throwing it away would be its own bug.
164
+ //
165
+ // The flag stays the primary test because THIS test was once the only one and got it
166
+ // wrong: the first cut matched "not found", which also matches `Error in
167
+ // configuration: context was not found for specified context: ...` -- a kubeconfig
168
+ // problem read as an absent namespace, the exact confusion this module exists to
169
+ // prevent. Only the API server says `Error from server (NotFound)`.
170
+ if (single && why(res).toLowerCase().replace(/ /gu, '').includes('fromserver(notfound)')) {
171
+ return answer(exports.ABSENT, null, res);
172
+ }
173
+ return answer(exports.REFUSED, null, res);
174
+ }
175
+ const raw = res.stdout.trim();
176
+ if (single && raw === '') {
177
+ // `--ignore-not-found` turns "not there" into exit 0 with nothing on stdout, which
178
+ // is the whole reason it is passed. `-o json` rather than a jsonpath because a
179
+ // jsonpath can be legitimately empty for an object that EXISTS -- a namespace with
180
+ // no labels reads identically to no namespace at all.
181
+ return answer(exports.ABSENT, null, res);
182
+ }
183
+ let doc = {};
184
+ if (raw !== '') {
185
+ try {
186
+ doc = JSON.parse(raw);
187
+ }
188
+ catch {
189
+ // The server answered and we cannot parse it. That is not absence.
190
+ return answer(exports.REFUSED, null, res);
191
+ }
192
+ }
193
+ return answer(exports.PRESENT, doc !== null && typeof doc === 'object' && !Array.isArray(doc) ? doc : {}, res);
194
+ }
195
+ /** Ask about ONE named object: PRESENT with its document, ABSENT, or REFUSED. */
196
+ async function askObject(kind, name, { context, namespace = '', timeout = names_1.PROBE_TIMEOUT }) {
197
+ const argv = ['kubectl', '--context', context];
198
+ if (namespace)
199
+ argv.push('-n', namespace);
200
+ argv.push('get', kind, name, '--ignore-not-found', '-o', 'json');
201
+ return classify(await exec_1.kube.run(argv, { own: (0, names_1.isOurs)(context), timeout }), { single: true });
202
+ }
203
+ /**
204
+ * Ask for a COLLECTION: PRESENT with `items` (possibly empty), or REFUSED.
205
+ *
206
+ * There is no ABSENT for a list. A cluster that holds no StorageClass answers with an
207
+ * empty collection and exit 0; a cluster nobody could reach is REFUSED. Reading those as
208
+ * the same empty list is what made `doctor` report "0 nodes, no StorageClass, no ingress"
209
+ * for a cluster with all three.
210
+ *
211
+ * `allNamespaces` is `-A`, and it is NOT the default for a reason worth stating: without
212
+ * it kubectl reads the CURRENT namespace, so a namespaced kind asked for without either
213
+ * flag answers about `default` alone -- an empty, exit-0, entirely believable "there are
214
+ * none of those here".
215
+ */
216
+ async function askList(kind, { context, namespace = '', selector = '', allNamespaces = false, timeout = names_1.PROBE_TIMEOUT, }) {
217
+ const argv = ['kubectl', '--context', context];
218
+ if (namespace && !allNamespaces)
219
+ argv.push('-n', namespace);
220
+ argv.push('get', kind, '-o', 'json');
221
+ if (allNamespaces) {
222
+ // AFTER the subcommand, and that is not cosmetic. `--namespace` is a global flag and
223
+ // may precede `get`; `--all-namespaces` belongs to `get` itself, and placed before it
224
+ // kubectl answers "flags cannot be placed before plugin name: --context" -- which
225
+ // `Answer` correctly refused to read as "this cluster has no Services".
226
+ argv.push('-A');
227
+ }
228
+ if (selector)
229
+ argv.push('-l', selector);
230
+ return classify(await exec_1.kube.run(argv, { own: (0, names_1.isOurs)(context), timeout }), { single: false });
231
+ }
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AMD64 = exports.FIRST_MULTIARCH_RC = void 0;
4
+ exports.storageClasses = storageClasses;
5
+ exports.metricsAvailable = metricsAvailable;
6
+ exports.nodesSummary = nodesSummary;
7
+ exports.ingressClasses = ingressClasses;
8
+ exports.workspaceNamespaces = workspaceNamespaces;
9
+ exports.architectureBlocker = architectureBlocker;
10
+ exports.storageBlocker = storageBlocker;
11
+ /**
12
+ * What this cluster can do, asked rather than assumed.
13
+ *
14
+ * Tier k2, read-only. Storage classes, API groups, nodes and the versions behind them. A
15
+ * cluster that cannot be asked yields a refusal, never an empty list -- see `ask.ts`.
16
+ */
17
+ const compose_1 = require("../../lib/compose");
18
+ const ask_1 = require("./ask");
19
+ const exec_1 = require("./exec");
20
+ const names_1 = require("./names");
21
+ const tools_1 = require("./tools");
22
+ function metadataOf(item) {
23
+ const meta = item.metadata;
24
+ return meta !== null && typeof meta === 'object' ? meta : {};
25
+ }
26
+ function annotationsOf(meta) {
27
+ const ann = meta.annotations;
28
+ return ann !== null && typeof ann === 'object' ? ann : {};
29
+ }
30
+ /**
31
+ * `[all storage class names, the default one]`, or null.
32
+ *
33
+ * The guide's step 1 opens with the warning that matters here: "Local Kubernetes
34
+ * distributions such as Kind, K3s, and Minikube often ship without a storage provisioner
35
+ * enabled." Without one, a PVC stays Pending forever and the workspace never boots --
36
+ * with no error that names storage.
37
+ *
38
+ * NULL, NOT `[[], '']`. A cluster that could not be asked was reporting the same answer
39
+ * as a cluster with no storage provisioner, so `doctor` told somebody with a perfectly
40
+ * good default StorageClass that their volume would stay Pending -- and gave it a green
41
+ * verdict, because a warning about missing storage is a warning and "I could not read
42
+ * your cluster" is not something it could say.
43
+ */
44
+ async function storageClasses(context = names_1.CONTEXT) {
45
+ const seen = await (0, ask_1.askList)('storageclass', { context });
46
+ if ((0, ask_1.refused)(seen))
47
+ return null;
48
+ const names = [];
49
+ let fallback = '';
50
+ for (const item of (0, ask_1.items)(seen)) {
51
+ const meta = metadataOf(item);
52
+ const name = String(meta.name ?? '');
53
+ if (name === '')
54
+ continue;
55
+ names.push(name);
56
+ if (annotationsOf(meta)['storageclass.kubernetes.io/is-default-class'] === 'true') {
57
+ fallback = name;
58
+ }
59
+ }
60
+ return [names, fallback];
61
+ }
62
+ /**
63
+ * Whether `kubectl top` can answer here, i.e. metrics-server is installed.
64
+ *
65
+ * Asked rather than assumed per distribution: kind ships none, k3s ships one, and
66
+ * minikube has it as an addon that is off by default -- and any of the three can be
67
+ * changed by the person running the cluster.
68
+ */
69
+ async function metricsAvailable(context = names_1.CONTEXT) {
70
+ const res = await exec_1.kube.run(['kubectl', '--context', context, 'top', 'nodes', '--no-headers'], {
71
+ own: (0, names_1.isOurs)(context),
72
+ });
73
+ return res.returncode === 0;
74
+ }
75
+ /**
76
+ * `[how many nodes, which architectures]`, or null. Both matter, for different reasons.
77
+ *
78
+ * Node COUNT decides whether a node-local default StorageClass can bite: `local-path` on
79
+ * kind and k3s alike is `WaitForFirstConsumer`, so on more than one node a MongoDB pod
80
+ * rescheduled elsewhere cannot rebind its volume. ARCHITECTURE matters because on kind
81
+ * and k3s the node is this machine and on a managed cluster it need not be --
82
+ * `bitnamilegacy/mongodb`, which every Rocket.Chat below 8 pairs with, is amd64-only.
83
+ *
84
+ * "0 nodes" was the answer for a cluster nobody could read, and it is a sentence doctor
85
+ * then printed next to a tick.
86
+ */
87
+ async function nodesSummary(context = names_1.CONTEXT) {
88
+ const seen = await (0, ask_1.askList)('nodes', { context });
89
+ if ((0, ask_1.refused)(seen))
90
+ return null;
91
+ const rows = (0, ask_1.items)(seen);
92
+ const arches = new Set();
93
+ for (const item of rows) {
94
+ const status = item.status;
95
+ const nodeInfo = status !== null && typeof status === 'object'
96
+ ? status.nodeInfo
97
+ : undefined;
98
+ const arch = String(nodeInfo?.architecture ?? '');
99
+ if (arch !== '')
100
+ arches.add(arch);
101
+ }
102
+ return [rows.length, [...arches].sort()];
103
+ }
104
+ /**
105
+ * Ingress controllers installed in this cluster, best choice first, or null.
106
+ *
107
+ * ORDERED, because the caller adopts the first one and the API's order is not a
108
+ * preference. An EKS cluster carrying both `alb` and `nginx` would otherwise have the
109
+ * choice made by whichever the API server happened to list first -- and the two behave
110
+ * differently for ACME http-01 solving and for endpoint discovery, so that is a real
111
+ * difference decided by nothing.
112
+ *
113
+ * The cluster's OWN default wins: `ingressclass.kubernetes.io/is-default-class` is
114
+ * Kubernetes' way of saying which controller an Ingress with no class gets, so somebody
115
+ * has already answered this question and houston should not overrule them. Names are the
116
+ * tiebreak after that -- arbitrary, but the same arbitrary answer every time, which
117
+ * "whatever the API listed first" was not.
118
+ */
119
+ async function ingressClasses(context = names_1.CONTEXT) {
120
+ const seen = await (0, ask_1.askList)('ingressclass', { context });
121
+ if ((0, ask_1.refused)(seen))
122
+ return null;
123
+ const rows = [];
124
+ for (const item of (0, ask_1.items)(seen)) {
125
+ const meta = metadataOf(item);
126
+ const name = String(meta.name ?? '');
127
+ if (name === '')
128
+ continue;
129
+ const isDefault = String(annotationsOf(meta)['ingressclass.kubernetes.io/is-default-class'] ?? '').toLowerCase() === 'true';
130
+ rows.push([isDefault ? 0 : 1, name]);
131
+ }
132
+ rows.sort((left, right) => left[0] - right[0] || (left[1] < right[1] ? -1 : left[1] > right[1] ? 1 : 0));
133
+ return rows.map(([, name]) => name);
134
+ }
135
+ /**
136
+ * Namespaces houston owns, selected by LABEL, or null if it could not be asked.
137
+ *
138
+ * THIS RETURNED `[]` FOR A REFUSED READ, and `[]` is what "this cluster holds no houston
139
+ * workspaces" looks like -- so a namespace-scoped RBAC identity, an 8 s PROBE_TIMEOUT
140
+ * under load or a control-plane restart all read as an empty cluster. Seven callers act
141
+ * on that, three of them destructively: `removeMonitoring` uninstalls the SHARED
142
+ * Prometheus/Grafana stack while another workspace is using it, `mongodbResources` does
143
+ * the same for the shared operator -- leaving other workspaces' MongoDBCommunity
144
+ * finalizers with nothing to clear, so THEIR teardown hangs -- and `createWorkspace`'s
145
+ * `hadNamespace` goes false, which makes a failed create delete a namespace `down` had
146
+ * kept, PVC and all. That last one is data loss.
147
+ */
148
+ async function workspaceNamespaces(context = names_1.CONTEXT) {
149
+ const seen = await (0, ask_1.askList)('namespace', { context, selector: names_1.OWNER_SELECTOR });
150
+ if ((0, ask_1.refused)(seen))
151
+ return null;
152
+ return (0, ask_1.items)(seen)
153
+ .map((item) => String(metadataOf(item).name ?? ''))
154
+ .filter((name) => name !== '')
155
+ .sort();
156
+ }
157
+ /**
158
+ * The first Rocket.Chat release published as a MULTI-ARCHITECTURE image.
159
+ *
160
+ * MEASURED with `docker manifest inspect` against registry.rocket.chat: 7.8.0, 7.9.0 and
161
+ * 7.10.0 each return a single `manifest.v2+json` -- one architecture, amd64 -- while
162
+ * 8.0.0 and 8.5.1 return `manifest.list.v2+json` carrying amd64 and arm64.
163
+ *
164
+ * Recorded as a version rather than read from the registry on every create, because
165
+ * asking would put a network call to a third-party registry -- and, with `docker
166
+ * manifest inspect`, a Docker dependency -- inside the one runtime that is meant not to
167
+ * need Docker at all.
168
+ */
169
+ exports.FIRST_MULTIARCH_RC = [8, 0, 0];
170
+ /**
171
+ * What Kubernetes calls the architectures houston's images are built for. Node
172
+ * architectures come back in these terms from `.status.nodeInfo.architecture`.
173
+ */
174
+ exports.AMD64 = 'amd64';
175
+ function atLeast(left, right) {
176
+ for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
177
+ const a = left[index] ?? 0;
178
+ const b = right[index] ?? 0;
179
+ if (a !== b)
180
+ return a > b;
181
+ }
182
+ return true;
183
+ }
184
+ /**
185
+ * Why this cluster's nodes cannot run this Rocket.Chat image, or ''.
186
+ *
187
+ * Same shape and same reason as `storageBlocker`: a refusal beats a create that installs
188
+ * cleanly and then cannot pull. `nodesSummary` has always READ the node architectures
189
+ * and its docstring has always said why they matter -- the value went to one string on
190
+ * `doctor`'s screen and was never compared against anything.
191
+ *
192
+ * THE IRONY IS THE POINT: the amd64-only range is precisely the range houston exists for.
193
+ * Reproducing a customer's old version is the product's whole purpose, and a Graviton
194
+ * node group is an ordinary way to run EKS cheaply.
195
+ *
196
+ * Bounded by what is actually known. An unread architecture is not a mismatch, an
197
+ * unreachable cluster is not our question, and a cluster with even one amd64 node can
198
+ * run the image -- Kubernetes will schedule it there, and pinning it with a nodeSelector
199
+ * would trade a fast, legible `ErrImagePull` for a silent `Pending`.
200
+ */
201
+ function architectureBlocker(pre, rcVersion, rcImage = '') {
202
+ if (!pre.clusterReachable || pre.architectures.length === 0)
203
+ return '';
204
+ if ((0, compose_1.isAmd64Only)(rcImage) && !pre.architectures.includes(exports.AMD64)) {
205
+ return (`${rcImage} is a FIPS build, published for ${exports.AMD64} only, and every node in this ` +
206
+ `cluster is ${[...pre.architectures].sort().join(', ')}. Add an ${exports.AMD64} node group, ` +
207
+ 'or use the build without -fips.');
208
+ }
209
+ const key = (0, tools_1.versionKey)(rcVersion);
210
+ // A VERSION THIS CANNOT READ MUST NOT BECOME A REFUSAL. `versionKey` answers [-1] for
211
+ // anything non-numeric, which sorts BELOW every real release -- so a version it could
212
+ // not parse would read as "older than 8.0.0" and block a create that is very likely
213
+ // fine. The direction of the mistake is the one this module exists to prevent: "I
214
+ // could not tell" turning into "no".
215
+ if (key.length === 0 || key[0] < 0 || atLeast(key, exports.FIRST_MULTIARCH_RC))
216
+ return '';
217
+ if (pre.architectures.includes(exports.AMD64))
218
+ return '';
219
+ const shape = [...pre.architectures].sort().join(', ');
220
+ return (`Rocket.Chat ${rcVersion} is published for ${exports.AMD64} only, and every node in this ` +
221
+ `cluster is ${shape}. The workspace would install and then fail to pull with 'no ` +
222
+ `matching manifest'. Add an ${exports.AMD64} node group, or use Rocket.Chat ` +
223
+ `${exports.FIRST_MULTIARCH_RC.join('.')} or newer, or reproduce this version on the Docker ` +
224
+ `runtime — which pins \`platform: linux/${exports.AMD64}\` and runs it under emulation, ` +
225
+ 'something a Kubernetes node cannot do.');
226
+ }
227
+ /**
228
+ * Why a workspace's volume could not bind in this cluster, or ''.
229
+ *
230
+ * Takes an already-probed Preflight rather than a context, so it cannot be called on
231
+ * data from an unreachable cluster -- reporting "no StorageClass" for a cluster nobody
232
+ * could reach is the same wrong answer as reporting an absent cluster for a stopped
233
+ * Docker.
234
+ *
235
+ * This is a REFUSAL, not a warning, for the reason that makes it nasty: with no
236
+ * provisioner the PVC stays Pending, the pod stays Pending, and Rocket.Chat never starts
237
+ * -- so there are no Rocket.Chat logs to find it in. Left to run, it costs the full
238
+ * readiness timeout and then reports "Rocket.Chat did not become ready", which blames
239
+ * the one component that is innocent.
240
+ */
241
+ function storageBlocker(pre) {
242
+ if (!pre.clusterReachable)
243
+ return ''; // not our question; unreachable is reported first
244
+ if (pre.defaultStorageClass !== '')
245
+ return '';
246
+ if (pre.unreadable.includes('storage')) {
247
+ // NOT "has no StorageClass". `preflight` records that the read was refused; this
248
+ // refused the create anyway and blamed the customer's cluster, which on a
249
+ // namespace-scoped RBAC identity made houston unusable AND sent the engineer to ask
250
+ // a platform team to install a provisioner that was already there. Still a refusal,
251
+ // because a create whose volume cannot be predicted is not a create worth starting
252
+ // -- but a refusal that names the right thing.
253
+ return (`Cluster '${pre.context}' would not let houston read its StorageClasses, so ` +
254
+ "whether the workspace's volume can bind is unknown. This is a permissions " +
255
+ 'problem on the credential in your kubeconfig, not a missing provisioner: ' +
256
+ '`kubectl get storageclass` as yourself says which.');
257
+ }
258
+ const where = `Cluster '${pre.context}'`;
259
+ if (pre.storageClasses.length > 0) {
260
+ return (`${where} has StorageClasses (${pre.storageClasses.join(', ')}) but none is ` +
261
+ "marked default, so the workspace's volume would stay Pending and Rocket.Chat " +
262
+ 'would never start. Mark one default with: kubectl patch storageclass <name> -p ' +
263
+ '\'{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}\'');
264
+ }
265
+ return (`${where} has no StorageClass, so the workspace's volume would stay Pending forever ` +
266
+ 'and Rocket.Chat would never start — with nothing in its logs naming storage, ' +
267
+ 'because it never runs. The official guide warns that local distributions often ' +
268
+ 'ship without a provisioner.');
269
+ }