@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,439 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PENDING_STATES = void 0;
|
|
4
|
+
exports.apply = apply;
|
|
5
|
+
exports.podsWaiting = podsWaiting;
|
|
6
|
+
exports.reportInstallProgress = reportInstallProgress;
|
|
7
|
+
exports.helmRollbackOnFailure = helmRollbackOnFailure;
|
|
8
|
+
exports.releaseState = releaseState;
|
|
9
|
+
exports.clearPendingRelease = clearPendingRelease;
|
|
10
|
+
exports.install = install;
|
|
11
|
+
exports.releaseValues = releaseValues;
|
|
12
|
+
exports.rerenderRelease = rerenderRelease;
|
|
13
|
+
exports.upgradeImage = upgradeImage;
|
|
14
|
+
/**
|
|
15
|
+
* The Helm release: installing it, upgrading it, and undoing a failed one.
|
|
16
|
+
*
|
|
17
|
+
* Tier k3. `helmRollbackOnFailure` picks the flag by the helm actually installed --
|
|
18
|
+
* `--atomic` does not exist in helm 4, it is `--rollback-on-failure` -- because a flag helm
|
|
19
|
+
* does not recognise turns a working install into a broken one.
|
|
20
|
+
*/
|
|
21
|
+
const errors_1 = require("../../lib/errors");
|
|
22
|
+
const events_1 = require("../../lib/events");
|
|
23
|
+
const json_text_1 = require("../../lib/json-text");
|
|
24
|
+
const ask_1 = require("./ask");
|
|
25
|
+
const exec_1 = require("./exec");
|
|
26
|
+
const manifests_1 = require("./manifests");
|
|
27
|
+
const names_1 = require("./names");
|
|
28
|
+
const tools_1 = require("./tools");
|
|
29
|
+
/** `kubectl apply` a manifest from stdin, so no temp file is left behind. */
|
|
30
|
+
async function apply(manifest, { namespace, context }) {
|
|
31
|
+
const res = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'apply', '-f', '-'], { input: manifest, timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
32
|
+
if (res.returncode !== 0)
|
|
33
|
+
throw new errors_1.CreateFailedError(`kubectl apply failed: ${(0, ask_1.why)(res)}`);
|
|
34
|
+
}
|
|
35
|
+
function mapOf(value) {
|
|
36
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
37
|
+
? value
|
|
38
|
+
: {};
|
|
39
|
+
}
|
|
40
|
+
function listOf(value) {
|
|
41
|
+
return Array.isArray(value) ? value : [];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One line naming what the pods in `namespace` are doing, or '' if it cannot ask.
|
|
45
|
+
*
|
|
46
|
+
* Deliberately best-effort and deliberately silent on failure: this runs beside an install
|
|
47
|
+
* that is going perfectly well, and a progress report that turned a slow create into a
|
|
48
|
+
* failed one would be worse than the silence it replaces.
|
|
49
|
+
*/
|
|
50
|
+
async function podsWaiting(namespace, context) {
|
|
51
|
+
const res = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'get', 'pods', '-o', 'json'], { timeout: names_1.PROBE_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
52
|
+
if (res.returncode !== 0)
|
|
53
|
+
return '';
|
|
54
|
+
let rows;
|
|
55
|
+
try {
|
|
56
|
+
rows = listOf(mapOf(JSON.parse(res.stdout || '{}')).items);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
if (rows.length === 0)
|
|
62
|
+
return 'no pods yet';
|
|
63
|
+
const tally = new Map();
|
|
64
|
+
for (const pod of rows) {
|
|
65
|
+
const status = mapOf(pod.status);
|
|
66
|
+
let reason = '';
|
|
67
|
+
for (const container of listOf(status.containerStatuses)) {
|
|
68
|
+
const waiting = String(mapOf(mapOf(container.state).waiting).reason ?? '');
|
|
69
|
+
if (waiting !== '') {
|
|
70
|
+
reason = waiting;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ContainerCreating on a fresh cluster is almost always the image coming down, and
|
|
75
|
+
// saying so is the difference between "it is stuck" and "it is doing the 1.6 GB".
|
|
76
|
+
// Named as what it IS, not as what it is probably doing.
|
|
77
|
+
const labels = {
|
|
78
|
+
ContainerCreating: 'starting (usually pulling the image)',
|
|
79
|
+
PodInitializing: 'initialising',
|
|
80
|
+
ImagePullBackOff: 'cannot pull its image',
|
|
81
|
+
ErrImagePull: 'cannot pull its image',
|
|
82
|
+
CrashLoopBackOff: 'crashing on start',
|
|
83
|
+
};
|
|
84
|
+
const label = labels[reason] ?? (reason !== '' ? reason : String(status.phase ?? 'unknown').toLowerCase());
|
|
85
|
+
tally.set(label, (tally.get(label) ?? 0) + 1);
|
|
86
|
+
}
|
|
87
|
+
return [...tally.entries()]
|
|
88
|
+
.sort((left, right) => (left[0] < right[0] ? -1 : left[0] > right[0] ? 1 : 0))
|
|
89
|
+
.map(([what, count]) => `${String(count)} ${what}`)
|
|
90
|
+
.join(', ');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Say what the longest step of a create is waiting for, while it waits.
|
|
94
|
+
*
|
|
95
|
+
* THE SILENCE THIS REPLACES WAS MEASURED: 254 seconds between "installing
|
|
96
|
+
* rocketchat/rocketchat" and the next line, on a real EKS create. Both rollback flags
|
|
97
|
+
* imply `--wait`, so helm blocks until the pods are Ready and prints nothing at all while
|
|
98
|
+
* it does -- the output is captured and returns in one piece at the end.
|
|
99
|
+
*
|
|
100
|
+
* Four minutes of nothing is the single worst thing a create does to whoever is watching
|
|
101
|
+
* it, and on a cloud cluster it is also the most expensive: it is where somebody decides
|
|
102
|
+
* the tool has hung and kills it, leaving a half-installed release that the next `up` then
|
|
103
|
+
* has to clear.
|
|
104
|
+
*
|
|
105
|
+
* Returns a stop function. It is a timer on the same event loop -- there is no second
|
|
106
|
+
* thread to join and no window where a stopped reporter is still running.
|
|
107
|
+
*/
|
|
108
|
+
function reportInstallProgress(namespace, context, emit) {
|
|
109
|
+
let waited = 0;
|
|
110
|
+
let stopped = false;
|
|
111
|
+
const timer = setInterval(() => {
|
|
112
|
+
void (async () => {
|
|
113
|
+
waited += 1;
|
|
114
|
+
if (waited < names_1.tuning.INSTALL_QUIET_S)
|
|
115
|
+
return;
|
|
116
|
+
if ((waited - names_1.tuning.INSTALL_QUIET_S) % names_1.tuning.INSTALL_REPORT_EVERY_S !== 0)
|
|
117
|
+
return;
|
|
118
|
+
let doing;
|
|
119
|
+
try {
|
|
120
|
+
doing = await podsWaiting(namespace, context);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return; // never fail a good install to report on it
|
|
124
|
+
}
|
|
125
|
+
// CHECKED AGAIN AFTER THE PROBE, not only before it. `podsWaiting` is a kubectl call
|
|
126
|
+
// that can take PROBE_TIMEOUT, and the install can finish while it is in flight --
|
|
127
|
+
// without this the reporter emits "still installing" AFTER the install has finished,
|
|
128
|
+
// into the middle of the next phase's output.
|
|
129
|
+
if (stopped || doing === '')
|
|
130
|
+
return;
|
|
131
|
+
const minutes = Math.trunc(waited / 60);
|
|
132
|
+
const seconds = String(Math.trunc(waited) % 60).padStart(2, '0');
|
|
133
|
+
(0, events_1.info)(emit, `still installing (${String(minutes)}m${seconds}s) — ${doing}`, {
|
|
134
|
+
phase: 'boot',
|
|
135
|
+
});
|
|
136
|
+
})();
|
|
137
|
+
}, 1000);
|
|
138
|
+
// The timer must not hold the process open: this is a reporter, not work.
|
|
139
|
+
timer.unref();
|
|
140
|
+
return () => {
|
|
141
|
+
stopped = true;
|
|
142
|
+
clearInterval(timer);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The flag that makes a failed install undo itself, named for the helm installed.
|
|
147
|
+
*
|
|
148
|
+
* `--atomic` DOES NOT EXIST IN HELM 4 -- it is `--rollback-on-failure`, checked against the
|
|
149
|
+
* 4.2.3 on this box. So the usual advice for a wedged release ("just add --atomic") would
|
|
150
|
+
* itself fail here, and a flag helm does not recognise turns a working install into a
|
|
151
|
+
* broken one. `CORE_TOOLS` admits helm 3, which has `--atomic` and not the new name, so the
|
|
152
|
+
* flag is chosen rather than written down.
|
|
153
|
+
*
|
|
154
|
+
* Empty for a helm too old to be sure about: no flag is the behaviour we already had, and
|
|
155
|
+
* guessing wrong costs the install itself.
|
|
156
|
+
*/
|
|
157
|
+
async function helmRollbackOnFailure() {
|
|
158
|
+
const found = await (0, tools_1.tool)('helm');
|
|
159
|
+
if (found.path === '' || found.version.length === 0)
|
|
160
|
+
return [];
|
|
161
|
+
return found.version[0] >= 4 ? ['--rollback-on-failure'] : ['--atomic'];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Helm release statuses that mean "an operation died part-way and the release is LOCKED".
|
|
165
|
+
* Helm refuses the next install or upgrade with "another operation
|
|
166
|
+
* (install/upgrade/rollback) is in progress" -- a sentence whose central claim is false,
|
|
167
|
+
* because nothing is in progress; the process that was doing it is gone.
|
|
168
|
+
*/
|
|
169
|
+
exports.PENDING_STATES = [
|
|
170
|
+
'pending-install',
|
|
171
|
+
'pending-upgrade',
|
|
172
|
+
'pending-rollback',
|
|
173
|
+
];
|
|
174
|
+
/**
|
|
175
|
+
* A release's STATUS and revision: `['', 0]` when there is no such release.
|
|
176
|
+
*
|
|
177
|
+
* `helm list -q` was the whole answer here, and from helm's own help: "By default, it lists
|
|
178
|
+
* all releases in any status." So a release wedged in `pending-install` was reported
|
|
179
|
+
* present exactly as a healthy one was, `up` went on to `helm upgrade --install`, and helm
|
|
180
|
+
* refused it -- for every subsequent attempt, including `--force`, with no path out that
|
|
181
|
+
* houston knew about.
|
|
182
|
+
*
|
|
183
|
+
* A release has a STATE, not a presence.
|
|
184
|
+
*/
|
|
185
|
+
async function releaseState(release, namespace, context) {
|
|
186
|
+
const res = await exec_1.kube.run(['helm', 'list', '--kube-context', context, '-n', namespace, '-o', 'json'], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
187
|
+
if (res.returncode !== 0) {
|
|
188
|
+
// Not "absent". The caller decides what to do about not knowing; guessing "there is
|
|
189
|
+
// nothing there" here is what would delete a record for a release that exists.
|
|
190
|
+
throw new errors_1.DockerError(`could not list helm releases in ${namespace} on '${context}': ${(0, ask_1.why)(res)}`);
|
|
191
|
+
}
|
|
192
|
+
let rows;
|
|
193
|
+
try {
|
|
194
|
+
rows = listOf(JSON.parse(res.stdout || '[]'));
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return ['', 0];
|
|
198
|
+
}
|
|
199
|
+
for (const item of rows) {
|
|
200
|
+
if (item.name === release) {
|
|
201
|
+
const revision = Number.parseInt(String(item.revision ?? 0), 10);
|
|
202
|
+
return [String(item.status ?? ''), Number.isFinite(revision) ? revision : 0];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return ['', 0];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Free a release stuck in a pending state. Returns what was done, or ''.
|
|
209
|
+
*
|
|
210
|
+
* The remedy DEPENDS ON WHETHER THERE IS ANYTHING TO GO BACK TO, and getting that wrong is
|
|
211
|
+
* why "just run helm rollback" is not the whole answer: a `pending-install` at revision 1
|
|
212
|
+
* never had a successful revision, so a rollback has no target and fails. That one is
|
|
213
|
+
* uninstalled instead -- nothing it created was ever serving.
|
|
214
|
+
*/
|
|
215
|
+
async function clearPendingRelease(release, namespace, context, { emit = events_1.nullEmit } = {}) {
|
|
216
|
+
const [state, revision] = await releaseState(release, namespace, context);
|
|
217
|
+
if (!exports.PENDING_STATES.includes(state))
|
|
218
|
+
return '';
|
|
219
|
+
const own = (0, names_1.isOurs)(context);
|
|
220
|
+
let res;
|
|
221
|
+
let action;
|
|
222
|
+
if (revision <= 1) {
|
|
223
|
+
(0, events_1.warn)(emit, `the '${release}' release is stuck in ${state} at revision ${String(revision)} — it ` +
|
|
224
|
+
'never completed once, so it is being removed rather than rolled back', { phase: 'provision' });
|
|
225
|
+
res = await exec_1.kube.run(['helm', 'uninstall', release, '--kube-context', context, '-n', namespace], {
|
|
226
|
+
timeout: names_1.APPLY_TIMEOUT,
|
|
227
|
+
own,
|
|
228
|
+
});
|
|
229
|
+
action = 'uninstalled';
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
(0, events_1.warn)(emit, `the '${release}' release is stuck in ${state} — rolling it back to revision ` +
|
|
233
|
+
`${String(revision - 1)} before continuing`, { phase: 'provision' });
|
|
234
|
+
res = await exec_1.kube.run([
|
|
235
|
+
'helm',
|
|
236
|
+
'rollback',
|
|
237
|
+
release,
|
|
238
|
+
String(revision - 1),
|
|
239
|
+
'--kube-context',
|
|
240
|
+
context,
|
|
241
|
+
'-n',
|
|
242
|
+
namespace,
|
|
243
|
+
], { timeout: names_1.INSTALL_TIMEOUT, own });
|
|
244
|
+
action = `rolled back to revision ${String(revision - 1)}`;
|
|
245
|
+
}
|
|
246
|
+
if (res.returncode !== 0) {
|
|
247
|
+
throw new errors_1.CreateFailedError(`the '${release}' release in ${namespace} is stuck in ${state} and could not be ` +
|
|
248
|
+
`freed: ${(0, ask_1.why)(res)}. Nothing is actually in progress — the operation that was ` +
|
|
249
|
+
`holding it has gone. Free it by hand with \`helm uninstall ${release} -n ` +
|
|
250
|
+
`${namespace}\` and try again`);
|
|
251
|
+
}
|
|
252
|
+
(0, events_1.info)(emit, `'${release}' ${action}`, { phase: 'provision' });
|
|
253
|
+
return action;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* `helm install` with values on stdin, so nothing is written to disk.
|
|
257
|
+
*
|
|
258
|
+
* The release is `rocketchat` -- the official docs' own name -- so every command in them
|
|
259
|
+
* works here by substituting the namespace.
|
|
260
|
+
*/
|
|
261
|
+
async function install({ namespace, context, values, chartVersion = '', emit = events_1.nullEmit, }) {
|
|
262
|
+
// `upgrade --install`, not `install`. Bringing a workspace back up re-runs this sequence,
|
|
263
|
+
// and plain `install` fails on a release that is already there.
|
|
264
|
+
//
|
|
265
|
+
// A RELEASE LEFT PENDING BY A KILLED OPERATION BLOCKS EVERY LATER ATTEMPT, and helm's
|
|
266
|
+
// refusal says "another operation is in progress" -- which is not true and sends the
|
|
267
|
+
// reader looking for a process that does not exist. Freed here rather than reported,
|
|
268
|
+
// because the state is not something the person asking for a workspace did or can fix.
|
|
269
|
+
try {
|
|
270
|
+
await clearPendingRelease(names_1.RELEASE, namespace, context, { emit });
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
// Could not even list the releases. Let the install below fail on its own terms; its
|
|
274
|
+
// message is about the thing actually being attempted.
|
|
275
|
+
if (!(error instanceof errors_1.DockerError))
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
// THE SAME UNDO THE SHARED RELEASES GET. The rollback flag was applied to the operator
|
|
279
|
+
// and the monitoring stack and not to the workspace's own release -- the one a workspace
|
|
280
|
+
// actually is -- so a partly-applied Rocket.Chat upgrade stayed partly applied.
|
|
281
|
+
const argv = [
|
|
282
|
+
'helm',
|
|
283
|
+
'upgrade',
|
|
284
|
+
'--install',
|
|
285
|
+
names_1.RELEASE,
|
|
286
|
+
names_1.CHART,
|
|
287
|
+
'--kube-context',
|
|
288
|
+
context,
|
|
289
|
+
'-n',
|
|
290
|
+
namespace,
|
|
291
|
+
'--values',
|
|
292
|
+
'-',
|
|
293
|
+
...(await helmRollbackOnFailure()),
|
|
294
|
+
];
|
|
295
|
+
if (chartVersion !== '')
|
|
296
|
+
argv.push('--version', chartVersion);
|
|
297
|
+
// BESIDE the install, not instead of it. helm is left exactly as it was -- one call whose
|
|
298
|
+
// output comes back in one piece -- and a reporter runs alongside to say what the pods
|
|
299
|
+
// are doing, because helm says nothing at all while `--wait` waits.
|
|
300
|
+
const stop = reportInstallProgress(namespace, context, emit);
|
|
301
|
+
let res;
|
|
302
|
+
try {
|
|
303
|
+
res = await exec_1.kube.run(argv, {
|
|
304
|
+
// `dumps(values)` on stdin: the values file helm reads, in the established bytes,
|
|
305
|
+
// spaced and ASCII-escaped. `JSON.stringify` wrote it compact.
|
|
306
|
+
input: (0, json_text_1.dumps)(values),
|
|
307
|
+
timeout: names_1.INSTALL_TIMEOUT,
|
|
308
|
+
env: (0, exec_1.helmEnv)(context),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
// In a `finally`, so a failed install does not leave a reporter describing a namespace
|
|
313
|
+
// nothing is installing into any more.
|
|
314
|
+
stop();
|
|
315
|
+
}
|
|
316
|
+
if (res.returncode !== 0)
|
|
317
|
+
throw new errors_1.CreateFailedError(`helm install failed: ${(0, ask_1.why)(res)}`);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* The values a release was installed with -- its `values.yaml`, from helm itself.
|
|
321
|
+
*
|
|
322
|
+
* `helm get values` returns exactly the user-supplied values, which is what a values file
|
|
323
|
+
* IS: the chart's computed defaults are its own business and come back only with `--all`.
|
|
324
|
+
* So this is the guide's "your values.yaml", read from the live release rather than rebuilt
|
|
325
|
+
* from our own records -- it cannot drift from what is actually deployed.
|
|
326
|
+
*/
|
|
327
|
+
async function releaseValues(release, namespace, context, { all = false } = {}) {
|
|
328
|
+
const res = await exec_1.kube.run([
|
|
329
|
+
'helm',
|
|
330
|
+
'get',
|
|
331
|
+
'values',
|
|
332
|
+
release,
|
|
333
|
+
'--kube-context',
|
|
334
|
+
context,
|
|
335
|
+
'-n',
|
|
336
|
+
namespace,
|
|
337
|
+
// `--all`: the chart's defaults as well, merged as the release was rendered with them.
|
|
338
|
+
...(all ? ['--all'] : []),
|
|
339
|
+
'-o',
|
|
340
|
+
'json',
|
|
341
|
+
], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
342
|
+
if (res.returncode !== 0) {
|
|
343
|
+
throw new errors_1.DockerError(`could not read the values of release '${release}' in ${namespace}: ${(0, ask_1.why)(res)}`);
|
|
344
|
+
}
|
|
345
|
+
let doc;
|
|
346
|
+
try {
|
|
347
|
+
doc = JSON.parse(res.stdout || 'null');
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
doc = null;
|
|
351
|
+
}
|
|
352
|
+
// `helm get values` answers `null` for a release installed with no values of its own.
|
|
353
|
+
// That is an empty values file, not a failure.
|
|
354
|
+
return doc !== null && typeof doc === 'object' && !Array.isArray(doc)
|
|
355
|
+
? doc
|
|
356
|
+
: {};
|
|
357
|
+
}
|
|
358
|
+
/** Give Helm the complete updated values file for an image upgrade. */
|
|
359
|
+
async function runImageUpgrade(namespace, context, chartVersion, values) {
|
|
360
|
+
const res = await exec_1.kube.run([
|
|
361
|
+
'helm',
|
|
362
|
+
'upgrade',
|
|
363
|
+
names_1.RELEASE,
|
|
364
|
+
names_1.CHART,
|
|
365
|
+
'--kube-context',
|
|
366
|
+
context,
|
|
367
|
+
'-n',
|
|
368
|
+
namespace,
|
|
369
|
+
'--version',
|
|
370
|
+
chartVersion,
|
|
371
|
+
'--values',
|
|
372
|
+
'-',
|
|
373
|
+
],
|
|
374
|
+
// `dumps(values)` on stdin, as the install above pipes it.
|
|
375
|
+
{ input: (0, json_text_1.dumps)(values), timeout: names_1.INSTALL_TIMEOUT, env: (0, exec_1.helmEnv)(context) });
|
|
376
|
+
if (res.returncode !== 0)
|
|
377
|
+
throw new errors_1.DockerError(`helm upgrade failed: ${(0, ask_1.why)(res)}`);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Render the Rocket.Chat release again, from the chart version and the values it is deployed
|
|
381
|
+
* with, so the only thing that can change is what the cluster now lets the chart render.
|
|
382
|
+
*
|
|
383
|
+
* A chart's templates read the cluster as well as their values: Rocket.Chat's renders its
|
|
384
|
+
* PodMonitor only where the cluster serves that kind (see `monitoring.ensurePodMonitor`).
|
|
385
|
+
*/
|
|
386
|
+
async function rerenderRelease(namespace, context) {
|
|
387
|
+
const res = await exec_1.kube.run(['helm', 'list', '--kube-context', context, '-n', namespace, '-o', 'json'], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
388
|
+
let rows = [];
|
|
389
|
+
try {
|
|
390
|
+
rows = listOf(JSON.parse(res.stdout || '[]'));
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
// Unreadable is refused below, with whatever helm said.
|
|
394
|
+
}
|
|
395
|
+
// `helm list` names the chart with its version: `rocketchat-7.0.2`.
|
|
396
|
+
const chart = String(rows.find((row) => row.name === names_1.RELEASE)?.chart ?? '');
|
|
397
|
+
const prefix = `${names_1.CHART.slice(names_1.CHART.lastIndexOf('/') + 1)}-`;
|
|
398
|
+
if (res.returncode !== 0 || !chart.startsWith(prefix)) {
|
|
399
|
+
throw new errors_1.DockerError(`could not read which chart '${names_1.RELEASE}' in ${namespace} runs: ${(0, ask_1.why)(res)}`);
|
|
400
|
+
}
|
|
401
|
+
await runImageUpgrade(namespace, context, chart.slice(prefix.length), await releaseValues(names_1.RELEASE, namespace, context));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Move a release to a new Rocket.Chat image, the way the official guide does.
|
|
405
|
+
*
|
|
406
|
+
* The guide says: change `image.tag` in your values and run `helm upgrade`. This is that,
|
|
407
|
+
* with two differences it explicitly warns about or implies.
|
|
408
|
+
*
|
|
409
|
+
* First, the chart version IS pinned. The guide's own note says its command "does not pin a
|
|
410
|
+
* chart version, so it installs the latest Rocket.Chat Helm chart" -- which for a tool whose
|
|
411
|
+
* entire purpose is reproducing a customer's exact version would quietly deploy different
|
|
412
|
+
* software than the one asked for.
|
|
413
|
+
*
|
|
414
|
+
* Second, the release's own values are carried over rather than a values file being
|
|
415
|
+
* re-rendered. The one value that must NOT be carried over is the oplog URL: Rocket.Chat 8
|
|
416
|
+
* dropped oplog tailing and chart 7.0.0 removed the key.
|
|
417
|
+
*
|
|
418
|
+
* THIS IS THE GUIDE'S PROCEDURE LITERALLY. It was `--reuse-values`, which is the one thing
|
|
419
|
+
* the guide does not do, and two separate failures came of that. `--reuse-values` never
|
|
420
|
+
* applies the NEW chart's defaults, so a chart that ADDS a templated value renders against a
|
|
421
|
+
* map with no such key -- RC 7.4.0 to 7.10.15 crosses chart 6.23.2 to 6.26.0, which added
|
|
422
|
+
* `podMonitor`, and it died on `nil pointer evaluating interface {}.enabled`. And it carries
|
|
423
|
+
* values that were only ever correct for the chart they were computed against: carrying
|
|
424
|
+
* `fsGroup: null` across the 6.26.0 to 7.0.0 boundary reintroduces the bug it was written to
|
|
425
|
+
* fix. `--reset-then-reuse-values` has the same defect, so no reuse flag is passed at all.
|
|
426
|
+
*/
|
|
427
|
+
async function upgradeImage({ namespace, context, chartVersion, imageRepo, tag, oplog, }) {
|
|
428
|
+
const values = await releaseValues(names_1.RELEASE, namespace, context);
|
|
429
|
+
// RECOMPUTED FOR THE TARGET CHART, never carried.
|
|
430
|
+
delete values.containerSecurityContext;
|
|
431
|
+
Object.assign(values, await (0, manifests_1.containerSecurityContext)(chartVersion));
|
|
432
|
+
values.image = { ...mapOf(values.image), repository: imageRepo, tag };
|
|
433
|
+
if (!oplog) {
|
|
434
|
+
// With a whole values file supplied, DELETING the key is how you say "not this any
|
|
435
|
+
// more"; `--set ...=null` was the way to say it through a flag.
|
|
436
|
+
delete values.externalMongodbOplogUrl;
|
|
437
|
+
}
|
|
438
|
+
await runImageUpgrade(namespace, context, chartVersion, values);
|
|
439
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MONGO_READY_INTERVAL = exports.RS_INITIATE = void 0;
|
|
4
|
+
exports.initReplicaSet = initReplicaSet;
|
|
5
|
+
/**
|
|
6
|
+
* Initialising the MongoDB replica set, which a StatefulSet cannot do for itself.
|
|
7
|
+
*/
|
|
8
|
+
const errors_1 = require("../../lib/errors");
|
|
9
|
+
const events_1 = require("../../lib/events");
|
|
10
|
+
const ask_1 = require("./ask");
|
|
11
|
+
const exec_1 = require("./exec");
|
|
12
|
+
const names_1 = require("./names");
|
|
13
|
+
/**
|
|
14
|
+
* Rocket.Chat needs change streams, which need a replica set. `--replSet rs0` only puts
|
|
15
|
+
* mongod IN replica-set mode; without `rs.initiate()` there is no primary, so nothing
|
|
16
|
+
* can write and Rocket.Chat waits forever. Compose has a `mongo-init` service for
|
|
17
|
+
* exactly this; the first cut of this module had no equivalent, and a real workspace sat
|
|
18
|
+
* at 5 pods for 540 s with Rocket.Chat never becoming ready and nothing in its logs
|
|
19
|
+
* naming MongoDB.
|
|
20
|
+
*/
|
|
21
|
+
exports.RS_INITIATE = `rs.initiate({_id:"rs0",members:[{_id:0,host:"${names_1.MONGO_SERVICE}-0.${names_1.MONGO_SERVICE}:27017"}]})`;
|
|
22
|
+
exports.MONGO_READY_INTERVAL = 5.0;
|
|
23
|
+
/**
|
|
24
|
+
* The transient shapes of "the pod is not ready for this yet", which are worth retrying
|
|
25
|
+
* because they resolve on their own within seconds.
|
|
26
|
+
*
|
|
27
|
+
* The second one is a defect found by running this on cold clusters. `initReplicaSet`
|
|
28
|
+
* waits for `containerStatuses[0].started` and says exactly why it cannot wait for
|
|
29
|
+
* READINESS -- readiness needs the replica set, and this is the initiation. That
|
|
30
|
+
* reasoning is right, and it leaves a window: the container is up and mongod has not yet
|
|
31
|
+
* bound :27017. The exec then fails with `MongoNetworkError: connect ECONNREFUSED
|
|
32
|
+
* 127.0.0.1:27017`, and the retry predicate was an allow-list of ONE error, so a
|
|
33
|
+
* connection refusal returned on the first attempt and failed the whole create.
|
|
34
|
+
* Reproduced twice out of two on a freshly installed k3s -- an empty containerd store
|
|
35
|
+
* and a cold PVC make mongod slow enough to lose the race every time. So it fired
|
|
36
|
+
* precisely on somebody's first create, which is the worst place for it.
|
|
37
|
+
*/
|
|
38
|
+
const MONGO_TRANSIENT = [
|
|
39
|
+
// `kubectl exec` into a container that exists but is not exec-able yet, or is on its
|
|
40
|
+
// way out: a pod reports `started` while TERMINATING.
|
|
41
|
+
'container not found',
|
|
42
|
+
// mongod has not bound its socket yet. Both spellings appear, and the driver
|
|
43
|
+
// lower-cases neither for us.
|
|
44
|
+
'econnrefused',
|
|
45
|
+
'connection refused',
|
|
46
|
+
];
|
|
47
|
+
const realSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
48
|
+
async function mongoExecOnce(context, namespace, script) {
|
|
49
|
+
return await exec_1.kube.run([
|
|
50
|
+
'kubectl',
|
|
51
|
+
'--context',
|
|
52
|
+
context,
|
|
53
|
+
'-n',
|
|
54
|
+
namespace,
|
|
55
|
+
'exec',
|
|
56
|
+
`${names_1.MONGO_SERVICE}-0`,
|
|
57
|
+
'--',
|
|
58
|
+
'mongosh',
|
|
59
|
+
names_1.MONGO_DIRECT_URI,
|
|
60
|
+
'--quiet',
|
|
61
|
+
'--eval',
|
|
62
|
+
script,
|
|
63
|
+
], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* mongosh inside the MongoDB pod, retried while the failure is a transient one.
|
|
67
|
+
*
|
|
68
|
+
* Retrying is safe for everything this is asked to run: `rs.initiate` is guarded by its
|
|
69
|
+
* caller's "already initialized" check, and `rs.status().ok` is a read.
|
|
70
|
+
*/
|
|
71
|
+
async function mongoExec(context, namespace, script, { tries = 5, sleep = realSleep } = {}) {
|
|
72
|
+
let res = await mongoExecOnce(context, namespace, script);
|
|
73
|
+
for (let attempt = 1; attempt < tries; attempt += 1) {
|
|
74
|
+
const combined = `${res.stdout}${res.stderr}`.toLowerCase();
|
|
75
|
+
if (res.returncode === 0 || !MONGO_TRANSIENT.some((mark) => combined.includes(mark))) {
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
await sleep(2.0);
|
|
79
|
+
res = await mongoExecOnce(context, namespace, script);
|
|
80
|
+
}
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
83
|
+
/** Wait until a restarted single-node set can accept writes again. */
|
|
84
|
+
async function waitForPrimary(context, namespace, { tries = 6, sleep = realSleep } = {}) {
|
|
85
|
+
for (let attempt = 0; attempt < tries; attempt += 1) {
|
|
86
|
+
const res = await mongoExec(context, namespace, 'db.hello().isWritablePrimary', { sleep });
|
|
87
|
+
if (res.stdout.trim().toLowerCase() === 'true')
|
|
88
|
+
return true;
|
|
89
|
+
await sleep(2.0);
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/** Verify a primary, repairing a persisted REMOVED member after restart. */
|
|
94
|
+
async function finishReplicaSet(context, namespace, combined, emit, sleep) {
|
|
95
|
+
if (await waitForPrimary(context, namespace, { sleep })) {
|
|
96
|
+
(0, events_1.info)(emit, 'replica set ready', { phase: 'boot' });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (combined.includes('already initialized')) {
|
|
100
|
+
const repaired = await mongoExec(context, namespace, 'rs.reconfig(rs.conf(), {force:true})', {
|
|
101
|
+
sleep,
|
|
102
|
+
});
|
|
103
|
+
if (repaired.returncode === 0 && (await waitForPrimary(context, namespace, { sleep }))) {
|
|
104
|
+
(0, events_1.info)(emit, 'replica set recovered after restart', { phase: 'boot' });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const ok = await mongoExec(context, namespace, 'rs.status().ok', { sleep });
|
|
109
|
+
if (ok.stdout.trim() !== '1') {
|
|
110
|
+
throw new errors_1.CreateFailedError("the MongoDB replica set is not initiated, so Rocket.Chat's change streams cannot " +
|
|
111
|
+
`work: ${(0, ask_1.why)(ok)}`);
|
|
112
|
+
}
|
|
113
|
+
(0, events_1.info)(emit, 'replica set ready', { phase: 'boot' });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Wait for MongoDB, initiate the single-node replica set, and VERIFY it.
|
|
117
|
+
*
|
|
118
|
+
* The shape exists to avoid a measured failure: `kubectl wait` called the instant after
|
|
119
|
+
* `apply`, before the pod existed, so it failed immediately and `rs.initiate` then ran
|
|
120
|
+
* against nothing -- with both errors discarded and the repro reported as created.
|
|
121
|
+
*
|
|
122
|
+
* So: poll for the pod, initiate, tolerate an already-initiated set, and check
|
|
123
|
+
* `rs.status().ok` rather than trusting an exit code. A failure here is
|
|
124
|
+
* `CreateFailedError` -- exit 7, known dead -- because every second spent waiting
|
|
125
|
+
* afterwards is spent waiting for something that cannot happen.
|
|
126
|
+
*/
|
|
127
|
+
async function initReplicaSet({ namespace, context, emit = events_1.nullEmit, sleep = realSleep, }) {
|
|
128
|
+
// RUNNING, not READY -- and the difference is a circular wait. The readiness probe
|
|
129
|
+
// cannot pass until the replica set is initiated, and initiation cannot run until
|
|
130
|
+
// something answers. Waiting on readiness here made the whole create a coin flip: the
|
|
131
|
+
// probe occasionally scraped through and the workspace built, otherwise it timed out
|
|
132
|
+
// at 300 s reporting that MongoDB never became ready -- while mongod had in fact been
|
|
133
|
+
// up the whole time, logging "ReadConcernMajorityNotAvailableYet".
|
|
134
|
+
let started = false;
|
|
135
|
+
for (let attempt = 0; attempt < names_1.tuning.MONGO_READY_TRIES; attempt += 1) {
|
|
136
|
+
// `started`, not `phase`. A pod reports Running before its container is exec-able,
|
|
137
|
+
// and `kubectl exec` then fails with `container not found ("mongod")` -- which is
|
|
138
|
+
// what `up` after a plain `down` hit: the PVC was still there, the StatefulSet came
|
|
139
|
+
// back, the pod said Running, and the exec raced the container.
|
|
140
|
+
//
|
|
141
|
+
// Not `ready` either: readiness needs the replica set initiated, and this IS the
|
|
142
|
+
// initiation. `started` is the field that means "the container is up", independent
|
|
143
|
+
// of whether it is serving.
|
|
144
|
+
const res = await exec_1.kube.run([
|
|
145
|
+
'kubectl',
|
|
146
|
+
'--context',
|
|
147
|
+
context,
|
|
148
|
+
'-n',
|
|
149
|
+
namespace,
|
|
150
|
+
'get',
|
|
151
|
+
'pod',
|
|
152
|
+
`${names_1.MONGO_SERVICE}-0`,
|
|
153
|
+
'-o',
|
|
154
|
+
'jsonpath={.status.containerStatuses[0].started}',
|
|
155
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
156
|
+
if (res.stdout.trim() === 'true') {
|
|
157
|
+
started = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (attempt % 6 === 0)
|
|
161
|
+
(0, events_1.info)(emit, 'waiting for MongoDB', { phase: 'wait' });
|
|
162
|
+
await sleep(exports.MONGO_READY_INTERVAL);
|
|
163
|
+
}
|
|
164
|
+
if (!started) {
|
|
165
|
+
throw new errors_1.CreateFailedError('the MongoDB pod never started, and Rocket.Chat cannot work without it ' +
|
|
166
|
+
`(kubectl -n ${namespace} describe pod ${names_1.MONGO_SERVICE}-0)`);
|
|
167
|
+
}
|
|
168
|
+
// This is still database provisioning; scenario resources follow at 25%, then the
|
|
169
|
+
// Rocket.Chat chart at 60%. Naming 45 here sent the create progress backwards.
|
|
170
|
+
(0, events_1.info)(emit, 'initiating the replica set', { phase: 'boot', pct: 22 });
|
|
171
|
+
const res = await mongoExec(context, namespace, exports.RS_INITIATE, { sleep });
|
|
172
|
+
const combined = `${res.stdout}${res.stderr}`.toLowerCase();
|
|
173
|
+
if (res.returncode !== 0 && !combined.includes('already initialized')) {
|
|
174
|
+
throw new errors_1.CreateFailedError(`could not initiate the MongoDB replica set: ${combined.trim().slice(0, 300)}`);
|
|
175
|
+
}
|
|
176
|
+
// A cold restart can resolve the member hostname too late. MongoDB then keeps the
|
|
177
|
+
// persisted member in REMOVED and never elects it again, even after DNS is healthy.
|
|
178
|
+
// `finishReplicaSet` reapplies that one-member config with force.
|
|
179
|
+
await finishReplicaSet(context, namespace, combined, emit, sleep);
|
|
180
|
+
}
|