@di-framework/cli-plugin-platform 6.1.2 → 6.3.0
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/README.md +154 -12
- package/dist/args.d.ts +8 -0
- package/dist/args.js +73 -28
- package/dist/assets/http-adapter.js +4 -1
- package/dist/assets/platform/README.md +68 -19
- package/dist/assets/platform/index.ts.tmpl +1 -1
- package/dist/assets/platform/tsconfig.json +2 -2
- package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/build.d.ts +27 -4
- package/dist/build.js +159 -18
- package/dist/bundle.d.ts +85 -0
- package/dist/bundle.js +608 -0
- package/dist/command.js +85 -3
- package/dist/console/catalog.js +2 -1
- package/dist/console/cluster.d.ts +4 -2
- package/dist/console/cluster.js +38 -40
- package/dist/control/auth.js +14 -2
- package/dist/controller/client.d.ts +47 -0
- package/dist/controller/client.js +157 -0
- package/dist/controller/commands.d.ts +48 -0
- package/dist/controller/commands.js +584 -0
- package/dist/controller/credentials.d.ts +63 -0
- package/dist/controller/credentials.js +156 -0
- package/dist/controller/index.d.ts +6 -0
- package/dist/controller/index.js +6 -0
- package/dist/controller/oidc.d.ts +54 -0
- package/dist/controller/oidc.js +121 -0
- package/dist/controller/registry.d.ts +15 -0
- package/dist/controller/registry.js +47 -0
- package/dist/controller/schema.d.ts +157 -0
- package/dist/controller/schema.js +1 -0
- package/dist/controller/sse.d.ts +12 -0
- package/dist/controller/sse.js +61 -0
- package/dist/controller/trust.d.ts +14 -0
- package/dist/controller/trust.js +39 -0
- package/dist/deploy.d.ts +14 -7
- package/dist/deploy.js +96 -5
- package/dist/deps.d.ts +4 -0
- package/dist/destroy.js +26 -2
- package/dist/environment-names.d.ts +6 -0
- package/dist/environment-names.js +10 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/manifest.d.ts +45 -1
- package/dist/manifest.js +197 -4
- package/dist/pglite-encryption.d.ts +79 -0
- package/dist/pglite-encryption.js +196 -0
- package/dist/pglite.d.ts +61 -4
- package/dist/pglite.js +124 -40
- package/dist/project.d.ts +7 -0
- package/dist/project.js +35 -0
- package/dist/publish.d.ts +7 -1
- package/dist/publish.js +33 -1
- package/dist/service.d.ts +34 -0
- package/dist/service.js +156 -145
- package/dist/target.d.ts +7 -1
- package/dist/target.js +19 -0
- package/dist/workload.d.ts +50 -12
- package/dist/workload.js +239 -44
- package/package.json +1 -1
package/dist/workload.js
CHANGED
|
@@ -12,13 +12,17 @@ import { hostInterfacesFromRequirements, renderHostInterfacesYaml } from './host
|
|
|
12
12
|
import { captureKubectl, runKubectl } from './kubernetes.js';
|
|
13
13
|
import { applyManagedBindings, cleanupManagedBindings } from './managed-bindings.js';
|
|
14
14
|
import { EXCLUSIVE_INSTANCE_KEY, isWithin, PGLITE_DATA_DIR_ENV, warnIfHostIgnoresExclusive, } from './pglite.js';
|
|
15
|
-
import { asWitIdentifier } from './project.js';
|
|
15
|
+
import { asWitIdentifier, CONFIG_FILE_NAME } from './project.js';
|
|
16
16
|
import { discoverQueueHandlers, isQueueWorkerProject } from './queues.js';
|
|
17
17
|
import { kubectlStatusReason, SECRET_UPDATE_KEYS_MESSAGE } from './secret-admission.js';
|
|
18
18
|
import { defaultProjectRequirements, guestLoggingRequirement, queueProjectRequirements, } from './wit.js';
|
|
19
19
|
export const MANAGED_BY_LABEL = 'di-framework';
|
|
20
20
|
export const WAIT_ATTEMPTS = 30;
|
|
21
|
+
export const STORAGE_WAIT_ATTEMPTS = 90;
|
|
21
22
|
export const WAIT_INTERVAL_MS = 2_000;
|
|
23
|
+
export const DEFAULT_DEPLOY_TIMEOUT_SECONDS = 60;
|
|
24
|
+
export const STORAGE_DEPLOY_TIMEOUT_SECONDS = 180;
|
|
25
|
+
export const DEPLOY_TIMEOUT_ENV = 'DI_FRAMEWORK_DEPLOY_TIMEOUT_SECONDS';
|
|
22
26
|
export const WORKLOAD_DEPLOYMENT_RESOURCE = 'workloaddeployment.runtime.wasmcloud.dev';
|
|
23
27
|
export const WORKLOAD_REPLICA_SET_RESOURCE = 'workloadreplicaset.runtime.wasmcloud.dev';
|
|
24
28
|
/** Host directory where the storage hostgroup mounts the shared PVC. */
|
|
@@ -350,8 +354,14 @@ ${labels.replace(/^/gm, ' ')}
|
|
|
350
354
|
}
|
|
351
355
|
/** Appended to a deploy failure that happened after the control Secret was rewritten. */
|
|
352
356
|
export const CONTROL_TOKEN_ROTATED_NOTICE = 'the control token was rotated; re-run deploy to roll the workload onto it';
|
|
353
|
-
/** The
|
|
354
|
-
export
|
|
357
|
+
/** The keys the CLI owns in every control Secret. */
|
|
358
|
+
export const CONTROL_SECRET_CLI_KEYS = ['DI_CONTROL_TOKEN', 'DI_CONTROL_IDENTITY'];
|
|
359
|
+
/**
|
|
360
|
+
* The control Secret document. The CLI's keys hold `token` and the workload name; `appData`
|
|
361
|
+
* (already base64, as in a Secret's `data`) carries app-owned keys over, and `resourceVersion`
|
|
362
|
+
* makes the update conditional.
|
|
363
|
+
*/
|
|
364
|
+
export function controlSecretDocument(workloadName, namespace, token, appData = {}, resourceVersion) {
|
|
355
365
|
const encode = (value) => Buffer.from(value, 'utf8').toString('base64');
|
|
356
366
|
return {
|
|
357
367
|
apiVersion: 'v1',
|
|
@@ -363,9 +373,11 @@ export function controlSecretDocument(workloadName, namespace, token) {
|
|
|
363
373
|
'app.kubernetes.io/managed-by': MANAGED_BY_LABEL,
|
|
364
374
|
'app.kubernetes.io/name': workloadName,
|
|
365
375
|
},
|
|
376
|
+
...(resourceVersion === undefined ? {} : { resourceVersion }),
|
|
366
377
|
},
|
|
367
378
|
type: 'Opaque',
|
|
368
379
|
data: {
|
|
380
|
+
...appData,
|
|
369
381
|
DI_CONTROL_TOKEN: encode(token),
|
|
370
382
|
DI_CONTROL_IDENTITY: encode(workloadName),
|
|
371
383
|
},
|
|
@@ -376,56 +388,207 @@ function secretsPath(namespace, name) {
|
|
|
376
388
|
return name === undefined ? collection : `${collection}/${encodeURIComponent(name)}`;
|
|
377
389
|
}
|
|
378
390
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
391
|
+
* Writes the workload's control Secret on deploy and returns whether the token rotated.
|
|
392
|
+
*
|
|
393
|
+
* The Secret holds the CLI's `DI_CONTROL_TOKEN` and `DI_CONTROL_IDENTITY` plus the app-owned keys
|
|
394
|
+
* the project declares in `controlSecretKeys` (cli-extensions#69). Any other key is refused: the
|
|
395
|
+
* Secret is injected whole into the workload's environment, so an undeclared key is either a
|
|
396
|
+
* mistake or a value nobody vouched for.
|
|
397
|
+
*
|
|
398
|
+
* - A new Secret is created with the CLI's keys and a fresh token.
|
|
399
|
+
* - An existing Secret the caller may read (an admin) is read, checked for undeclared keys, and
|
|
400
|
+
* updated with a fresh token and its declared keys carried over, conditional on the
|
|
401
|
+
* `resourceVersion` that was read.
|
|
402
|
+
* - Tenant developers may create, update and delete Secrets but never get, list, watch or patch
|
|
403
|
+
* them (platform#112), and the platform's `tenant-secret-update` admission policy refuses an
|
|
404
|
+
* update that drops a key. So an existing Secret is replaced blind with the CLI's keys and a
|
|
405
|
+
* fresh token. When that is refused because the Secret holds more keys, a dry-run update that
|
|
406
|
+
* also names every declared key asks the same policy whether all of the extra keys are
|
|
407
|
+
* declared. If they are, the Secret is kept as it is, token included, since a blind writer
|
|
408
|
+
* cannot carry over values it cannot read; otherwise deploy stops.
|
|
409
|
+
*
|
|
410
|
+
* Every request goes through `--raw`: `kubectl replace -f` would GET the object first.
|
|
386
411
|
*/
|
|
387
412
|
export async function writeControlSecret(project, connection, deps) {
|
|
388
413
|
const workloadName = deploymentResourceName(project);
|
|
389
414
|
const name = controlSecretResourceName(workloadName);
|
|
415
|
+
const declared = project.controlSecretKeys ?? [];
|
|
390
416
|
const token = randomBytes(32).toString('base64url');
|
|
417
|
+
const rotated = { name, revision: createHash('sha256').update(token).digest('hex').slice(0, 16) };
|
|
418
|
+
/** Values that must never appear in an error: the token and any value read from the cluster. */
|
|
419
|
+
const secrets = [token];
|
|
391
420
|
const directory = mkdtempSync(join(tmpdir(), 'di-control-secret-'));
|
|
421
|
+
let written = 0;
|
|
422
|
+
const send = async (verb, document, query = '') => {
|
|
423
|
+
const path = join(directory, `secret-${written++}.json`);
|
|
424
|
+
writeFileSync(path, JSON.stringify(document), { mode: 0o600 });
|
|
425
|
+
const target = verb === 'create'
|
|
426
|
+
? secretsPath(connection.namespace)
|
|
427
|
+
: secretsPath(connection.namespace, name);
|
|
428
|
+
return captureKubectl(deps, connection, [verb, '--raw', `${target}${query}`, '-f', path], project.projectRoot);
|
|
429
|
+
};
|
|
430
|
+
const failed = (command, result) => controlSecretWriteFailed(command, name, connection, result, secrets);
|
|
392
431
|
try {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
432
|
+
const document = controlSecretDocument(workloadName, connection.namespace, token);
|
|
433
|
+
const created = await send('create', document);
|
|
434
|
+
if (created.exitCode === 0)
|
|
435
|
+
return rotated;
|
|
436
|
+
if (kubectlStatusReason(created.stderr) !== 'AlreadyExists') {
|
|
437
|
+
throw failed('kubectl create', created);
|
|
438
|
+
}
|
|
439
|
+
const stored = await readControlSecret(project, connection, deps, name, secrets);
|
|
440
|
+
if (stored !== undefined) {
|
|
441
|
+
const undeclared = Object.keys(stored.data).filter((key) => !CONTROL_SECRET_CLI_KEYS.includes(key) && !declared.includes(key));
|
|
442
|
+
if (undeclared.length > 0)
|
|
443
|
+
throw controlSecretForeignKeys(name, connection, undeclared);
|
|
444
|
+
const appData = Object.fromEntries(Object.entries(stored.data).filter(([key]) => declared.includes(key)));
|
|
445
|
+
const merged = controlSecretDocument(workloadName, connection.namespace, token, appData, stored.resourceVersion);
|
|
446
|
+
const updated = await send('replace', merged);
|
|
447
|
+
if (updated.exitCode !== 0)
|
|
448
|
+
throw failed('kubectl replace', updated);
|
|
449
|
+
return rotated;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Asks the `tenant-secret-update` policy, with a dry run that stores nothing, whether an
|
|
453
|
+
* update holding only `keys` would drop a key of the stored Secret. Values are placeholders:
|
|
454
|
+
* the policy compares key names only. True when the policy refuses it.
|
|
455
|
+
*/
|
|
456
|
+
const dropsAKey = async (keys) => {
|
|
457
|
+
const probe = controlSecretDocument(workloadName, connection.namespace, token);
|
|
458
|
+
const data = {};
|
|
459
|
+
for (const key of keys)
|
|
460
|
+
data[key] = '';
|
|
461
|
+
probe.data = data;
|
|
462
|
+
const checked = await send('replace', probe, '?dryRun=All');
|
|
463
|
+
if (checked.exitCode === 0)
|
|
464
|
+
return false;
|
|
465
|
+
if (checked.stderr.includes(SECRET_UPDATE_KEYS_MESSAGE))
|
|
466
|
+
return true;
|
|
467
|
+
throw failed('kubectl replace --dry-run', checked);
|
|
468
|
+
};
|
|
469
|
+
// With app keys declared, a blind update must never be the one to find out that the policy
|
|
470
|
+
// does not protect them (a caller that is not `di-user-*`, a namespace outside the policy, an
|
|
471
|
+
// older platform): it would succeed and drop them. The policy must first refuse a dry run
|
|
472
|
+
// that keeps only DI_CONTROL_IDENTITY, which it does exactly when it applies and the Secret
|
|
473
|
+
// holds another key.
|
|
474
|
+
if (declared.length > 0 && !(await dropsAKey(['DI_CONTROL_IDENTITY']))) {
|
|
475
|
+
throw controlSecretUnguarded(name, connection);
|
|
476
|
+
}
|
|
477
|
+
const replaced = await send('replace', document);
|
|
478
|
+
if (replaced.exitCode === 0)
|
|
479
|
+
return rotated;
|
|
480
|
+
if (!replaced.stderr.includes(SECRET_UPDATE_KEYS_MESSAGE)) {
|
|
481
|
+
throw failed('kubectl replace', replaced);
|
|
482
|
+
}
|
|
483
|
+
if (declared.length === 0)
|
|
484
|
+
throw controlSecretForeignKeys(name, connection);
|
|
485
|
+
if (await dropsAKey([...CONTROL_SECRET_CLI_KEYS, ...declared])) {
|
|
486
|
+
throw controlSecretForeignKeys(name, connection);
|
|
487
|
+
}
|
|
488
|
+
// Kept as it is, so the CLI's keys must be there: a workload without its token would have
|
|
489
|
+
// no control credentials. Leaving one out must drop a key, which proves it is stored.
|
|
490
|
+
for (const key of CONTROL_SECRET_CLI_KEYS) {
|
|
491
|
+
const others = CONTROL_SECRET_CLI_KEYS.filter((other) => other !== key);
|
|
492
|
+
if (!(await dropsAKey([...others, ...declared]))) {
|
|
493
|
+
throw controlSecretIncomplete(name, connection, key);
|
|
403
494
|
}
|
|
404
495
|
}
|
|
496
|
+
return { name };
|
|
405
497
|
}
|
|
406
498
|
finally {
|
|
407
499
|
rmSync(directory, { recursive: true, force: true });
|
|
408
500
|
}
|
|
409
|
-
return { name, revision: createHash('sha256').update(token).digest('hex').slice(0, 16) };
|
|
410
501
|
}
|
|
411
502
|
/**
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
503
|
+
* The stored control Secret's keys (base64 values) and `resourceVersion` when the caller may read
|
|
504
|
+
* it, or undefined when it may not. `kubectl auth can-i` asks first, so a tenant developer never
|
|
505
|
+
* sends a Secret read the platform forbids. Values read here are added to `secrets` so no error
|
|
506
|
+
* can show them; nothing read is ever printed.
|
|
507
|
+
*/
|
|
508
|
+
async function readControlSecret(project, connection, deps, name, secrets) {
|
|
509
|
+
const allowed = await captureKubectl(deps, connection, ['auth', 'can-i', 'get', `secrets/${name}`], project.projectRoot);
|
|
510
|
+
if (allowed.exitCode !== 0 || allowed.stdout.trim() !== 'yes')
|
|
511
|
+
return undefined;
|
|
512
|
+
const read = await captureKubectl(deps, connection, ['get', '--raw', secretsPath(connection.namespace, name)], project.projectRoot);
|
|
513
|
+
if (read.exitCode !== 0) {
|
|
514
|
+
throw controlSecretWriteFailed('kubectl get', name, connection, read, secrets);
|
|
515
|
+
}
|
|
516
|
+
let stored;
|
|
517
|
+
try {
|
|
518
|
+
stored = JSON.parse(read.stdout);
|
|
519
|
+
}
|
|
520
|
+
catch {
|
|
521
|
+
throw new CommandFailure('WASMCLOUD_TOOL_FAILED', `kubectl get returned a control Secret ${name} that is not JSON`, 3, { command: 'kubectl get', name });
|
|
522
|
+
}
|
|
523
|
+
const data = {};
|
|
524
|
+
if (stored.data !== null && typeof stored.data === 'object') {
|
|
525
|
+
for (const [key, value] of Object.entries(stored.data)) {
|
|
526
|
+
// The API only returns strings. Anything else cannot be carried over, so fail closed.
|
|
527
|
+
if (typeof value !== 'string') {
|
|
528
|
+
throw new CommandFailure('WASMCLOUD_TOOL_FAILED', `kubectl get returned a control Secret ${name} whose ${key} is not a string`, 3, { command: 'kubectl get', name, key });
|
|
529
|
+
}
|
|
530
|
+
data[key] = value;
|
|
531
|
+
secrets.push(value, Buffer.from(value, 'base64').toString('utf8'));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
const resourceVersion = stored.metadata?.resourceVersion;
|
|
535
|
+
return typeof resourceVersion === 'string' ? { data, resourceVersion } : { data };
|
|
536
|
+
}
|
|
537
|
+
/** The `tenant-secret-update` policy did not protect the Secret, so a blind update could drop keys. */
|
|
538
|
+
function controlSecretUnguarded(name, connection) {
|
|
539
|
+
return new CommandFailure('WASMCLOUD_CONTROL_SECRET_UNGUARDED', `Refusing to replace the control Secret ${name} blind: the platform accepted a dry-run ` +
|
|
540
|
+
'update that drops DI_CONTROL_TOKEN, so either its tenant-secret-update policy does not ' +
|
|
541
|
+
'apply to this caller or the Secret has no DI_CONTROL_TOKEN. A replace could then drop ' +
|
|
542
|
+
'the declared app keys, which this caller cannot read back. Deploy as a tenant developer ' +
|
|
543
|
+
'(di-user-*) or as a caller that may read Secrets, or have the app tooling write ' +
|
|
544
|
+
`DI_CONTROL_TOKEN and DI_CONTROL_IDENTITY into ${name} in ${connection.namespace}`, 2, { name, namespace: connection.namespace });
|
|
545
|
+
}
|
|
546
|
+
/** The Secret holds declared app keys but lacks one of the CLI's keys. */
|
|
547
|
+
function controlSecretIncomplete(name, connection, key) {
|
|
548
|
+
return new CommandFailure('WASMCLOUD_CONTROL_SECRET_INCOMPLETE', `The control Secret ${name} holds declared app keys but no ${key}, so the workload would ` +
|
|
549
|
+
'have no control credentials. The tooling that writes the app keys must also write ' +
|
|
550
|
+
'non-empty DI_CONTROL_TOKEN and DI_CONTROL_IDENTITY (the workload name); fix the Secret, ' +
|
|
551
|
+
`or delete it with \`kubectl delete secret ${name} --namespace ${connection.namespace}\` and redeploy`, 2, { name, namespace: connection.namespace, key });
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* The control Secret holds keys that are neither the CLI's nor declared in `controlSecretKeys`.
|
|
555
|
+
* `keys` names them when the Secret could be read; a tenant developer only learns that some exist.
|
|
415
556
|
*/
|
|
416
|
-
function
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
557
|
+
function controlSecretForeignKeys(name, connection, keys) {
|
|
558
|
+
const which = keys === undefined ? "keys this CLI didn't write" : `undeclared keys ${keys.join(', ')}`;
|
|
559
|
+
return new CommandFailure('WASMCLOUD_CONTROL_SECRET_FOREIGN_KEYS', `The control Secret ${name} has ${which}; declare app-owned keys in "controlSecretKeys" ` +
|
|
560
|
+
`of ${CONFIG_FILE_NAME}, or delete the Secret with ` +
|
|
561
|
+
`\`kubectl delete secret ${name} --namespace ${connection.namespace}\` and redeploy`, 2, { name, namespace: connection.namespace, ...(keys === undefined ? {} : { keys: [...keys] }) });
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* A failed control Secret request, with kubectl's reason. Kubernetes errors for these requests
|
|
565
|
+
* name the object, not its data, but the stderr is still scrubbed of `secrets` (the token raw and
|
|
566
|
+
* base64, and any value read from the cluster) and of credential-shaped text before it is shown,
|
|
567
|
+
* in case a response echoes the body.
|
|
568
|
+
*/
|
|
569
|
+
function controlSecretWriteFailed(command, name, connection, result, secrets) {
|
|
570
|
+
const scrub = [
|
|
571
|
+
...new Set(secrets.flatMap((secret) => [secret, Buffer.from(secret, 'utf8').toString('base64')])),
|
|
572
|
+
]
|
|
573
|
+
.filter((secret) => secret.length > 0)
|
|
574
|
+
.sort((a, b) => b.length - a.length);
|
|
575
|
+
const stderr = sanitizePublicText(scrub.reduce((text, secret) => redact(text, secret), result.stderr).trim());
|
|
576
|
+
if (kubectlStatusReason(result.stderr) === 'Conflict') {
|
|
577
|
+
return new CommandFailure('WASMCLOUD_CONTROL_SECRET_CHANGED', `The control Secret ${name} in ${connection.namespace} changed while deploy was updating it; re-run deploy`, 3, { name, namespace: connection.namespace, command, exitCode: result.exitCode, stderr });
|
|
425
578
|
}
|
|
426
579
|
const reason = stderr.length > 0 ? `: ${stderr}` : '';
|
|
427
580
|
return new CommandFailure('WASMCLOUD_TOOL_FAILED', `${command} failed with exit code ${result.exitCode}${reason}`, 3, { command, exitCode: result.exitCode, stderr });
|
|
428
581
|
}
|
|
582
|
+
/** Shorter values are only redacted as whole tokens, so `on` does not blank every `json`. */
|
|
583
|
+
const SHORT_SECRET = 4;
|
|
584
|
+
const TOKEN_CHARACTER = '[A-Za-z0-9+/=_.-]';
|
|
585
|
+
/** `text` with every occurrence of `secret` replaced by `[redacted]`. */
|
|
586
|
+
function redact(text, secret) {
|
|
587
|
+
if (secret.length >= SHORT_SECRET)
|
|
588
|
+
return text.split(secret).join('[redacted]');
|
|
589
|
+
const escaped = secret.replace(/[.*+?^${}()|[\]\\/-]/g, '\\$&');
|
|
590
|
+
return text.replace(new RegExp(`(?<!${TOKEN_CHARACTER})${escaped}(?!${TOKEN_CHARACTER})`, 'g'), '[redacted]');
|
|
591
|
+
}
|
|
429
592
|
/**
|
|
430
593
|
* Deletes the control Secret by name. A label-selected delete would LIST Secrets and the
|
|
431
594
|
* default `--wait=true` would GET it afterwards, both forbidden to tenant developers.
|
|
@@ -454,11 +617,8 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
454
617
|
cronJobs.length > 0 ||
|
|
455
618
|
queueHandlers.length > 0 ||
|
|
456
619
|
hasPersistentStorage;
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
: isWorker
|
|
460
|
-
? queueProjectRequirements()
|
|
461
|
-
: [];
|
|
620
|
+
const workerRequirements = isWorker ? queueProjectRequirements() : [];
|
|
621
|
+
const baseRequirements = needsHttp ? defaultProjectRequirements() : workerRequirements;
|
|
462
622
|
const requirements = [
|
|
463
623
|
...baseRequirements,
|
|
464
624
|
...requirementsFromBindings(bindings),
|
|
@@ -483,6 +643,9 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
483
643
|
hasPersistentStorage,
|
|
484
644
|
});
|
|
485
645
|
const controlSecret = needsHttp ? await writeControlSecret(project, connection, deps) : undefined;
|
|
646
|
+
if (controlSecret !== undefined && controlSecret.revision === undefined) {
|
|
647
|
+
io.stdout.write(`Kept control Secret ${controlSecret.name}: it holds declared app keys this deploy cannot read, so the control token was not rotated\n`);
|
|
648
|
+
}
|
|
486
649
|
// From here on the cron invokers already use the new token, which the running workload
|
|
487
650
|
// rejects until it rolls out with this manifest.
|
|
488
651
|
let path;
|
|
@@ -502,7 +665,7 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
502
665
|
await waitForReady(project, connection, deps, io);
|
|
503
666
|
}
|
|
504
667
|
catch (error) {
|
|
505
|
-
throw controlSecret === undefined ? error : withRotatedTokenNotice(error);
|
|
668
|
+
throw controlSecret?.revision === undefined ? error : withRotatedTokenNotice(error);
|
|
506
669
|
}
|
|
507
670
|
await cleanupManagedBindings(project, connection, associations, deps);
|
|
508
671
|
if (egress === undefined)
|
|
@@ -517,8 +680,12 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
517
680
|
* so every cron invocation is refused until a deploy succeeds. Say so in the failure.
|
|
518
681
|
*/
|
|
519
682
|
function withRotatedTokenNotice(error) {
|
|
520
|
-
if (!isCommandFailure(error))
|
|
683
|
+
if (!isCommandFailure(error)) {
|
|
684
|
+
if (error instanceof Error) {
|
|
685
|
+
error.message = `${error.message}; ${CONTROL_TOKEN_ROTATED_NOTICE}`;
|
|
686
|
+
}
|
|
521
687
|
return error;
|
|
688
|
+
}
|
|
522
689
|
// Every failure on this path (kubectl, readiness) carries an object of details.
|
|
523
690
|
const details = error.details;
|
|
524
691
|
return new CommandFailure(error.code, `${error.message}; ${CONTROL_TOKEN_ROTATED_NOTICE}`, error.exitCode, { ...details, controlTokenRotated: true });
|
|
@@ -569,22 +736,50 @@ export async function deleteWorkload(project, connection, io, deps) {
|
|
|
569
736
|
await cleanupManagedBindings(project, connection, new Set(), deps);
|
|
570
737
|
await removeWorkloadEgress(project, connection, deps);
|
|
571
738
|
}
|
|
572
|
-
export
|
|
739
|
+
export function projectHasStorageOrPglite(project) {
|
|
740
|
+
return (project.pglite !== undefined ||
|
|
741
|
+
project.persistentStorage === true ||
|
|
742
|
+
project.storage !== undefined ||
|
|
743
|
+
project.actors === true ||
|
|
744
|
+
discoverActors(project).length > 0 ||
|
|
745
|
+
discoverQueueHandlers(project).length > 0);
|
|
746
|
+
}
|
|
747
|
+
export function resolveDeployTimeoutSeconds(project, deps, options) {
|
|
748
|
+
if (options?.timeoutSeconds !== undefined &&
|
|
749
|
+
Number.isFinite(options.timeoutSeconds) &&
|
|
750
|
+
options.timeoutSeconds > 0) {
|
|
751
|
+
return Math.ceil(options.timeoutSeconds);
|
|
752
|
+
}
|
|
753
|
+
const raw = deps.env?.[DEPLOY_TIMEOUT_ENV];
|
|
754
|
+
if (raw !== undefined && /^[1-9]\d*$/.test(raw.trim())) {
|
|
755
|
+
return Number(raw.trim());
|
|
756
|
+
}
|
|
757
|
+
return projectHasStorageOrPglite(project)
|
|
758
|
+
? STORAGE_DEPLOY_TIMEOUT_SECONDS
|
|
759
|
+
: DEFAULT_DEPLOY_TIMEOUT_SECONDS;
|
|
760
|
+
}
|
|
761
|
+
export async function waitForReady(project, connection, deps, io, options) {
|
|
573
762
|
const name = deploymentResourceName(project);
|
|
574
|
-
|
|
763
|
+
const timeoutSeconds = resolveDeployTimeoutSeconds(project, deps, options);
|
|
764
|
+
const attempts = Math.max(1, Math.ceil((timeoutSeconds * 1_000) / WAIT_INTERVAL_MS));
|
|
765
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
575
766
|
const result = await captureKubectl(deps, connection, ['get', WORKLOAD_DEPLOYMENT_RESOURCE, name, '-o', 'json'], project.projectRoot);
|
|
576
767
|
if (result.exitCode === 0 && isReady(result.stdout))
|
|
577
768
|
return;
|
|
578
769
|
await deps.wait(WAIT_INTERVAL_MS);
|
|
579
770
|
}
|
|
580
771
|
const diagnostics = await deploymentDiagnostics(project, connection, deps);
|
|
772
|
+
const recovery = `The workload may still become Ready while the host finishes rolling; check status with ` +
|
|
773
|
+
`"kubectl get workloaddeployment ${name} -n ${connection.namespace}" or re-run ` +
|
|
774
|
+
`"di-framework platform deploy ${project.applicationName} --target ${connection.target}".`;
|
|
581
775
|
if (io !== undefined) {
|
|
582
|
-
io.stderr.write(`WorkloadDeployment ${name} did not become ready. Kubernetes diagnostics follow:\n${diagnostics}\n`);
|
|
776
|
+
io.stderr.write(`WorkloadDeployment ${name} did not become ready. ${recovery} Kubernetes diagnostics follow:\n${diagnostics}\n`);
|
|
583
777
|
}
|
|
584
|
-
throw new CommandFailure('WASMCLOUD_DEPLOYMENT_NOT_READY', `WorkloadDeployment ${name} in ${connection.namespace} did not become ready`, 3, {
|
|
778
|
+
throw new CommandFailure('WASMCLOUD_DEPLOYMENT_NOT_READY', `WorkloadDeployment ${name} in ${connection.namespace} did not become ready. ${recovery}`, 3, {
|
|
585
779
|
application: project.applicationName,
|
|
586
780
|
namespace: connection.namespace,
|
|
587
781
|
name,
|
|
782
|
+
timeoutSeconds,
|
|
588
783
|
diagnostics,
|
|
589
784
|
});
|
|
590
785
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@di-framework/cli-plugin-platform",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "di-framework CLI extension that builds, serves, and deploys DI Framework apps as platform WebAssembly components.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|