@rocket.chat/houston 0.27.0-next.3 → 2.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +109 -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 +642 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/loadtest.md +264 -0
- package/data/docs/troubleshooting.md +203 -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 +170 -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 +57 -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 +3694 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +814 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2599 -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 +345 -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 +694 -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 +1549 -0
- package/dist/core/lifecycle/create-k8s.js +960 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +636 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +862 -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 +818 -0
- package/dist/core/lifecycle/request.js +510 -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 +1051 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +976 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1336 -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 +877 -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 +371 -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 +299 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +191 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +236 -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 +70 -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,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POD_GONE_INTERVAL = exports.POD_GONE_TRIES = exports.SCALE_ANNOTATION = void 0;
|
|
4
|
+
exports.scaleWorkspace = scaleWorkspace;
|
|
5
|
+
exports.desiredReplicas = desiredReplicas;
|
|
6
|
+
exports.mongoPodsTheOperatorKeeps = mongoPodsTheOperatorKeeps;
|
|
7
|
+
exports.stopWorkspace = stopWorkspace;
|
|
8
|
+
exports.startWorkspace = startWorkspace;
|
|
9
|
+
exports.scaleRocketchat = scaleRocketchat;
|
|
10
|
+
exports.rocketchatReplicas = rocketchatReplicas;
|
|
11
|
+
exports.restoreRocketchatReplicas = restoreRocketchatReplicas;
|
|
12
|
+
/**
|
|
13
|
+
* Scaling a workspace down and back up, and remembering what it was.
|
|
14
|
+
*/
|
|
15
|
+
const errors_1 = require("../../lib/errors");
|
|
16
|
+
const events_1 = require("../../lib/events");
|
|
17
|
+
const json_text_1 = require("../../lib/json-text");
|
|
18
|
+
const ask_1 = require("./ask");
|
|
19
|
+
const exec_1 = require("./exec");
|
|
20
|
+
const names_1 = require("./names");
|
|
21
|
+
const namespace_1 = require("./namespace");
|
|
22
|
+
const replicaset_1 = require("./replicaset");
|
|
23
|
+
/**
|
|
24
|
+
* Where the replica count lives while a workspace is stopped. Kubernetes has no "stopped"
|
|
25
|
+
* state -- scaling to 0 is the whole mechanism -- so the number that was there has to be
|
|
26
|
+
* written down or `start` cannot put it back. An annotation on the namespace rather than
|
|
27
|
+
* repro.json, because `kubectl scale` by hand is a legitimate thing for someone to do and
|
|
28
|
+
* the cluster should carry its own truth.
|
|
29
|
+
*/
|
|
30
|
+
exports.SCALE_ANNOTATION = 'houston.io/replicas-before-stop';
|
|
31
|
+
/** Up to a minute for pods to terminate. MongoDB gets a grace period and uses it. */
|
|
32
|
+
exports.POD_GONE_TRIES = 30;
|
|
33
|
+
exports.POD_GONE_INTERVAL = 2.0;
|
|
34
|
+
const realSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
35
|
+
/**
|
|
36
|
+
* Every workload in the namespace that has a replica count, as `kind/name`.
|
|
37
|
+
*
|
|
38
|
+
* The MongoDB StatefulSet is included deliberately. `docker compose stop` stops the
|
|
39
|
+
* database too, and a workspace that keeps 8Gi of MongoDB resident while claiming to be
|
|
40
|
+
* stopped is not stopped in the sense anyone means -- the whole reason to stop one on a
|
|
41
|
+
* laptop is to get the memory back.
|
|
42
|
+
*/
|
|
43
|
+
async function scalables(namespace, context) {
|
|
44
|
+
const res = await exec_1.kube.run([
|
|
45
|
+
'kubectl',
|
|
46
|
+
'--context',
|
|
47
|
+
context,
|
|
48
|
+
'-n',
|
|
49
|
+
namespace,
|
|
50
|
+
'get',
|
|
51
|
+
'deployment,statefulset',
|
|
52
|
+
'-o',
|
|
53
|
+
'name',
|
|
54
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
55
|
+
return res.stdout
|
|
56
|
+
.split('\n')
|
|
57
|
+
.map((line) => line.trim())
|
|
58
|
+
.filter((line) => line !== '');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Scale every workload in a workspace to `replicas`. Returns how many it moved.
|
|
62
|
+
*
|
|
63
|
+
* `--all` is not used: it would also catch anything a preset or a person added, and
|
|
64
|
+
* scaling something back up to a number it never had is worse than leaving it.
|
|
65
|
+
*/
|
|
66
|
+
async function scaleWorkspace(name, { replicas, context, version = '<version>', emit: _emit = events_1.nullEmit, }) {
|
|
67
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
68
|
+
const targets = await scalables(namespace, context);
|
|
69
|
+
if (targets.length === 0) {
|
|
70
|
+
throw new errors_1.NotFoundError(`'${name}' has no workloads to scale -- it was \`down\`ed, so there is nothing to ` +
|
|
71
|
+
`stop or start. Recreate it with \`houston up --version ${version} --name ${name}\``);
|
|
72
|
+
}
|
|
73
|
+
const res = await exec_1.kube.run([
|
|
74
|
+
'kubectl',
|
|
75
|
+
'--context',
|
|
76
|
+
context,
|
|
77
|
+
'-n',
|
|
78
|
+
namespace,
|
|
79
|
+
'scale',
|
|
80
|
+
`--replicas=${String(replicas)}`,
|
|
81
|
+
...targets,
|
|
82
|
+
], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
83
|
+
if (res.returncode !== 0)
|
|
84
|
+
throw new errors_1.DockerError(`could not scale '${name}': ${(0, ask_1.why)(res)}`);
|
|
85
|
+
return targets.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The Rocket.Chat Deployment's DESIRED replica count, or -1 if unknown.
|
|
89
|
+
*
|
|
90
|
+
* `.spec.replicas`, not `.status`: the question is what was asked for, so that a workspace
|
|
91
|
+
* scaled to zero reads as stopped the instant `stop` returns rather than once the pods
|
|
92
|
+
* have finished terminating.
|
|
93
|
+
*/
|
|
94
|
+
async function desiredReplicas(name, { context }) {
|
|
95
|
+
const res = await exec_1.kube.run([
|
|
96
|
+
'kubectl',
|
|
97
|
+
'--context',
|
|
98
|
+
context,
|
|
99
|
+
'-n',
|
|
100
|
+
await (0, namespace_1.namespaceFor)(name),
|
|
101
|
+
'get',
|
|
102
|
+
'deployment',
|
|
103
|
+
`${names_1.RELEASE}-rocketchat`,
|
|
104
|
+
'-o',
|
|
105
|
+
'jsonpath={.spec.replicas}',
|
|
106
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
107
|
+
const count = Number.parseInt(res.stdout.trim(), 10);
|
|
108
|
+
return Number.isFinite(count) ? count : -1;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Pod names (as `pod/<n>`) that an operator-managed MongoDB will not give up.
|
|
112
|
+
*
|
|
113
|
+
* Empty for the hand-written StatefulSet, which scales to zero like anything else.
|
|
114
|
+
*/
|
|
115
|
+
async function mongoPodsTheOperatorKeeps(name, { context }) {
|
|
116
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
117
|
+
const res = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'get', 'mongodbcommunity', '-o', 'name'], { own: (0, names_1.isOurs)(context) });
|
|
118
|
+
if (res.returncode !== 0 || res.stdout.trim() === '')
|
|
119
|
+
return new Set();
|
|
120
|
+
const pods = await exec_1.kube.run([
|
|
121
|
+
'kubectl',
|
|
122
|
+
'--context',
|
|
123
|
+
context,
|
|
124
|
+
'-n',
|
|
125
|
+
namespace,
|
|
126
|
+
'get',
|
|
127
|
+
'pods',
|
|
128
|
+
'-l',
|
|
129
|
+
`app=${names_1.MONGO_SERVICE}-svc`,
|
|
130
|
+
'-o',
|
|
131
|
+
'name',
|
|
132
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
133
|
+
return new Set(pods.stdout.split(/\s+/u).filter((entry) => entry.trim() !== ''));
|
|
134
|
+
}
|
|
135
|
+
/** Scale to zero, remembering what to come back to, and wait for it. */
|
|
136
|
+
async function stopWorkspace(name, { context, version = '<version>', emit = events_1.nullEmit, sleep = realSleep, }) {
|
|
137
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
138
|
+
// Recorded BEFORE scaling, or the number read back is the zero we just wrote.
|
|
139
|
+
const before = {};
|
|
140
|
+
for (const target of await scalables(namespace, context)) {
|
|
141
|
+
const res = await exec_1.kube.run([
|
|
142
|
+
'kubectl',
|
|
143
|
+
'--context',
|
|
144
|
+
context,
|
|
145
|
+
'-n',
|
|
146
|
+
namespace,
|
|
147
|
+
'get',
|
|
148
|
+
target,
|
|
149
|
+
'-o',
|
|
150
|
+
'jsonpath={.spec.replicas}',
|
|
151
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
152
|
+
const count = res.stdout.trim();
|
|
153
|
+
if (count !== '' && count !== '0')
|
|
154
|
+
before[target] = count;
|
|
155
|
+
}
|
|
156
|
+
if (Object.keys(before).length > 0) {
|
|
157
|
+
await exec_1.kube.run([
|
|
158
|
+
'kubectl',
|
|
159
|
+
'--context',
|
|
160
|
+
context,
|
|
161
|
+
'-n',
|
|
162
|
+
namespace,
|
|
163
|
+
'annotate',
|
|
164
|
+
'--overwrite',
|
|
165
|
+
'namespace',
|
|
166
|
+
namespace,
|
|
167
|
+
// `dumps(before)`: the established spacing, so the annotation -- cluster state the
|
|
168
|
+
// other build reads back on `start` -- is the same bytes whichever build stopped
|
|
169
|
+
// the workspace. `JSON.stringify` wrote it compact.
|
|
170
|
+
`${exports.SCALE_ANNOTATION}=${(0, json_text_1.dumps)(before)}`,
|
|
171
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
172
|
+
}
|
|
173
|
+
const moved = await scaleWorkspace(name, { replicas: 0, context, version, emit });
|
|
174
|
+
// An operator-managed MongoDB CANNOT be scaled to zero: the operator reconciles its
|
|
175
|
+
// StatefulSet straight back, and the Community operator has no way to pause
|
|
176
|
+
// reconciliation. So its pods are expected to survive `stop`, and two things follow.
|
|
177
|
+
// First, the wait below must not require them to go, or every stop and restart on the
|
|
178
|
+
// operator path burns the whole budget waiting for something that will never happen.
|
|
179
|
+
// Second and worse, `stop` documents itself as giving the memory back -- on this path it
|
|
180
|
+
// gives back Rocket.Chat's and not MongoDB's, and said nothing.
|
|
181
|
+
const survivors = await mongoPodsTheOperatorKeeps(name, { context });
|
|
182
|
+
if (survivors.size > 0) {
|
|
183
|
+
(0, events_1.warn)(emit, 'MongoDB stays up: it is operator-managed, and the operator recreates it as fast as ' +
|
|
184
|
+
"it is scaled down (there is no way to pause its reconciliation). Rocket.Chat's " +
|
|
185
|
+
`memory is freed, MongoDB's is not — \`houston down --name ${name} --volumes\` is ` +
|
|
186
|
+
'what reclaims it.', { phase: 'done' });
|
|
187
|
+
}
|
|
188
|
+
// WAIT for the pods to actually go, rather than returning on the API call. `restart` is
|
|
189
|
+
// stop-then-start, so returning early scales back up while the old pods are still
|
|
190
|
+
// Terminating -- and the readiness check then finds one of THOSE, reports ready, and the
|
|
191
|
+
// port-forward attaches to a pod on its way out. This is the fourth time on this runtime
|
|
192
|
+
// that trusting a readiness signal over the actual state produced a workspace that looks
|
|
193
|
+
// up and is not.
|
|
194
|
+
for (let attempt = 0; attempt < exports.POD_GONE_TRIES; attempt += 1) {
|
|
195
|
+
const res = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'get', 'pods', '-o', 'name'], { own: (0, names_1.isOurs)(context) });
|
|
196
|
+
const left = res.stdout.split(/\s+/u).filter((entry) => entry.trim() !== '');
|
|
197
|
+
if (left.filter((pod) => !survivors.has(pod)).length === 0)
|
|
198
|
+
break;
|
|
199
|
+
await sleep(exports.POD_GONE_INTERVAL);
|
|
200
|
+
}
|
|
201
|
+
(0, events_1.info)(emit, `scaled ${String(moved)} workload(s) to zero`, { phase: 'done' });
|
|
202
|
+
return moved;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Scale back to whatever was recorded, or to 1 if nothing was.
|
|
206
|
+
*
|
|
207
|
+
* A workspace stopped by hand carries no annotation, and refusing to start it would be
|
|
208
|
+
* pedantry -- 1 is what `up` would have given it.
|
|
209
|
+
*/
|
|
210
|
+
async function startWorkspace(name, { context, version = '<version>', emit = events_1.nullEmit, }) {
|
|
211
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
212
|
+
// Read as JSON and pick the key here, rather than through jsonpath.
|
|
213
|
+
//
|
|
214
|
+
// jsonpath was how this went wrong: the key is `houston.io/replicas-before-stop` and the
|
|
215
|
+
// code escaped the SLASH while leaving the DOT in `houston.io` unescaped -- so jsonpath
|
|
216
|
+
// read `houston` and `io/...` as separate path segments, matched nothing, and returned
|
|
217
|
+
// empty. Every stop/start therefore restored the DEFAULT of 1, silently turning a
|
|
218
|
+
// `--replicas 2` workspace into a one-replica one, and the annotation written to prevent
|
|
219
|
+
// exactly that was never once read back. No escaping at all is a rule that cannot be got
|
|
220
|
+
// subtly wrong.
|
|
221
|
+
const res = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'get', 'namespace', namespace, '-o', 'json'], { own: (0, names_1.isOurs)(context) });
|
|
222
|
+
let before = {};
|
|
223
|
+
try {
|
|
224
|
+
const doc = JSON.parse(res.stdout || '{}');
|
|
225
|
+
const parsed = JSON.parse(doc.metadata?.annotations?.[exports.SCALE_ANNOTATION] ?? '{}');
|
|
226
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
227
|
+
before = parsed;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
before = {};
|
|
232
|
+
}
|
|
233
|
+
const targets = await scalables(namespace, context);
|
|
234
|
+
if (targets.length === 0) {
|
|
235
|
+
throw new errors_1.NotFoundError(`'${name}' has no workloads to start -- it was \`down\`ed. Recreate it with ` +
|
|
236
|
+
`\`houston up --version ${version} --name ${name}\``);
|
|
237
|
+
}
|
|
238
|
+
const mongo = targets.filter((target) => target.split('/').pop() === names_1.MONGO_SERVICE);
|
|
239
|
+
const rest = targets.filter((target) => !mongo.includes(target));
|
|
240
|
+
for (const target of [...mongo, ...rest]) {
|
|
241
|
+
const count = String(before[target] ?? '1');
|
|
242
|
+
const scaled = await exec_1.kube.run(['kubectl', '--context', context, '-n', namespace, 'scale', `--replicas=${count}`, target], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
243
|
+
if (scaled.returncode !== 0)
|
|
244
|
+
throw new errors_1.DockerError(`could not scale ${target}: ${(0, ask_1.why)(scaled)}`);
|
|
245
|
+
if (mongo.includes(target) && (await mongoPodsTheOperatorKeeps(name, { context })).size === 0) {
|
|
246
|
+
await (0, replicaset_1.initReplicaSet)({ namespace, context, emit });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
(0, events_1.info)(emit, `scaled ${String(targets.length)} workload(s) back up`, { phase: 'done' });
|
|
250
|
+
return targets.length;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Scale ONLY Rocket.Chat, leaving MongoDB up.
|
|
254
|
+
*
|
|
255
|
+
* What `stopWorkspace` does is wrong for a backup: a dump needs the database running and
|
|
256
|
+
* only its writers quiesced. This is the Kubernetes counterpart of `stopServices`.
|
|
257
|
+
*/
|
|
258
|
+
async function scaleRocketchat(name, { replicas, context, sleep = realSleep, selector = names_1.APPLICATION_SELECTOR, }) {
|
|
259
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
260
|
+
const listed = await exec_1.kube.run([
|
|
261
|
+
'kubectl',
|
|
262
|
+
'--context',
|
|
263
|
+
context,
|
|
264
|
+
'-n',
|
|
265
|
+
namespace,
|
|
266
|
+
'get',
|
|
267
|
+
'deployment',
|
|
268
|
+
'-l',
|
|
269
|
+
selector,
|
|
270
|
+
'-o',
|
|
271
|
+
'name',
|
|
272
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
273
|
+
if (listed.returncode !== 0) {
|
|
274
|
+
throw new errors_1.DockerError(`could not list Rocket.Chat deployments for '${name}': ${(0, ask_1.why)(listed)}`);
|
|
275
|
+
}
|
|
276
|
+
const targets = listed.stdout
|
|
277
|
+
.split('\n')
|
|
278
|
+
.map((line) => line.trim())
|
|
279
|
+
.filter((line) => line !== '');
|
|
280
|
+
if (targets.length === 0)
|
|
281
|
+
throw new errors_1.NotFoundError(`'${name}' has no Rocket.Chat deployments`);
|
|
282
|
+
const res = await exec_1.kube.run([
|
|
283
|
+
'kubectl',
|
|
284
|
+
'--context',
|
|
285
|
+
context,
|
|
286
|
+
'-n',
|
|
287
|
+
namespace,
|
|
288
|
+
'scale',
|
|
289
|
+
`--replicas=${String(replicas)}`,
|
|
290
|
+
...targets,
|
|
291
|
+
], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
292
|
+
if (res.returncode !== 0 || replicas !== 0)
|
|
293
|
+
return res.returncode;
|
|
294
|
+
await waitForRocketchatPodsGone(namespace, context, name, sleep, selector);
|
|
295
|
+
return 0;
|
|
296
|
+
}
|
|
297
|
+
/** Desired counts before quiescence, including already stopped deployments. */
|
|
298
|
+
async function rocketchatReplicas(name, { context }) {
|
|
299
|
+
const res = await exec_1.kube.run([
|
|
300
|
+
'kubectl',
|
|
301
|
+
'--context',
|
|
302
|
+
context,
|
|
303
|
+
'-n',
|
|
304
|
+
await (0, namespace_1.namespaceFor)(name),
|
|
305
|
+
'get',
|
|
306
|
+
'deployment',
|
|
307
|
+
'-l',
|
|
308
|
+
names_1.APPLICATION_SELECTOR,
|
|
309
|
+
'-o',
|
|
310
|
+
'json',
|
|
311
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
312
|
+
if (res.returncode !== 0) {
|
|
313
|
+
throw new errors_1.DockerError(`could not read Rocket.Chat replicas for '${name}': ${(0, ask_1.why)(res)}`);
|
|
314
|
+
}
|
|
315
|
+
let doc;
|
|
316
|
+
try {
|
|
317
|
+
doc = JSON.parse(res.stdout);
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
throw new errors_1.DockerError(`could not read Rocket.Chat replicas for '${name}': invalid deployment list`);
|
|
321
|
+
}
|
|
322
|
+
const rows = typeof doc === 'object' && doc !== null && !Array.isArray(doc)
|
|
323
|
+
? doc.items
|
|
324
|
+
: undefined;
|
|
325
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
326
|
+
throw new errors_1.DockerError(`could not read Rocket.Chat replicas for '${name}': no deployment list`);
|
|
327
|
+
}
|
|
328
|
+
const counts = {};
|
|
329
|
+
for (const row of rows) {
|
|
330
|
+
const item = typeof row === 'object' && row !== null ? row : {};
|
|
331
|
+
const metadata = item.metadata;
|
|
332
|
+
const spec = item.spec;
|
|
333
|
+
const deployment = metadata?.name;
|
|
334
|
+
const count = spec?.replicas;
|
|
335
|
+
if (typeof deployment !== 'string' ||
|
|
336
|
+
!/^[a-z0-9][a-z0-9.-]*$/u.test(deployment) ||
|
|
337
|
+
typeof count !== 'number' ||
|
|
338
|
+
!Number.isInteger(count) ||
|
|
339
|
+
count < 0) {
|
|
340
|
+
throw new errors_1.DockerError(`could not read Rocket.Chat replicas for '${name}': invalid deployment count`);
|
|
341
|
+
}
|
|
342
|
+
const target = `deployment.apps/${deployment}`;
|
|
343
|
+
if (Object.hasOwn(counts, target)) {
|
|
344
|
+
throw new errors_1.DockerError(`could not read Rocket.Chat replicas for '${name}': duplicate deployment`);
|
|
345
|
+
}
|
|
346
|
+
counts[target] = count;
|
|
347
|
+
}
|
|
348
|
+
return counts;
|
|
349
|
+
}
|
|
350
|
+
/** Restore the same deployment set; an uncertain or changed set is not safe to guess. */
|
|
351
|
+
async function restoreRocketchatReplicas(name, counts, { context }) {
|
|
352
|
+
const current = await rocketchatReplicas(name, { context });
|
|
353
|
+
if (Object.keys(current).sort().join('\n') !== Object.keys(counts).sort().join('\n') ||
|
|
354
|
+
Object.values(counts).some((count) => !Number.isInteger(count) || count < 0)) {
|
|
355
|
+
throw new errors_1.DockerError(`cannot restore Rocket.Chat replicas for '${name}': deployment shape changed`);
|
|
356
|
+
}
|
|
357
|
+
const namespace = await (0, namespace_1.namespaceFor)(name);
|
|
358
|
+
for (const [target, count] of Object.entries(counts)) {
|
|
359
|
+
const res = await exec_1.kube.run([
|
|
360
|
+
'kubectl',
|
|
361
|
+
'--context',
|
|
362
|
+
context,
|
|
363
|
+
'-n',
|
|
364
|
+
namespace,
|
|
365
|
+
'scale',
|
|
366
|
+
`--replicas=${String(count)}`,
|
|
367
|
+
target,
|
|
368
|
+
], { timeout: names_1.APPLY_TIMEOUT, own: (0, names_1.isOurs)(context) });
|
|
369
|
+
if (res.returncode !== 0)
|
|
370
|
+
return res.returncode;
|
|
371
|
+
}
|
|
372
|
+
return 0;
|
|
373
|
+
}
|
|
374
|
+
async function waitForRocketchatPodsGone(namespace, context, name, sleep, selector) {
|
|
375
|
+
for (let attempt = 0; attempt < exports.POD_GONE_TRIES; attempt += 1) {
|
|
376
|
+
const res = await exec_1.kube.run([
|
|
377
|
+
'kubectl',
|
|
378
|
+
'--context',
|
|
379
|
+
context,
|
|
380
|
+
'-n',
|
|
381
|
+
namespace,
|
|
382
|
+
'get',
|
|
383
|
+
'pods',
|
|
384
|
+
'-l',
|
|
385
|
+
selector,
|
|
386
|
+
'-o',
|
|
387
|
+
'name',
|
|
388
|
+
], { own: (0, names_1.isOurs)(context) });
|
|
389
|
+
if (res.returncode !== 0) {
|
|
390
|
+
throw new errors_1.DockerError(`could not verify Rocket.Chat termination for '${name}': ${(0, ask_1.why)(res)}`);
|
|
391
|
+
}
|
|
392
|
+
if (res.stdout.trim() === '')
|
|
393
|
+
return;
|
|
394
|
+
if (attempt + 1 < exports.POD_GONE_TRIES)
|
|
395
|
+
await sleep(exports.POD_GONE_INTERVAL);
|
|
396
|
+
}
|
|
397
|
+
throw new errors_1.DockerError(`Rocket.Chat pods did not terminate for '${name}'; refusing to access the database`);
|
|
398
|
+
}
|