@rocket.chat/houston 0.27.0-next.3 → 2.1.8
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.
- package/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,732 @@
|
|
|
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.QUICK_FAILURES = exports.ENDPOINT_WAIT_INTERVAL = exports.ENDPOINT_WAIT_TRIES = exports.UI_PORT_LABEL = void 0;
|
|
37
|
+
exports.holderCommand = holderCommand;
|
|
38
|
+
exports.listeningInodes = listeningInodes;
|
|
39
|
+
exports.socketInodesOf = socketInodesOf;
|
|
40
|
+
exports.pidOwnsPort = pidOwnsPort;
|
|
41
|
+
exports.pidOwnsPortExclusively = pidOwnsPortExclusively;
|
|
42
|
+
exports.forwardBound = forwardBound;
|
|
43
|
+
exports.forwardReachable = forwardReachable;
|
|
44
|
+
exports.forwardAlive = forwardAlive;
|
|
45
|
+
exports.stopForward = stopForward;
|
|
46
|
+
exports.signalForward = signalForward;
|
|
47
|
+
exports.supervisorScript = supervisorScript;
|
|
48
|
+
exports.portForward = portForward;
|
|
49
|
+
exports.ensurePortForward = ensurePortForward;
|
|
50
|
+
exports.listedService = listedService;
|
|
51
|
+
exports.scenarioUiForwards = scenarioUiForwards;
|
|
52
|
+
exports.grafanaForward = grafanaForward;
|
|
53
|
+
/**
|
|
54
|
+
* `kubectl port-forward`, and the question of whether the socket is actually ours.
|
|
55
|
+
*
|
|
56
|
+
* A forward dies with its pod, so this is the module `ready` leans on when somebody asks why
|
|
57
|
+
* the URL stopped answering. `forwardBound` confirms the socket rather than trusting the pid:
|
|
58
|
+
* kubectl returns one before it binds.
|
|
59
|
+
*/
|
|
60
|
+
const fs = __importStar(require("node:fs"));
|
|
61
|
+
const net = __importStar(require("node:net"));
|
|
62
|
+
const path = __importStar(require("node:path"));
|
|
63
|
+
const errors_1 = require("../../lib/errors");
|
|
64
|
+
const events_1 = require("../../lib/events");
|
|
65
|
+
const exec_1 = require("../../seams/exec");
|
|
66
|
+
const ask_1 = require("./ask");
|
|
67
|
+
const exec_2 = require("./exec");
|
|
68
|
+
const monitoring_1 = require("./monitoring");
|
|
69
|
+
const names_1 = require("./names");
|
|
70
|
+
const status_1 = require("./status");
|
|
71
|
+
const realSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
72
|
+
/**
|
|
73
|
+
* A scenario Service wearing this label is published on the host port it names. The label
|
|
74
|
+
* rather than a table here, because the adapter that creates the Service is the thing that
|
|
75
|
+
* knows it has a UI -- and a table would be a second place to declare a port.
|
|
76
|
+
*/
|
|
77
|
+
exports.UI_PORT_LABEL = 'houston.io/ui-port';
|
|
78
|
+
/**
|
|
79
|
+
* Up to two minutes for a scenario's workload to have a ready endpoint. Keycloak imports a
|
|
80
|
+
* realm on first boot and takes about forty seconds of it.
|
|
81
|
+
*/
|
|
82
|
+
exports.ENDPOINT_WAIT_TRIES = 60;
|
|
83
|
+
exports.ENDPOINT_WAIT_INTERVAL = 2.0;
|
|
84
|
+
/**
|
|
85
|
+
* Whether ownership is read from /proc. Everywhere else -- macOS, where the owner's kind
|
|
86
|
+
* workspaces run -- /proc is absent, every answer below came back empty, and a live forward
|
|
87
|
+
* read as dead: pid 0 recorded, "the port-forward did not stay up", and a fresh kubectl per
|
|
88
|
+
* check that died with "address already in use" while the first one kept the port. There,
|
|
89
|
+
* `lsof` and `ps` answer the same questions. Read per call, so a test can be a Mac.
|
|
90
|
+
*/
|
|
91
|
+
function hasProc() {
|
|
92
|
+
return process.platform === 'linux';
|
|
93
|
+
}
|
|
94
|
+
/** What `command` printed, or "" when it could not be run in time. Off Linux only. */
|
|
95
|
+
async function printed(command) {
|
|
96
|
+
try {
|
|
97
|
+
return String((await (0, exec_1.capture)(command, { encoding: 'utf8', timeoutMs: 5000 })).stdout ?? '');
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// A Ctrl-C mid-`ps` is the caller's to unwind, not "no such process".
|
|
101
|
+
if (error instanceof exec_1.Interrupted)
|
|
102
|
+
throw error;
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Off Linux: the pids LISTENING on `port`, as `lsof -Fp` names them -- one `p<pid>` line
|
|
108
|
+
* per process, whatever families it bound.
|
|
109
|
+
*
|
|
110
|
+
* ponytail: lsof run as a non-root user sees only that user's processes, so a squatter
|
|
111
|
+
* belonging to someone else is invisible here where /proc/net/tcp would show it. Good enough
|
|
112
|
+
* for a laptop; run lsof through sudo if a shared Mac ever matters.
|
|
113
|
+
*/
|
|
114
|
+
async function listeningPids(port) {
|
|
115
|
+
const text = await printed(['lsof', '-nP', `-iTCP:${String(port)}`, '-sTCP:LISTEN', '-Fp']);
|
|
116
|
+
const out = new Set();
|
|
117
|
+
for (const line of text.split('\n'))
|
|
118
|
+
if (line.startsWith('p'))
|
|
119
|
+
out.add(Number(line.slice(1)));
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** The command that names what listens on `port`. A Mac has no `ss`. */
|
|
123
|
+
function holderCommand(port) {
|
|
124
|
+
return hasProc()
|
|
125
|
+
? `ss -ltnp | grep ${String(port)}`
|
|
126
|
+
: `lsof -nP -iTCP:${String(port)} -sTCP:LISTEN`;
|
|
127
|
+
}
|
|
128
|
+
/** Whether anything at all listens on `port`. */
|
|
129
|
+
async function portHeld(port) {
|
|
130
|
+
return hasProc() ? listeningInodes(port).size > 0 : (await listeningPids(port)).size > 0;
|
|
131
|
+
}
|
|
132
|
+
/** Socket inodes LISTENING on `port`, from /proc/net/tcp{,6}. */
|
|
133
|
+
function listeningInodes(port) {
|
|
134
|
+
const out = new Set();
|
|
135
|
+
for (const file of ['/proc/net/tcp', '/proc/net/tcp6']) {
|
|
136
|
+
let lines;
|
|
137
|
+
try {
|
|
138
|
+
lines = fs.readFileSync(file, 'utf8').split('\n').slice(1);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
for (const line of lines) {
|
|
144
|
+
const fields = line.split(/\s+/u).filter((entry) => entry !== '');
|
|
145
|
+
// 0A is TCP_LISTEN; anything else is a connection, not a bind.
|
|
146
|
+
if (fields.length < 10 || fields[3] !== '0A')
|
|
147
|
+
continue;
|
|
148
|
+
const local = (fields[1] ?? '').split(':')[1];
|
|
149
|
+
if (local === undefined)
|
|
150
|
+
continue;
|
|
151
|
+
if (Number.parseInt(local, 16) === port)
|
|
152
|
+
out.add(fields[9]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
/** The socket inodes this pid holds open. Empty for a process we cannot read. */
|
|
158
|
+
function socketInodesOf(pid) {
|
|
159
|
+
let entries;
|
|
160
|
+
try {
|
|
161
|
+
entries = fs.readdirSync(`/proc/${String(pid)}/fd`);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return new Set();
|
|
165
|
+
}
|
|
166
|
+
const out = new Set();
|
|
167
|
+
for (const entry of entries) {
|
|
168
|
+
let target;
|
|
169
|
+
try {
|
|
170
|
+
target = fs.readlinkSync(path.join(`/proc/${String(pid)}/fd`, entry));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (target.startsWith('socket:['))
|
|
176
|
+
out.add(target.slice(8, -1));
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Whether THIS pid holds a listening socket on `port`.
|
|
182
|
+
*
|
|
183
|
+
* Ownership, and it is answered rather than timed. Every other way of asking -- "is the port
|
|
184
|
+
* up?", "is the child still alive?" -- is a race against a kubectl that has not failed yet,
|
|
185
|
+
* and it lost that race 3 times out of 3 against a squatter.
|
|
186
|
+
*
|
|
187
|
+
* An unreadable /proc entry (a process that is not ours) yields no inodes and so answers
|
|
188
|
+
* false, which is the safe direction.
|
|
189
|
+
*/
|
|
190
|
+
async function pidOwnsPort(pid, port) {
|
|
191
|
+
if (!hasProc())
|
|
192
|
+
return (await listeningPids(port)).has(pid);
|
|
193
|
+
const inodes = listeningInodes(port);
|
|
194
|
+
if (inodes.size === 0)
|
|
195
|
+
return false;
|
|
196
|
+
const mine = socketInodesOf(pid);
|
|
197
|
+
if (mine.size === 0)
|
|
198
|
+
return false;
|
|
199
|
+
for (const inode of inodes)
|
|
200
|
+
if (mine.has(inode))
|
|
201
|
+
return true;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Whether EVERY listener on `port` belongs to `pid` -- no other family, no other process.
|
|
206
|
+
*
|
|
207
|
+
* `pidOwnsPort` answers "is one of these sockets mine", and that is not the same question
|
|
208
|
+
* when two processes can hold the same port on different families. `kubectl port-forward`
|
|
209
|
+
* binds "localhost", which is BOTH 127.0.0.1 and [::1] -- and if an IPv4-only process
|
|
210
|
+
* already holds the port, kubectl does not fail: it binds [::1] alone and runs happily.
|
|
211
|
+
* Measured exactly that: kubectl on `[::1]:3250` only, `127.0.0.1:3250` answering a
|
|
212
|
+
* different program, and houston reporting the workspace as reachable.
|
|
213
|
+
*
|
|
214
|
+
* Deliberately not solved by forcing `--address 127.0.0.1`: houston publishes
|
|
215
|
+
* `http://localhost:P`, and on a box whose `localhost` resolves to `::1` first, binding IPv4
|
|
216
|
+
* only would break the URL for everybody.
|
|
217
|
+
*/
|
|
218
|
+
async function pidOwnsPortExclusively(pid, port) {
|
|
219
|
+
return await pidsOwnPortExclusively([pid], port);
|
|
220
|
+
}
|
|
221
|
+
/** `pidOwnsPortExclusively` for a supervised forward: the shell or the kubectl it runs. */
|
|
222
|
+
async function pidsOwnPortExclusively(pids, port) {
|
|
223
|
+
if (!hasProc()) {
|
|
224
|
+
const listening = await listeningPids(port);
|
|
225
|
+
return listening.size > 0 && [...listening].every((pid) => pids.includes(pid));
|
|
226
|
+
}
|
|
227
|
+
const inodes = listeningInodes(port);
|
|
228
|
+
if (inodes.size === 0)
|
|
229
|
+
return false;
|
|
230
|
+
const mine = new Set(pids.flatMap((pid) => [...socketInodesOf(pid)]));
|
|
231
|
+
for (const inode of inodes)
|
|
232
|
+
if (!mine.has(inode))
|
|
233
|
+
return false;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
/** `pid` and its children: a supervised forward's socket belongs to its kubectl. */
|
|
237
|
+
async function withChildren(pid) {
|
|
238
|
+
if (!hasProc()) {
|
|
239
|
+
const text = await printed(['pgrep', '-P', String(pid)]);
|
|
240
|
+
return [
|
|
241
|
+
pid,
|
|
242
|
+
...text
|
|
243
|
+
.split('\n')
|
|
244
|
+
.filter((line) => /^\d+$/u.test(line))
|
|
245
|
+
.map(Number),
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
const out = [pid];
|
|
249
|
+
for (const entry of fs.readdirSync('/proc')) {
|
|
250
|
+
if (!/^\d+$/u.test(entry))
|
|
251
|
+
continue;
|
|
252
|
+
try {
|
|
253
|
+
// The parent is the second field after the command, which may itself hold ") ".
|
|
254
|
+
const stat = fs.readFileSync(`/proc/${entry}/stat`, 'utf8');
|
|
255
|
+
if (Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]) === pid)
|
|
256
|
+
out.push(Number(entry));
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// gone between the listing and the read
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
function alive(pid) {
|
|
265
|
+
try {
|
|
266
|
+
process.kill(pid, 0);
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Whether THIS child actually got the socket. Waits for one answer or the other.
|
|
275
|
+
*
|
|
276
|
+
* `kubectl port-forward` cannot share a port: if something already holds it, kubectl prints
|
|
277
|
+
* "Unable to listen on port N: bind: address already in use" and exits within milliseconds.
|
|
278
|
+
* Returning the pid regardless recorded a pid that was already dead -- and because a port
|
|
279
|
+
* check only asks whether the port ANSWERS, and the squatter answers, `ready` then certified
|
|
280
|
+
* the workspace's URL while a different program served it.
|
|
281
|
+
*
|
|
282
|
+
* The child exiting is a definite no; the socket answering while the child lives is a yes;
|
|
283
|
+
* neither yet means keep waiting.
|
|
284
|
+
*/
|
|
285
|
+
async function forwardBound(pid, hostPort, { tries = 20, interval = 0.5, sleep = realSleep } = {}) {
|
|
286
|
+
for (let attempt = 0; attempt < tries; attempt += 1) {
|
|
287
|
+
if (!alive(pid))
|
|
288
|
+
return false;
|
|
289
|
+
// OUR CHILD'S SOCKET, not "a socket". Asking whether the PORT answers made this return
|
|
290
|
+
// true against a squatter every time, in a tenth of a millisecond.
|
|
291
|
+
if (await pidsOwnPortExclusively(await withChildren(pid), hostPort))
|
|
292
|
+
return true;
|
|
293
|
+
await sleep(interval);
|
|
294
|
+
}
|
|
295
|
+
return alive(pid) && (await pidsOwnPortExclusively(await withChildren(pid), hostPort));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Whether SOMETHING is listening on the host port yet. Occupancy, not identity.
|
|
299
|
+
*
|
|
300
|
+
* `kubectl port-forward` returns a pid long before it has bound the socket, so a URL printed
|
|
301
|
+
* straight after spawning it is a guess.
|
|
302
|
+
*
|
|
303
|
+
* It cannot tell you WHOSE socket it is. A foreign process holding the port answers this
|
|
304
|
+
* exactly as our own forward does, so nothing may conclude "the workspace is serving" from
|
|
305
|
+
* this alone.
|
|
306
|
+
*/
|
|
307
|
+
async function forwardReachable(hostPort, { tries = 20, interval = 0.5, sleep = realSleep } = {}) {
|
|
308
|
+
for (let attempt = 0; attempt < tries; attempt += 1) {
|
|
309
|
+
const answered = await new Promise((resolve) => {
|
|
310
|
+
const probe = new net.Socket();
|
|
311
|
+
const done = (value) => {
|
|
312
|
+
probe.destroy();
|
|
313
|
+
resolve(value);
|
|
314
|
+
};
|
|
315
|
+
probe.setTimeout(1000, () => done(false));
|
|
316
|
+
probe.once('connect', () => done(true));
|
|
317
|
+
probe.once('error', () => done(false));
|
|
318
|
+
probe.connect(hostPort, '127.0.0.1');
|
|
319
|
+
});
|
|
320
|
+
if (answered)
|
|
321
|
+
return true;
|
|
322
|
+
await sleep(interval);
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Fallback identity when the process hid its own arguments.
|
|
328
|
+
*
|
|
329
|
+
* Three facts together, and none of them alone would do: the pid came from OUR record, the
|
|
330
|
+
* process is still a `kubectl`, and the port it was started for is actually held. Pid
|
|
331
|
+
* recycling is what the argv check exists to defeat, and a recycled pid that is also a
|
|
332
|
+
* kubectl that is also listening on exactly the port we recorded is a coincidence worth
|
|
333
|
+
* accepting -- the alternative is calling every healthy forward on every k3s host dead.
|
|
334
|
+
*/
|
|
335
|
+
async function forwardAliveWithoutArgv(pid, hostPort, argv) {
|
|
336
|
+
let comm;
|
|
337
|
+
try {
|
|
338
|
+
comm = hasProc()
|
|
339
|
+
? fs.readFileSync(`/proc/${String(pid)}/comm`, 'utf8').trim()
|
|
340
|
+
: path.basename(argv[0] ?? '');
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
if (comm !== 'kubectl' && comm !== 'k3s')
|
|
346
|
+
return false;
|
|
347
|
+
if (hostPort === null)
|
|
348
|
+
return true;
|
|
349
|
+
// `pidOwnsPort`, not `forwardReachable`: "the port answers" is satisfied by whoever holds
|
|
350
|
+
// it, which is exactly the confusion this fallback exists inside.
|
|
351
|
+
return await pidOwnsPort(pid, hostPort);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A process's argv, or null for one that cannot be read. /proc keeps the NUL boundaries;
|
|
355
|
+
* `ps` joins with spaces, which splits no token a forward's argv carries.
|
|
356
|
+
*/
|
|
357
|
+
async function argvOf(pid) {
|
|
358
|
+
if (!hasProc()) {
|
|
359
|
+
const line = (await printed(['ps', '-o', 'args=', '-p', String(pid)])).trim();
|
|
360
|
+
return line === '' ? null : line.split(/\s+/u);
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
const raw = fs.readFileSync(`/proc/${String(pid)}/cmdline`, 'utf8');
|
|
364
|
+
return raw.split('\0').filter((token) => token !== '');
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Whether `pid` is OUR port-forward -- not merely someone's.
|
|
372
|
+
*
|
|
373
|
+
* A pid alone is not enough: the OS recycles them. This used to accept any process whose
|
|
374
|
+
* command line mentioned `port-forward`, which is a liveness check dressed as an identity
|
|
375
|
+
* check. A recycled pid belonging to a different workspace's forward -- or another user's,
|
|
376
|
+
* on a shared box -- passed it.
|
|
377
|
+
*
|
|
378
|
+
* The argv already carries the proof. Matched as whole NUL-separated tokens, because a
|
|
379
|
+
* substring test lets `3000` match `13000`.
|
|
380
|
+
*/
|
|
381
|
+
async function forwardAlive(pid, { namespace = '', hostPort = null } = {}) {
|
|
382
|
+
if (pid === null || pid === undefined || pid === 0)
|
|
383
|
+
return false;
|
|
384
|
+
const argv = await argvOf(pid);
|
|
385
|
+
if (argv === null)
|
|
386
|
+
return false;
|
|
387
|
+
// AN ARGV OF ONE IS NOT AN ARGV THAT DISAGREES. On a host where `kubectl` is a symlink to
|
|
388
|
+
// `k3s` -- which is every k3s host -- the multi-call binary rewrites its own command line
|
|
389
|
+
// when it dispatches, so /proc/<pid>/cmdline reads `kubectl` and then nothing. Reading that
|
|
390
|
+
// as "the forward is gone" made this respawn onto a port its own live forward already
|
|
391
|
+
// held, on every call.
|
|
392
|
+
if (argv.length <= 1)
|
|
393
|
+
return await forwardAliveWithoutArgv(pid, hostPort, argv);
|
|
394
|
+
if (!argv.includes('port-forward'))
|
|
395
|
+
return false;
|
|
396
|
+
if (namespace !== '' && !argv.includes(namespace))
|
|
397
|
+
return false;
|
|
398
|
+
if (hostPort !== null && !argv.some((token) => token.startsWith(`${String(hostPort)}:`))) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Retire a recorded port-forward. True if one was signalled.
|
|
405
|
+
*
|
|
406
|
+
* `hostPort` is the port the forward was PUBLISHED ON, not the one being asked for now, and
|
|
407
|
+
* that difference is the whole bug: `up --port 3261` on a workspace already forwarded on
|
|
408
|
+
* 3260 asked about 3261, got false, recorded pid 0 and walked away -- leaving the old
|
|
409
|
+
* kubectl alive on 3260 with nothing able to find it again.
|
|
410
|
+
*/
|
|
411
|
+
async function stopForward(pid, { namespace, hostPort, emit = events_1.nullEmit, }) {
|
|
412
|
+
if (pid === null || pid === undefined || pid === 0)
|
|
413
|
+
return false;
|
|
414
|
+
if (!(await forwardAlive(pid, { namespace, hostPort })))
|
|
415
|
+
return false;
|
|
416
|
+
if (!signalForward(pid))
|
|
417
|
+
return false;
|
|
418
|
+
(0, events_1.info)(emit, `stopped the previous port-forward on :${String(hostPort)} (pid ${String(pid)})`, {
|
|
419
|
+
phase: 'boot',
|
|
420
|
+
});
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
function forwardArgv(context, namespace, bindHost, target, ports) {
|
|
424
|
+
const argv = [
|
|
425
|
+
'kubectl',
|
|
426
|
+
'--context',
|
|
427
|
+
context,
|
|
428
|
+
'-n',
|
|
429
|
+
namespace,
|
|
430
|
+
'port-forward',
|
|
431
|
+
];
|
|
432
|
+
// `--bind` was accepted and then dropped on this path, which is worse than refusing it: a
|
|
433
|
+
// workspace created with `--bind 0.0.0.0` on a shared box was reachable only from
|
|
434
|
+
// localhost, and nothing said so. kubectl binds 127.0.0.1 by default and takes --address.
|
|
435
|
+
if (bindHost !== '' && bindHost !== '127.0.0.1' && bindHost !== 'localhost') {
|
|
436
|
+
argv.push('--address', bindHost);
|
|
437
|
+
}
|
|
438
|
+
argv.push(target, ports);
|
|
439
|
+
return argv;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Stop a forward: SIGTERM to the process group it leads, so a supervisor takes its kubectl
|
|
443
|
+
* with it. Every forward is started detached, and so leads its own group. True if signalled.
|
|
444
|
+
*/
|
|
445
|
+
function signalForward(pid) {
|
|
446
|
+
try {
|
|
447
|
+
process.kill(-pid, 'SIGTERM');
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
try {
|
|
452
|
+
process.kill(pid, 'SIGTERM');
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/** Starts in a row, each over in under 10 s, after which the supervisor stops trying. */
|
|
461
|
+
exports.QUICK_FAILURES = 60;
|
|
462
|
+
/**
|
|
463
|
+
* The supervisor's loop: run `"$@"` again whenever it exits, pausing `pause` seconds, and
|
|
464
|
+
* give up after `quickFailures` runs in a row that each ended within ten seconds -- a
|
|
465
|
+
* namespace that is gone, a port someone else holds.
|
|
466
|
+
*/
|
|
467
|
+
function supervisorScript(quickFailures, pause) {
|
|
468
|
+
return (`n=0; while [ "$n" -lt ${String(quickFailures)} ]; do s=$(date +%s); "$@"; ` +
|
|
469
|
+
'if [ $(($(date +%s) - s)) -lt 10 ]; then n=$((n + 1)); else n=0; fi; ' +
|
|
470
|
+
`sleep ${String(pause)}; done`);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Start a forward that restarts itself. kubectl exits whenever its stream to the pod breaks --
|
|
474
|
+
* measured after 19 minutes with the pod healthy and never restarted -- and once `up` has
|
|
475
|
+
* returned nothing was left to start it again, so the URL stayed dead until somebody ran
|
|
476
|
+
* `houston ready`. The shell keeps kubectl's argv as its own trailing tokens, which is what
|
|
477
|
+
* `forwardAlive` reads, so a supervised forward is identified exactly as a bare kubectl is.
|
|
478
|
+
* Windows has no `sh`, and keeps the bare kubectl.
|
|
479
|
+
*/
|
|
480
|
+
async function spawnForward(argv, context) {
|
|
481
|
+
const env = (0, exec_2.envFor)(context);
|
|
482
|
+
const supervised = process.platform === 'win32'
|
|
483
|
+
? argv
|
|
484
|
+
: ['sh', '-c', supervisorScript(exports.QUICK_FAILURES, 2), 'houston-port-forward', ...argv];
|
|
485
|
+
try {
|
|
486
|
+
// Detached, so it outlives the `up` that started it -- the workspace has to stay
|
|
487
|
+
// reachable after the command returns, exactly as a published Compose port does.
|
|
488
|
+
const child = await (0, exec_1.startDetached)(supervised, { ...(env !== undefined ? { env } : {}) });
|
|
489
|
+
return child.pid;
|
|
490
|
+
}
|
|
491
|
+
catch {
|
|
492
|
+
return 0;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/** Wait for a Rocket.Chat pod, and say why if none arrives. */
|
|
496
|
+
async function waitForAPodToForwardTo(context, emit, name, namespace, sleep) {
|
|
497
|
+
// RUNNING, not merely existing. `kubectl port-forward` refuses a pod that is still
|
|
498
|
+
// ContainerCreating and exits, which is precisely what happened when this waited only for a
|
|
499
|
+
// pod NAME. Existence is not reachability.
|
|
500
|
+
//
|
|
501
|
+
// THE EXIT CODE WAS NEVER READ HERE, and empty stdout from a refused call is identical to
|
|
502
|
+
// "the pod is not Running yet". So this waited the full budget against a cluster that had
|
|
503
|
+
// been destroyed: measured at 94 seconds and nine "waiting" messages after the control
|
|
504
|
+
// plane was killed.
|
|
505
|
+
let refusals = 0;
|
|
506
|
+
for (let attempt = 0; attempt < names_1.POD_WAIT_TRIES; attempt += 1) {
|
|
507
|
+
const seen = await (0, ask_1.askList)('pod', {
|
|
508
|
+
context,
|
|
509
|
+
namespace,
|
|
510
|
+
selector: 'app.kubernetes.io/name=rocketchat',
|
|
511
|
+
});
|
|
512
|
+
if ((0, ask_1.refused)(seen)) {
|
|
513
|
+
refusals += 1;
|
|
514
|
+
if (refusals >= names_1.POD_WAIT_REFUSALS) {
|
|
515
|
+
throw new errors_1.DockerError(`could not ask cluster '${context}' about the Rocket.Chat pod in ${namespace} ` +
|
|
516
|
+
`(${String(refusals)} attempts): ${(0, ask_1.answerWhy)(seen)}. Waiting longer will not ` +
|
|
517
|
+
'help while the cluster cannot be reached.');
|
|
518
|
+
}
|
|
519
|
+
await sleep(names_1.POD_WAIT_INTERVAL);
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
refusals = 0;
|
|
523
|
+
const phases = (0, ask_1.items)(seen).map((item) => {
|
|
524
|
+
const status = item.status;
|
|
525
|
+
return status !== null && typeof status === 'object'
|
|
526
|
+
? String(status.phase ?? '')
|
|
527
|
+
: '';
|
|
528
|
+
});
|
|
529
|
+
if (phases.includes('Running'))
|
|
530
|
+
return;
|
|
531
|
+
// Stop waiting for something Kubernetes has already decided cannot happen.
|
|
532
|
+
const doomed = await (0, status_1.terminalPodFailure)(name, { context });
|
|
533
|
+
if (doomed !== null) {
|
|
534
|
+
const [pod, reason, message] = doomed;
|
|
535
|
+
throw new errors_1.CreateFailedError(`'${name}' cannot start: pod ${pod} is ${reason}` +
|
|
536
|
+
(message !== '' ? ` — ${message}` : '') +
|
|
537
|
+
`. Nothing will change by waiting. \`kubectl -n ${namespace} describe pod ${pod}\` ` +
|
|
538
|
+
'has the detail.');
|
|
539
|
+
}
|
|
540
|
+
if (attempt % 4 === 0)
|
|
541
|
+
(0, events_1.info)(emit, 'waiting for the Rocket.Chat pod', { phase: 'wait' });
|
|
542
|
+
await sleep(names_1.POD_WAIT_INTERVAL);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Publish a workspace on a host port. Returns the pid, or 0.
|
|
547
|
+
*
|
|
548
|
+
* Forwards to the DEPLOYMENT, not the Service. `port-forward svc/...` needs a ready
|
|
549
|
+
* ENDPOINT, and a Service has none until its pod passes readiness -- so the first version
|
|
550
|
+
* started the forward immediately after `helm install`, kubectl found nothing to attach to
|
|
551
|
+
* and exited, and the URL `up` printed never answered.
|
|
552
|
+
*/
|
|
553
|
+
async function portForward(name, { namespace, context, hostPort, bindHost = '', previousPid = 0, previousPort = null, emit = events_1.nullEmit, sleep = realSleep, }) {
|
|
554
|
+
await waitForAPodToForwardTo(context, emit, name, namespace, sleep);
|
|
555
|
+
// THE OLD ONE GOES FIRST. A `--port` change leaves the previous kubectl alive holding the
|
|
556
|
+
// previous port, with nothing able to find it again because every later lookup asks about
|
|
557
|
+
// the NEW port.
|
|
558
|
+
await stopForward(previousPid, {
|
|
559
|
+
namespace,
|
|
560
|
+
hostPort: previousPort !== null && previousPort !== 0 ? previousPort : hostPort,
|
|
561
|
+
emit,
|
|
562
|
+
});
|
|
563
|
+
const pid = await spawnForward(forwardArgv(context, namespace, bindHost, `deployment/${names_1.RELEASE}-rocketchat`, `${String(hostPort)}:3000`), context);
|
|
564
|
+
if (pid === 0)
|
|
565
|
+
return 0;
|
|
566
|
+
// CONFIRMED, not assumed: returning the pid recorded one for a kubectl that had already
|
|
567
|
+
// exited because the port was taken.
|
|
568
|
+
if (!(await forwardBound(pid, hostPort, { sleep }))) {
|
|
569
|
+
// Not left retrying: no record names it, so nothing would ever stop it.
|
|
570
|
+
signalForward(pid);
|
|
571
|
+
// WHY IT DID NOT COME UP, rather than one guess applied to every cause. This asserted
|
|
572
|
+
// "Something else probably holds that port" unconditionally, and the commonest cause is
|
|
573
|
+
// the exact opposite: during a rolling update the pod the forward attached to goes away,
|
|
574
|
+
// kubectl exits, and NOTHING holds the port. A false alarm that prescribes destroying
|
|
575
|
+
// the workspace is worse than no alarm.
|
|
576
|
+
if (await portHeld(hostPort)) {
|
|
577
|
+
(0, events_1.warn)(emit, `the port-forward for '${name}' did not come up on port ${String(hostPort)}: ` +
|
|
578
|
+
`something else already holds it — \`${holderCommand(hostPort)}\` says ` +
|
|
579
|
+
`what, and \`houston down --name ${name}\` then \`houston up\` picks a free one.`, { phase: 'wait' });
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
(0, events_1.warn)(emit, `the port-forward for '${name}' dropped while the pod was moving — nothing holds ` +
|
|
583
|
+
`port ${String(hostPort)}, so this is not a collision. \`houston ready --name ` +
|
|
584
|
+
`${name}\` re-establishes it; a create or upgrade does that for you on the next ` +
|
|
585
|
+
'check.', { phase: 'wait' });
|
|
586
|
+
}
|
|
587
|
+
return 0;
|
|
588
|
+
}
|
|
589
|
+
return pid;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Return a live port-forward pid, starting one if the recorded one is gone.
|
|
593
|
+
*
|
|
594
|
+
* A forward dies with its pod, so `ready` and `start` call this rather than assuming the one
|
|
595
|
+
* written at create time is still there. Idempotent: an already-live forward is left alone
|
|
596
|
+
* rather than duplicated onto a busy port.
|
|
597
|
+
*/
|
|
598
|
+
async function ensurePortForward(name, { namespace, context, hostPort, pid = 0, bindHost = '', emit = events_1.nullEmit, }) {
|
|
599
|
+
if (await forwardAlive(pid, { namespace, hostPort }))
|
|
600
|
+
return pid;
|
|
601
|
+
// The recorded pid is handed on as the one to retire: it is not alive ON THIS PORT, which
|
|
602
|
+
// is a different statement from "it is not alive".
|
|
603
|
+
return await portForward(name, {
|
|
604
|
+
namespace,
|
|
605
|
+
context,
|
|
606
|
+
hostPort,
|
|
607
|
+
bindHost,
|
|
608
|
+
previousPid: pid,
|
|
609
|
+
previousPort: hostPort,
|
|
610
|
+
emit,
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
/** Parse one service publication row, or return null for malformed output. */
|
|
614
|
+
function listedService(line) {
|
|
615
|
+
const parts = line.split(/\s+/u).filter((entry) => entry !== '');
|
|
616
|
+
if (parts.length !== 3 && parts.length !== 4)
|
|
617
|
+
return null;
|
|
618
|
+
const [svc, host, target] = parts;
|
|
619
|
+
const deploy = parts.length === 4 ? parts[3] : svc;
|
|
620
|
+
const hostPort = Number.parseInt(host, 10);
|
|
621
|
+
const targetPort = Number.parseInt(target, 10);
|
|
622
|
+
if (!Number.isFinite(hostPort) || !Number.isFinite(targetPort))
|
|
623
|
+
return null;
|
|
624
|
+
return [svc, hostPort, targetPort, deploy];
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Publish every scenario Service that asks to be published. Returns `{port: pid}`.
|
|
628
|
+
*
|
|
629
|
+
* Compose gives a preset's UI a host port for free; here it is a port-forward, for the
|
|
630
|
+
* reasons NodePort cannot serve: its range is 30000-32767 so the port would not MATCH the
|
|
631
|
+
* Compose one, kind's nodes are unreachable from the host on macOS and Windows, and
|
|
632
|
+
* `extraPortMappings` is fixed when the cluster is created.
|
|
633
|
+
*/
|
|
634
|
+
async function scenarioUiForwards(_name, { namespace, context, bindHost = '', emit = events_1.nullEmit, sleep = realSleep, }) {
|
|
635
|
+
const res = await exec_2.kube.run([
|
|
636
|
+
'kubectl',
|
|
637
|
+
'--context',
|
|
638
|
+
context,
|
|
639
|
+
'-n',
|
|
640
|
+
namespace,
|
|
641
|
+
'get',
|
|
642
|
+
'svc',
|
|
643
|
+
'-l',
|
|
644
|
+
exports.UI_PORT_LABEL,
|
|
645
|
+
'-o',
|
|
646
|
+
'jsonpath={range .items[*]}{.metadata.name}{" "}' +
|
|
647
|
+
'{.metadata.labels.houston\\.io/ui-port}{" "}' +
|
|
648
|
+
'{.spec.ports[0].targetPort}{" "}' +
|
|
649
|
+
'{.metadata.labels.houston\\.io/ui-deployment}{"\\n"}{end}',
|
|
650
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
651
|
+
const forwards = {};
|
|
652
|
+
for (const line of res.stdout.split('\n')) {
|
|
653
|
+
const listed = listedService(line);
|
|
654
|
+
if (listed === null)
|
|
655
|
+
continue;
|
|
656
|
+
const [svc, hostPort, targetPort, deploy] = listed;
|
|
657
|
+
// AND FOR THE ROLLOUT TO FINISH. Mid-rollout the pod being replaced is still a ready
|
|
658
|
+
// endpoint, so a rebuild that changed an image forwarded to it, and once it was gone the
|
|
659
|
+
// forward stayed up answering every request empty (live, k3s: an ldap workspace rebuilt
|
|
660
|
+
// onto its new images, :8082 dead until `houston ready`). A rollout that does not finish
|
|
661
|
+
// in the bound falls through to the endpoint wait and its message, as before.
|
|
662
|
+
const bound = exports.ENDPOINT_WAIT_TRIES * exports.ENDPOINT_WAIT_INTERVAL;
|
|
663
|
+
await exec_2.kube.run([
|
|
664
|
+
'kubectl',
|
|
665
|
+
'--context',
|
|
666
|
+
context,
|
|
667
|
+
'-n',
|
|
668
|
+
namespace,
|
|
669
|
+
'rollout',
|
|
670
|
+
'status',
|
|
671
|
+
`deployment/${deploy}`,
|
|
672
|
+
`--timeout=${String(bound)}s`,
|
|
673
|
+
], { timeout: bound + 30, own: (0, names_1.isOurs)(context) });
|
|
674
|
+
// WAIT FOR A READY ENDPOINT FIRST. `kubectl port-forward svc/...` binds the local socket
|
|
675
|
+
// immediately and only then dials a pod -- so a forward started while the workload is
|
|
676
|
+
// still booting passes a TCP check on the local side, fails upstream, and exits. Keycloak
|
|
677
|
+
// takes ~40 s to import its realm, and that is exactly what happened.
|
|
678
|
+
let ready = false;
|
|
679
|
+
for (let attempt = 0; attempt < exports.ENDPOINT_WAIT_TRIES; attempt += 1) {
|
|
680
|
+
const counts = await (0, status_1.serviceReadyAddresses)(namespace, { context });
|
|
681
|
+
if (counts !== null && (counts[svc] ?? 0) > 0) {
|
|
682
|
+
ready = true;
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
await sleep(exports.ENDPOINT_WAIT_INTERVAL);
|
|
686
|
+
}
|
|
687
|
+
if (!ready) {
|
|
688
|
+
(0, events_1.warn)(emit, `${svc} has no ready endpoint yet; publish it when it is up: kubectl -n ${namespace} ` +
|
|
689
|
+
`port-forward svc/${svc} ${String(hostPort)}:${String(targetPort)}`, { phase: 'boot' });
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
// deployment/, NOT svc/. A Service forward dies when its endpoint churns -- which is
|
|
693
|
+
// exactly what happened to a live OIDC workspace: Keycloak was 1/1 Running, the recorded
|
|
694
|
+
// pid was gone, and nothing answered.
|
|
695
|
+
const pid = await spawnForward(forwardArgv(context, namespace, bindHost, `deployment/${deploy}`, `${String(hostPort)}:${String(targetPort)}`), context);
|
|
696
|
+
// Confirmed, not assumed -- the same rule the workspace URL and Grafana both had to
|
|
697
|
+
// learn. And `forwardBound` rather than `forwardReachable`, because the port answering is
|
|
698
|
+
// not evidence that OUR kubectl is the thing answering.
|
|
699
|
+
if (pid !== 0 && (await forwardBound(pid, hostPort, { sleep }))) {
|
|
700
|
+
forwards[hostPort] = pid;
|
|
701
|
+
(0, events_1.info)(emit, `${svc} published at http://localhost:${String(hostPort)}`, { phase: 'boot' });
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
// Not left running: no record names a forward that never bound, so nothing would
|
|
705
|
+
// ever stop it, and the command below would find its port taken.
|
|
706
|
+
if (pid !== 0)
|
|
707
|
+
signalForward(pid);
|
|
708
|
+
(0, events_1.warn)(emit, `${svc} is running but http://localhost:${String(hostPort)} is not answering yet; ` +
|
|
709
|
+
`\`kubectl -n ${namespace} port-forward svc/${svc} ${String(hostPort)}:` +
|
|
710
|
+
`${String(targetPort)}\` re-establishes it`, { phase: 'boot' });
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return forwards;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Publish Grafana on a host port. Returns the pid, or 0.
|
|
717
|
+
*
|
|
718
|
+
* Same deployment-not-Service rule as the workspace forward, for the same reason: a Service
|
|
719
|
+
* with no ready endpoint makes kubectl exit immediately.
|
|
720
|
+
*/
|
|
721
|
+
async function grafanaForward({ context, hostPort, bindHost = '', }) {
|
|
722
|
+
const pid = await spawnForward(forwardArgv(context, monitoring_1.MONITORING_NAMESPACE, bindHost, `deployment/${monitoring_1.GRAFANA_DEPLOYMENT}`, `${String(hostPort)}:${String(monitoring_1.GRAFANA_PORT)}`), context);
|
|
723
|
+
if (pid === 0)
|
|
724
|
+
return 0;
|
|
725
|
+
// Same rule as the workspace forward. This path has form: it is where "reported attached
|
|
726
|
+
// and exit 0, and a curl a moment later got nothing" was measured.
|
|
727
|
+
if (!(await forwardBound(pid, hostPort))) {
|
|
728
|
+
signalForward(pid);
|
|
729
|
+
return 0;
|
|
730
|
+
}
|
|
731
|
+
return pid;
|
|
732
|
+
}
|