@di-framework/cli-plugin-platform 6.2.0 → 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 +10 -0
- package/dist/args.d.ts +8 -0
- package/dist/args.js +73 -28
- 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.js +17 -4
- package/dist/bundle.d.ts +85 -0
- package/dist/bundle.js +608 -0
- package/dist/command.js +85 -3
- package/dist/console/cluster.d.ts +4 -2
- package/dist/console/cluster.js +38 -40
- 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 +8 -1
- package/dist/deploy.js +89 -2
- package/dist/deps.d.ts +4 -0
- package/dist/destroy.js +26 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/manifest.d.ts +45 -1
- package/dist/manifest.js +197 -4
- package/dist/pglite.d.ts +12 -2
- package/dist/pglite.js +19 -11
- 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 +17 -1
- package/dist/workload.js +44 -11
- package/package.json +1 -1
package/dist/service.js
CHANGED
|
@@ -2,12 +2,14 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { CommandFailure } from '@di-framework/cli-extension';
|
|
5
|
+
import { readEnvFlag, readStringFlag } from './args.js';
|
|
6
|
+
import { resolveControllerSession, wrapControllerError } from './controller/index.js';
|
|
5
7
|
import { DEFAULT_DEPS } from './deps.js';
|
|
6
8
|
import { captureKubectl } from './kubernetes.js';
|
|
7
|
-
import { loadDeployManifest } from './manifest.js';
|
|
9
|
+
import { loadDeployManifest, tenantNamespace, } from './manifest.js';
|
|
8
10
|
import { isNamespace } from './namespace.js';
|
|
9
11
|
import { invalidUsage, matchOption } from './support.js';
|
|
10
|
-
import { resolveConnection, resolveTarget } from './target.js';
|
|
12
|
+
import { isControllerBackedTarget, resolveConnection, resolveTarget, } from './target.js';
|
|
11
13
|
export const BACKING_SERVICE_API_VERSION = 'platform.di-framework.dev/v1alpha1';
|
|
12
14
|
export const BACKING_SERVICE_KIND = 'BackingService';
|
|
13
15
|
export const BACKING_SERVICE_RESOURCE = 'backingservices.platform.di-framework.dev';
|
|
@@ -81,59 +83,50 @@ export function buildBackingServiceManifest(options) {
|
|
|
81
83
|
spec,
|
|
82
84
|
};
|
|
83
85
|
}
|
|
86
|
+
const SERVICE_CREATE_STRING_FLAGS = {
|
|
87
|
+
'--name': 'name',
|
|
88
|
+
'--class': 'className',
|
|
89
|
+
'--target': 'target',
|
|
90
|
+
'--namespace': 'namespace',
|
|
91
|
+
'--context': 'context',
|
|
92
|
+
};
|
|
93
|
+
const SERVICE_SIZING_FLAGS = {
|
|
94
|
+
'--memory': 'memory',
|
|
95
|
+
'--storage': 'storage',
|
|
96
|
+
'--cpu': 'cpu',
|
|
97
|
+
};
|
|
98
|
+
const SERVICE_LIST_STRING_FLAGS = {
|
|
99
|
+
'--target': 'target',
|
|
100
|
+
'--namespace': 'namespace',
|
|
101
|
+
'--context': 'context',
|
|
102
|
+
};
|
|
84
103
|
export function parseServiceCreateArgs(args) {
|
|
85
104
|
let type;
|
|
86
|
-
|
|
87
|
-
let className;
|
|
105
|
+
const values = {};
|
|
88
106
|
let deletionPolicy;
|
|
89
|
-
let
|
|
90
|
-
let namespace;
|
|
91
|
-
let context;
|
|
107
|
+
let env;
|
|
92
108
|
let wait = false;
|
|
93
109
|
let timeoutMs = DEFAULT_WAIT_TIMEOUT_MS;
|
|
94
110
|
let timeoutExplicit = false;
|
|
95
111
|
const parameters = {};
|
|
96
112
|
const destinations = [];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
name = nameOpt.value;
|
|
104
|
-
position = nameOpt.consumedThrough;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const classOpt = matchOption(args, position, token, '--class');
|
|
108
|
-
if (classOpt) {
|
|
109
|
-
if (className !== undefined)
|
|
110
|
-
invalidUsage('Option may be provided only once: --class', '--class');
|
|
111
|
-
className = classOpt.value;
|
|
112
|
-
position = classOpt.consumedThrough;
|
|
113
|
+
let position = 0;
|
|
114
|
+
while (position < args.length) {
|
|
115
|
+
const token = args[position];
|
|
116
|
+
const nextStringPos = readStringFlag(args, position, token, SERVICE_CREATE_STRING_FLAGS, values);
|
|
117
|
+
if (nextStringPos !== undefined) {
|
|
118
|
+
position = nextStringPos;
|
|
113
119
|
continue;
|
|
114
120
|
}
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
invalidUsage('Option may be provided only once: --target', '--target');
|
|
119
|
-
target = targetOpt.value;
|
|
120
|
-
position = targetOpt.consumedThrough;
|
|
121
|
+
const nextSizingPos = readStringFlag(args, position, token, SERVICE_SIZING_FLAGS, parameters);
|
|
122
|
+
if (nextSizingPos !== undefined) {
|
|
123
|
+
position = nextSizingPos;
|
|
121
124
|
continue;
|
|
122
125
|
}
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
namespace = namespaceOpt.value;
|
|
128
|
-
position = namespaceOpt.consumedThrough;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const contextOpt = matchOption(args, position, token, '--context');
|
|
132
|
-
if (contextOpt) {
|
|
133
|
-
if (context !== undefined)
|
|
134
|
-
invalidUsage('Option may be provided only once: --context', '--context');
|
|
135
|
-
context = contextOpt.value;
|
|
136
|
-
position = contextOpt.consumedThrough;
|
|
126
|
+
const envOpt = readEnvFlag(args, position, token, env, 'platform service create');
|
|
127
|
+
if (envOpt) {
|
|
128
|
+
env = envOpt.value;
|
|
129
|
+
position = envOpt.nextPosition;
|
|
137
130
|
continue;
|
|
138
131
|
}
|
|
139
132
|
const deletionOpt = matchOption(args, position, token, '--deletion-policy');
|
|
@@ -146,31 +139,7 @@ export function parseServiceCreateArgs(args) {
|
|
|
146
139
|
});
|
|
147
140
|
}
|
|
148
141
|
deletionPolicy = deletionOpt.value;
|
|
149
|
-
position = deletionOpt.consumedThrough;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
const memoryOpt = matchOption(args, position, token, '--memory');
|
|
153
|
-
if (memoryOpt) {
|
|
154
|
-
if (parameters.memory !== undefined)
|
|
155
|
-
invalidUsage('Option may be provided only once: --memory', '--memory');
|
|
156
|
-
parameters.memory = memoryOpt.value;
|
|
157
|
-
position = memoryOpt.consumedThrough;
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const storageOpt = matchOption(args, position, token, '--storage');
|
|
161
|
-
if (storageOpt) {
|
|
162
|
-
if (parameters.storage !== undefined)
|
|
163
|
-
invalidUsage('Option may be provided only once: --storage', '--storage');
|
|
164
|
-
parameters.storage = storageOpt.value;
|
|
165
|
-
position = storageOpt.consumedThrough;
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
const cpuOpt = matchOption(args, position, token, '--cpu');
|
|
169
|
-
if (cpuOpt) {
|
|
170
|
-
if (parameters.cpu !== undefined)
|
|
171
|
-
invalidUsage('Option may be provided only once: --cpu', '--cpu');
|
|
172
|
-
parameters.cpu = cpuOpt.value;
|
|
173
|
-
position = cpuOpt.consumedThrough;
|
|
142
|
+
position = deletionOpt.consumedThrough + 1;
|
|
174
143
|
continue;
|
|
175
144
|
}
|
|
176
145
|
const timeoutOpt = matchOption(args, position, token, '--timeout');
|
|
@@ -183,19 +152,20 @@ export function parseServiceCreateArgs(args) {
|
|
|
183
152
|
invalidUsage('--timeout must be a positive number of seconds', timeoutOpt.value);
|
|
184
153
|
}
|
|
185
154
|
timeoutMs = Math.floor(parsed * 1000);
|
|
186
|
-
position = timeoutOpt.consumedThrough;
|
|
155
|
+
position = timeoutOpt.consumedThrough + 1;
|
|
187
156
|
continue;
|
|
188
157
|
}
|
|
189
158
|
const destinationOpt = matchOption(args, position, token, '--destination');
|
|
190
159
|
if (destinationOpt) {
|
|
191
160
|
destinations.push(destinationOpt.value);
|
|
192
|
-
position = destinationOpt.consumedThrough;
|
|
161
|
+
position = destinationOpt.consumedThrough + 1;
|
|
193
162
|
continue;
|
|
194
163
|
}
|
|
195
164
|
if (token === '--wait') {
|
|
196
165
|
if (wait)
|
|
197
166
|
invalidUsage('Option may be provided only once: --wait', '--wait');
|
|
198
167
|
wait = true;
|
|
168
|
+
position += 1;
|
|
199
169
|
continue;
|
|
200
170
|
}
|
|
201
171
|
if (token.startsWith('--')) {
|
|
@@ -203,26 +173,29 @@ export function parseServiceCreateArgs(args) {
|
|
|
203
173
|
}
|
|
204
174
|
if (type !== undefined) {
|
|
205
175
|
// `service create egress <name>`: the name may follow the type instead of --name.
|
|
206
|
-
if (name !== undefined)
|
|
176
|
+
if (values.name !== undefined)
|
|
207
177
|
invalidUsage(`Unexpected argument: ${token}`, token, {
|
|
208
178
|
command: 'platform service create',
|
|
209
179
|
});
|
|
210
|
-
name = token;
|
|
180
|
+
values.name = token;
|
|
181
|
+
position += 1;
|
|
211
182
|
continue;
|
|
212
183
|
}
|
|
213
184
|
if (!isServiceType(token)) {
|
|
214
185
|
invalidUsage(`Unknown service type "${token}". Supported types: ${SERVICE_TYPES.join(', ')}`, token, { command: 'platform service create', types: [...SERVICE_TYPES] });
|
|
215
186
|
}
|
|
216
187
|
type = token;
|
|
188
|
+
position += 1;
|
|
217
189
|
}
|
|
218
190
|
return {
|
|
219
191
|
type,
|
|
220
|
-
name,
|
|
221
|
-
className,
|
|
192
|
+
name: values.name,
|
|
193
|
+
className: values.className,
|
|
222
194
|
deletionPolicy,
|
|
223
|
-
target,
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
target: values.target,
|
|
196
|
+
...(env ? { env } : {}),
|
|
197
|
+
namespace: values.namespace,
|
|
198
|
+
context: values.context,
|
|
226
199
|
wait,
|
|
227
200
|
timeoutMs,
|
|
228
201
|
parameters: Object.keys(parameters).length > 0 ? parameters : undefined,
|
|
@@ -231,33 +204,20 @@ export function parseServiceCreateArgs(args) {
|
|
|
231
204
|
}
|
|
232
205
|
export function parseServiceNameArgs(args, command) {
|
|
233
206
|
let name;
|
|
234
|
-
|
|
235
|
-
let
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
const token = args[position]
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
invalidUsage('Option may be provided only once: --target', '--target');
|
|
243
|
-
target = targetOpt.value;
|
|
244
|
-
position = targetOpt.consumedThrough;
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
const namespaceOpt = matchOption(args, position, token, '--namespace');
|
|
248
|
-
if (namespaceOpt) {
|
|
249
|
-
if (namespace !== undefined)
|
|
250
|
-
invalidUsage('Option may be provided only once: --namespace', '--namespace');
|
|
251
|
-
namespace = namespaceOpt.value;
|
|
252
|
-
position = namespaceOpt.consumedThrough;
|
|
207
|
+
const values = {};
|
|
208
|
+
let env;
|
|
209
|
+
let position = 0;
|
|
210
|
+
while (position < args.length) {
|
|
211
|
+
const token = args[position];
|
|
212
|
+
const nextPos = readStringFlag(args, position, token, SERVICE_LIST_STRING_FLAGS, values);
|
|
213
|
+
if (nextPos !== undefined) {
|
|
214
|
+
position = nextPos;
|
|
253
215
|
continue;
|
|
254
216
|
}
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
context = contextOpt.value;
|
|
260
|
-
position = contextOpt.consumedThrough;
|
|
217
|
+
const envOpt = readEnvFlag(args, position, token, env, command);
|
|
218
|
+
if (envOpt) {
|
|
219
|
+
env = envOpt.value;
|
|
220
|
+
position = envOpt.nextPosition;
|
|
261
221
|
continue;
|
|
262
222
|
}
|
|
263
223
|
if (token.startsWith('--')) {
|
|
@@ -267,37 +227,24 @@ export function parseServiceNameArgs(args, command) {
|
|
|
267
227
|
invalidUsage(`Unexpected argument: ${token}`, token, { command });
|
|
268
228
|
}
|
|
269
229
|
name = token;
|
|
230
|
+
position += 1;
|
|
270
231
|
}
|
|
271
|
-
return {
|
|
232
|
+
return {
|
|
233
|
+
name,
|
|
234
|
+
target: values.target,
|
|
235
|
+
...(env ? { env } : {}),
|
|
236
|
+
namespace: values.namespace,
|
|
237
|
+
context: values.context,
|
|
238
|
+
};
|
|
272
239
|
}
|
|
273
240
|
export function parseServiceListArgs(args) {
|
|
274
|
-
|
|
275
|
-
let
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (target !== undefined)
|
|
282
|
-
invalidUsage('Option may be provided only once: --target', '--target');
|
|
283
|
-
target = targetOpt.value;
|
|
284
|
-
position = targetOpt.consumedThrough;
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
const namespaceOpt = matchOption(args, position, token, '--namespace');
|
|
288
|
-
if (namespaceOpt) {
|
|
289
|
-
if (namespace !== undefined)
|
|
290
|
-
invalidUsage('Option may be provided only once: --namespace', '--namespace');
|
|
291
|
-
namespace = namespaceOpt.value;
|
|
292
|
-
position = namespaceOpt.consumedThrough;
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
const contextOpt = matchOption(args, position, token, '--context');
|
|
296
|
-
if (contextOpt) {
|
|
297
|
-
if (context !== undefined)
|
|
298
|
-
invalidUsage('Option may be provided only once: --context', '--context');
|
|
299
|
-
context = contextOpt.value;
|
|
300
|
-
position = contextOpt.consumedThrough;
|
|
241
|
+
const values = {};
|
|
242
|
+
let position = 0;
|
|
243
|
+
while (position < args.length) {
|
|
244
|
+
const token = args[position];
|
|
245
|
+
const nextPos = readStringFlag(args, position, token, SERVICE_LIST_STRING_FLAGS, values);
|
|
246
|
+
if (nextPos !== undefined) {
|
|
247
|
+
position = nextPos;
|
|
301
248
|
continue;
|
|
302
249
|
}
|
|
303
250
|
if (token.startsWith('--')) {
|
|
@@ -305,7 +252,11 @@ export function parseServiceListArgs(args) {
|
|
|
305
252
|
}
|
|
306
253
|
invalidUsage(`Unexpected argument: ${token}`, token, { command: 'platform service list' });
|
|
307
254
|
}
|
|
308
|
-
return {
|
|
255
|
+
return {
|
|
256
|
+
target: values.target,
|
|
257
|
+
namespace: values.namespace,
|
|
258
|
+
context: values.context,
|
|
259
|
+
};
|
|
309
260
|
}
|
|
310
261
|
function validateSizing(parameters) {
|
|
311
262
|
if (!parameters)
|
|
@@ -373,12 +324,8 @@ async function resolveServiceConnection(options, deps) {
|
|
|
373
324
|
return connection;
|
|
374
325
|
}
|
|
375
326
|
function kubectlFailure(verb, result, details = {}) {
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
`kubectl exited ${result.exitCode}`)
|
|
379
|
-
.split('\n')
|
|
380
|
-
.slice(0, 12)
|
|
381
|
-
.join('\n');
|
|
327
|
+
const rawDetail = result.stderr.trim() || result.stdout.trim() || `kubectl exited ${result.exitCode}`;
|
|
328
|
+
const detail = rawDetail.split('\n').slice(0, 12).join('\n');
|
|
382
329
|
const lower = detail.toLowerCase();
|
|
383
330
|
if (lower.includes('alreadyexists') || lower.includes('already exists')) {
|
|
384
331
|
return new CommandFailure('WASMCLOUD_SERVICE_ALREADY_EXISTS', `BackingService already exists: ${detail}`, 2, { ...details, stderr: detail });
|
|
@@ -405,11 +352,10 @@ function readyCondition(document) {
|
|
|
405
352
|
export function summarizeService(document) {
|
|
406
353
|
const ready = readyCondition(document);
|
|
407
354
|
const endpoint = document.status?.endpoint;
|
|
408
|
-
const
|
|
409
|
-
document.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
: '');
|
|
355
|
+
const defaultClass = document.spec?.type && isServiceType(document.spec.type)
|
|
356
|
+
? DEFAULT_SERVICE_CLASSES[document.spec.type]
|
|
357
|
+
: '';
|
|
358
|
+
const className = document.spec?.className || document.status?.classRef?.name || defaultClass;
|
|
413
359
|
return {
|
|
414
360
|
name: document.metadata?.name ?? '',
|
|
415
361
|
namespace: document.metadata?.namespace ?? '',
|
|
@@ -524,9 +470,50 @@ async function getServiceDocument(connection, name, deps) {
|
|
|
524
470
|
throw new CommandFailure('WASMCLOUD_TOOL_FAILED', `kubectl get returned unparseable JSON for BackingService ${name}`, 3, { name, namespace: connection.namespace });
|
|
525
471
|
}
|
|
526
472
|
}
|
|
473
|
+
async function runControllerServiceCreate(type, name, options, target, deployManifest, deps) {
|
|
474
|
+
try {
|
|
475
|
+
const { credential, client } = await resolveControllerSession({ target }, deps);
|
|
476
|
+
const env = options.env ?? target.env ?? deployManifest.env ?? 'prod';
|
|
477
|
+
const created = await client.createService({
|
|
478
|
+
env,
|
|
479
|
+
type,
|
|
480
|
+
name,
|
|
481
|
+
className: options.className,
|
|
482
|
+
parameters: options.parameters,
|
|
483
|
+
deletionPolicy: options.deletionPolicy,
|
|
484
|
+
destinations: options.destinations,
|
|
485
|
+
});
|
|
486
|
+
const data = {
|
|
487
|
+
name: created.name,
|
|
488
|
+
type: created.type,
|
|
489
|
+
className: created.className,
|
|
490
|
+
env: created.env,
|
|
491
|
+
account: credential.account,
|
|
492
|
+
namespace: tenantNamespace(credential.account),
|
|
493
|
+
target: target.name,
|
|
494
|
+
...(created.parameters ? { parameters: created.parameters } : {}),
|
|
495
|
+
...(created.deletionPolicy ? { deletionPolicy: created.deletionPolicy } : {}),
|
|
496
|
+
...(created.destinations ? { destinations: created.destinations } : {}),
|
|
497
|
+
wait: options.wait,
|
|
498
|
+
ready: 'True',
|
|
499
|
+
createdAt: created.createdAt,
|
|
500
|
+
resource: { apiVersion: BACKING_SERVICE_API_VERSION, kind: BACKING_SERVICE_KIND },
|
|
501
|
+
};
|
|
502
|
+
const text = `Created ${created.type} service ${created.name} (${created.className}) in ${created.env} (${credential.account}).`;
|
|
503
|
+
return { data, text };
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
wrapControllerError(error);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
527
509
|
export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
|
|
528
510
|
const options = parseServiceCreateArgs(args);
|
|
529
511
|
const { type, name } = validateCreateOptions(options);
|
|
512
|
+
const deployManifest = loadDeployManifest(deps.cwd(), deps.env);
|
|
513
|
+
const target = resolveTarget(deployManifest, options.target);
|
|
514
|
+
if (isControllerBackedTarget(target)) {
|
|
515
|
+
return runControllerServiceCreate(type, name, options, target, deployManifest, deps);
|
|
516
|
+
}
|
|
530
517
|
const connection = await resolveServiceConnection(options, deps);
|
|
531
518
|
const existing = await captureKubectl(deps, connection, ['get', BACKING_SERVICE_RESOURCE, name, '-o', 'name'], deps.cwd());
|
|
532
519
|
if (existing.exitCode === 0) {
|
|
@@ -571,6 +558,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
|
|
|
571
558
|
ready: 'Unknown',
|
|
572
559
|
...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
|
|
573
560
|
};
|
|
561
|
+
const context = options.context ?? connection.context;
|
|
574
562
|
return {
|
|
575
563
|
data: {
|
|
576
564
|
name,
|
|
@@ -578,9 +566,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
|
|
|
578
566
|
className: summary.className,
|
|
579
567
|
namespace: connection.namespace,
|
|
580
568
|
target: connection.target,
|
|
581
|
-
...(
|
|
582
|
-
? { context: options.context ?? connection.context }
|
|
583
|
-
: {}),
|
|
569
|
+
...(context !== undefined ? { context } : {}),
|
|
584
570
|
...(options.parameters ? { parameters: options.parameters } : {}),
|
|
585
571
|
...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
|
|
586
572
|
...(options.destinations ? { destinations: options.destinations } : {}),
|
|
@@ -649,6 +635,26 @@ export async function runWasmcloudServiceGet(args, _io, deps = DEFAULT_DEPS) {
|
|
|
649
635
|
text: formatServiceDetail(summary),
|
|
650
636
|
};
|
|
651
637
|
}
|
|
638
|
+
async function runControllerServiceDelete(name, options, target, deployManifest, deps) {
|
|
639
|
+
try {
|
|
640
|
+
const { credential, client } = await resolveControllerSession({ target }, deps);
|
|
641
|
+
const env = options.env ?? target.env ?? deployManifest.env ?? 'prod';
|
|
642
|
+
await client.deleteService(env, name);
|
|
643
|
+
const data = {
|
|
644
|
+
name,
|
|
645
|
+
env,
|
|
646
|
+
account: credential.account,
|
|
647
|
+
namespace: tenantNamespace(credential.account),
|
|
648
|
+
target: target.name,
|
|
649
|
+
deleted: true,
|
|
650
|
+
};
|
|
651
|
+
const text = `Deleted BackingService ${name} from ${env} (${credential.account}).`;
|
|
652
|
+
return { data, text };
|
|
653
|
+
}
|
|
654
|
+
catch (error) {
|
|
655
|
+
wrapControllerError(error);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
652
658
|
export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
|
|
653
659
|
const options = parseServiceNameArgs(args, 'platform service delete');
|
|
654
660
|
if (options.name === undefined) {
|
|
@@ -659,6 +665,11 @@ export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
|
|
|
659
665
|
if (!isBackingServiceName(options.name)) {
|
|
660
666
|
invalidUsage(`Invalid service name "${options.name}". Names must be DNS labels of at most 40 characters`, options.name, { command: 'platform service delete' });
|
|
661
667
|
}
|
|
668
|
+
const deployManifest = loadDeployManifest(deps.cwd(), deps.env);
|
|
669
|
+
const target = resolveTarget(deployManifest, options.target);
|
|
670
|
+
if (isControllerBackedTarget(target)) {
|
|
671
|
+
return runControllerServiceDelete(options.name, options, target, deployManifest, deps);
|
|
672
|
+
}
|
|
662
673
|
const connection = await resolveServiceConnection(options, deps);
|
|
663
674
|
let deletionPolicy;
|
|
664
675
|
try {
|
package/dist/target.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WasmcloudDeps } from './deps.js';
|
|
2
|
-
import type { DeployManifest, DeployTarget } from './manifest.js';
|
|
2
|
+
import type { AccountTarget, ControllerTarget, DeployManifest, DeployTarget } from './manifest.js';
|
|
3
3
|
import { type PlatformOutputs } from './platform.js';
|
|
4
4
|
import { type RegistryLocation } from './registry.js';
|
|
5
5
|
export type ClusterConnection = {
|
|
@@ -14,5 +14,11 @@ export type ClusterConnection = {
|
|
|
14
14
|
platformRoot?: string;
|
|
15
15
|
stack?: string;
|
|
16
16
|
};
|
|
17
|
+
export declare function isControllerBackedTarget(target: DeployTarget): target is AccountTarget | ControllerTarget;
|
|
18
|
+
/**
|
|
19
|
+
* Derives the platform gateway route for a tenant controller (`https://<account>.controller.<domain>`),
|
|
20
|
+
* matching the HTTPRoute created by the platform tenancy reconcile (platform#58).
|
|
21
|
+
*/
|
|
22
|
+
export declare function discoverAccountControllerUrl(account: string, domain?: string, env?: Record<string, string | undefined>): string;
|
|
17
23
|
export declare function resolveTarget(manifest: DeployManifest, requested?: string): DeployTarget;
|
|
18
24
|
export declare function resolveConnection(target: DeployTarget, workspaceRoot: string, manifestPath: string, deps: WasmcloudDeps): Promise<ClusterConnection>;
|
package/dist/target.js
CHANGED
|
@@ -2,6 +2,17 @@ import { resolve } from 'node:path';
|
|
|
2
2
|
import { CommandFailure } from '@di-framework/cli-extension';
|
|
3
3
|
import { loadPlatformOutputs, resolvePlatformDirectory } from './platform.js';
|
|
4
4
|
import { materializeRegistry } from './registry.js';
|
|
5
|
+
export function isControllerBackedTarget(target) {
|
|
6
|
+
return target.kind === 'account' || target.kind === 'controller';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Derives the platform gateway route for a tenant controller (`https://<account>.controller.<domain>`),
|
|
10
|
+
* matching the HTTPRoute created by the platform tenancy reconcile (platform#58).
|
|
11
|
+
*/
|
|
12
|
+
export function discoverAccountControllerUrl(account, domain, env) {
|
|
13
|
+
const effectiveDomain = domain ?? env?.DI_PLATFORM_DOMAIN ?? 'localhost';
|
|
14
|
+
return `https://${account}.controller.${effectiveDomain}`;
|
|
15
|
+
}
|
|
5
16
|
export function resolveTarget(manifest, requested) {
|
|
6
17
|
const name = requested ?? manifest.defaultTarget;
|
|
7
18
|
if (name === undefined) {
|
|
@@ -14,6 +25,14 @@ export function resolveTarget(manifest, requested) {
|
|
|
14
25
|
return target;
|
|
15
26
|
}
|
|
16
27
|
export async function resolveConnection(target, workspaceRoot, manifestPath, deps) {
|
|
28
|
+
if (isControllerBackedTarget(target)) {
|
|
29
|
+
const msg = `Target "${target.name}" is a ${target.kind} target and talks to the tenant controller /v1 API rather than a kubeconfig.`;
|
|
30
|
+
throw new CommandFailure('WASMCLOUD_TARGET_INVALID_KIND', msg, 2, {
|
|
31
|
+
target: target.name,
|
|
32
|
+
kind: target.kind,
|
|
33
|
+
manifestPath,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
17
36
|
if (target.kind === 'managed') {
|
|
18
37
|
return resolveManagedConnection(target, workspaceRoot, manifestPath, deps);
|
|
19
38
|
}
|
package/dist/workload.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ import type { ClusterConnection } from './target.js';
|
|
|
8
8
|
import { type WitRequirement } from './wit.js';
|
|
9
9
|
export declare const MANAGED_BY_LABEL = "di-framework";
|
|
10
10
|
export declare const WAIT_ATTEMPTS = 30;
|
|
11
|
+
export declare const STORAGE_WAIT_ATTEMPTS = 90;
|
|
11
12
|
export declare const WAIT_INTERVAL_MS = 2000;
|
|
13
|
+
export declare const DEFAULT_DEPLOY_TIMEOUT_SECONDS = 60;
|
|
14
|
+
export declare const STORAGE_DEPLOY_TIMEOUT_SECONDS = 180;
|
|
15
|
+
export declare const DEPLOY_TIMEOUT_ENV = "DI_FRAMEWORK_DEPLOY_TIMEOUT_SECONDS";
|
|
12
16
|
export declare const WORKLOAD_DEPLOYMENT_RESOURCE = "workloaddeployment.runtime.wasmcloud.dev";
|
|
13
17
|
export declare const WORKLOAD_REPLICA_SET_RESOURCE = "workloadreplicaset.runtime.wasmcloud.dev";
|
|
14
18
|
/** Host directory where the storage hostgroup mounts the shared PVC. */
|
|
@@ -137,5 +141,17 @@ export declare function writeControlSecret(project: WasmcloudProject, connection
|
|
|
137
141
|
export declare function deleteControlSecret(project: WasmcloudProject, connection: ClusterConnection, deps: WasmcloudDeps): Promise<void>;
|
|
138
142
|
export declare function applyWorkload(project: WasmcloudProject, connection: ClusterConnection, image: string, io: CliIo, deps: WasmcloudDeps): Promise<string>;
|
|
139
143
|
export declare function deleteWorkload(project: WasmcloudProject, connection: ClusterConnection, io: CliIo, deps: WasmcloudDeps): Promise<void>;
|
|
140
|
-
export declare function
|
|
144
|
+
export declare function projectHasStorageOrPglite(project: WasmcloudProject & {
|
|
145
|
+
storage?: unknown;
|
|
146
|
+
}): boolean;
|
|
147
|
+
export declare function resolveDeployTimeoutSeconds(project: WasmcloudProject & {
|
|
148
|
+
storage?: unknown;
|
|
149
|
+
}, deps: Pick<WasmcloudDeps, 'env'>, options?: {
|
|
150
|
+
timeoutSeconds?: number;
|
|
151
|
+
}): number;
|
|
152
|
+
export declare function waitForReady(project: WasmcloudProject & {
|
|
153
|
+
storage?: unknown;
|
|
154
|
+
}, connection: ClusterConnection, deps: WasmcloudDeps, io?: CliIo, options?: {
|
|
155
|
+
timeoutSeconds?: number;
|
|
156
|
+
}): Promise<void>;
|
|
141
157
|
export declare function isReady(stdout: string): boolean;
|
package/dist/workload.js
CHANGED
|
@@ -18,7 +18,11 @@ import { kubectlStatusReason, SECRET_UPDATE_KEYS_MESSAGE } from './secret-admiss
|
|
|
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. */
|
|
@@ -569,7 +573,7 @@ function controlSecretWriteFailed(command, name, connection, result, secrets) {
|
|
|
569
573
|
.filter((secret) => secret.length > 0)
|
|
570
574
|
.sort((a, b) => b.length - a.length);
|
|
571
575
|
const stderr = sanitizePublicText(scrub.reduce((text, secret) => redact(text, secret), result.stderr).trim());
|
|
572
|
-
if (kubectlStatusReason(stderr) === 'Conflict') {
|
|
576
|
+
if (kubectlStatusReason(result.stderr) === 'Conflict') {
|
|
573
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 });
|
|
574
578
|
}
|
|
575
579
|
const reason = stderr.length > 0 ? `: ${stderr}` : '';
|
|
@@ -613,11 +617,8 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
613
617
|
cronJobs.length > 0 ||
|
|
614
618
|
queueHandlers.length > 0 ||
|
|
615
619
|
hasPersistentStorage;
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
: isWorker
|
|
619
|
-
? queueProjectRequirements()
|
|
620
|
-
: [];
|
|
620
|
+
const workerRequirements = isWorker ? queueProjectRequirements() : [];
|
|
621
|
+
const baseRequirements = needsHttp ? defaultProjectRequirements() : workerRequirements;
|
|
621
622
|
const requirements = [
|
|
622
623
|
...baseRequirements,
|
|
623
624
|
...requirementsFromBindings(bindings),
|
|
@@ -679,8 +680,12 @@ export async function applyWorkload(project, connection, image, io, deps) {
|
|
|
679
680
|
* so every cron invocation is refused until a deploy succeeds. Say so in the failure.
|
|
680
681
|
*/
|
|
681
682
|
function withRotatedTokenNotice(error) {
|
|
682
|
-
if (!isCommandFailure(error))
|
|
683
|
+
if (!isCommandFailure(error)) {
|
|
684
|
+
if (error instanceof Error) {
|
|
685
|
+
error.message = `${error.message}; ${CONTROL_TOKEN_ROTATED_NOTICE}`;
|
|
686
|
+
}
|
|
683
687
|
return error;
|
|
688
|
+
}
|
|
684
689
|
// Every failure on this path (kubectl, readiness) carries an object of details.
|
|
685
690
|
const details = error.details;
|
|
686
691
|
return new CommandFailure(error.code, `${error.message}; ${CONTROL_TOKEN_ROTATED_NOTICE}`, error.exitCode, { ...details, controlTokenRotated: true });
|
|
@@ -731,22 +736,50 @@ export async function deleteWorkload(project, connection, io, deps) {
|
|
|
731
736
|
await cleanupManagedBindings(project, connection, new Set(), deps);
|
|
732
737
|
await removeWorkloadEgress(project, connection, deps);
|
|
733
738
|
}
|
|
734
|
-
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) {
|
|
735
762
|
const name = deploymentResourceName(project);
|
|
736
|
-
|
|
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++) {
|
|
737
766
|
const result = await captureKubectl(deps, connection, ['get', WORKLOAD_DEPLOYMENT_RESOURCE, name, '-o', 'json'], project.projectRoot);
|
|
738
767
|
if (result.exitCode === 0 && isReady(result.stdout))
|
|
739
768
|
return;
|
|
740
769
|
await deps.wait(WAIT_INTERVAL_MS);
|
|
741
770
|
}
|
|
742
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}".`;
|
|
743
775
|
if (io !== undefined) {
|
|
744
|
-
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`);
|
|
745
777
|
}
|
|
746
|
-
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, {
|
|
747
779
|
application: project.applicationName,
|
|
748
780
|
namespace: connection.namespace,
|
|
749
781
|
name,
|
|
782
|
+
timeoutSeconds,
|
|
750
783
|
diagnostics,
|
|
751
784
|
});
|
|
752
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",
|