@serve.zone/interfaces 32.22.0 → 32.23.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/changelog.md +46 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/corestorelegacyadoption.d.ts +178 -0
- package/dist_ts/data/corestorelegacyadoption.js +289 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/data/networkprotection.d.ts +13 -0
- package/dist_ts/data/networkprotection.js +8 -2
- package/dist_ts/data/service.d.ts +15 -1
- package/dist_ts/data/service.js +1 -1
- package/dist_ts/data/serviceruntime.d.ts +8 -3
- package/dist_ts/data/serviceruntime.js +3 -2
- package/dist_ts/data/servicevolumeinitialization.d.ts +91 -0
- package/dist_ts/data/servicevolumeinitialization.js +93 -0
- package/dist_ts/platform/types.d.ts +45 -0
- package/dist_ts/platform/types.js +27 -2
- package/dist_ts/requests/corestore.d.ts +60 -0
- package/dist_ts/requests/corestore.js +1 -1
- package/dist_ts/requests/platform.d.ts +6 -1
- package/dist_ts/requests/service.d.ts +23 -0
- package/package.json +1 -1
- package/readme.md +133 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/corestorelegacyadoption.ts +471 -0
- package/ts/data/index.ts +2 -0
- package/ts/data/networkprotection.ts +20 -1
- package/ts/data/service.ts +16 -0
- package/ts/data/serviceruntime.ts +8 -2
- package/ts/data/servicevolumeinitialization.ts +159 -0
- package/ts/platform/types.ts +75 -0
- package/ts/requests/corestore.ts +79 -0
- package/ts/requests/platform.ts +6 -0
- package/ts/requests/service.ts +28 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import type { IObjectStorageRetentionIntent } from '../platform/objectstorageretention.js';
|
|
2
|
+
import {
|
|
3
|
+
objectStorageRetentionIntentsEqual,
|
|
4
|
+
validateObjectStorageRetentionIntent,
|
|
5
|
+
} from '../platform/objectstorageretention.js';
|
|
6
|
+
import { validatePlatformObjectStorageBucketName } from '../platform/objectstorage.js';
|
|
7
|
+
import type { TPlatformBindingStatusReason } from '../platform/types.js';
|
|
8
|
+
import { platformBindingStatusReasons } from '../platform/types.js';
|
|
9
|
+
import {
|
|
10
|
+
canonicalizeStrictJson,
|
|
11
|
+
compareWireTokens,
|
|
12
|
+
createCanonicalJsonSha256Hex,
|
|
13
|
+
} from '../private/canonicaljson.js';
|
|
14
|
+
import { hasExactKeys, isPlainRecord } from '../private/dataproperties.js';
|
|
15
|
+
import { isClusterNodeId } from '../private/nodeidentifier.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Moving a service's legacy Corestore resources into credential bindings.
|
|
19
|
+
*
|
|
20
|
+
* A Corestore root converted from a release before 32 still holds the databases and buckets
|
|
21
|
+
* `/resources/provision` created, one per service and capability, in its manifest. Corestore
|
|
22
|
+
* refuses a credential binding beside such a resource until an operator authorizes that exact
|
|
23
|
+
* binding to adopt it, offline, with a plan file. The flow across the three owners:
|
|
24
|
+
*
|
|
25
|
+
* 1. Corestore answers `GET /control/legacy-resources` with its `ICorestoreLegacyResourceInventory`;
|
|
26
|
+
* the cluster relay reads it for Cloudly (`getClusterCorestoreLegacyResources`).
|
|
27
|
+
* 2. `adoptCorestoreLegacyResources` checks the admin's selection against that inventory at an
|
|
28
|
+
* exact digest, creates each adopting binding with the legacy bucket and retention intent, and
|
|
29
|
+
* answers the plan (`ICorestoreLegacyResourceAdoptionPlanEntry[]`).
|
|
30
|
+
* 3. The operator stops Corestore and runs its `legacy-resource-adoption` migration with that plan.
|
|
31
|
+
* Until then Corestore refuses the binding, which reports `legacy-adoption-pending`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export type TCorestoreLegacyCapability = 'database' | 'objectstorage';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Why Corestore's offline adoption would refuse an unadopted resource:
|
|
38
|
+
*
|
|
39
|
+
* - `not-adoptable`: its identity is not what a credential binding can adopt (an
|
|
40
|
+
* allocation-managed database, another provider, a resource name that differs from its database
|
|
41
|
+
* or bucket name, or a bucket name that is not a canonical S3 name);
|
|
42
|
+
* - `ordinary-credentials-rotated`: its credentials were rotated, so the delivered ones are no
|
|
43
|
+
* longer the generation a binding adopts;
|
|
44
|
+
* - `owned-by-binding`: a credential binding or a named storage binding already owns the service
|
|
45
|
+
* capability, the resource or the bucket.
|
|
46
|
+
*/
|
|
47
|
+
export type TCorestoreLegacyResourceBlocker =
|
|
48
|
+
| 'not-adoptable'
|
|
49
|
+
| 'ordinary-credentials-rotated'
|
|
50
|
+
| 'owned-by-binding';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `unadopted` names what would stop the offline adoption, or `null` when nothing would;
|
|
54
|
+
* `authorized` names the binding the operator authorized, which is the only binding Corestore will
|
|
55
|
+
* let take the resource. A consumed adoption leaves no legacy resource behind, so it never appears.
|
|
56
|
+
*/
|
|
57
|
+
export type TCorestoreLegacyResourceAdoption =
|
|
58
|
+
| { state: 'unadopted'; blocker: TCorestoreLegacyResourceBlocker | null }
|
|
59
|
+
| { state: 'authorized'; bindingId: string };
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* One legacy resource, by the identity Corestore's manifest states. A database is named by its
|
|
63
|
+
* database name, a bucket by its bucket name and its retention intent, `null` when it has none.
|
|
64
|
+
*/
|
|
65
|
+
export type TCorestoreLegacyResource =
|
|
66
|
+
| { capability: 'database'; databaseName: string; adoption: TCorestoreLegacyResourceAdoption }
|
|
67
|
+
| {
|
|
68
|
+
capability: 'objectstorage';
|
|
69
|
+
bucketName: string;
|
|
70
|
+
retention: IObjectStorageRetentionIntent | null;
|
|
71
|
+
adoption: TCorestoreLegacyResourceAdoption;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** One service's legacy resources, at most one per capability, `database` first. */
|
|
75
|
+
export interface ICorestoreLegacyServiceResources {
|
|
76
|
+
serviceId: string;
|
|
77
|
+
resources: TCorestoreLegacyResource[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What Corestore answers on `GET /control/legacy-resources`: every service, sorted by id. */
|
|
81
|
+
export interface ICorestoreLegacyResourceInventory {
|
|
82
|
+
services: ICorestoreLegacyServiceResources[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* One node's legacy resources as the cluster relay read them. An unreachable node names why and
|
|
87
|
+
* lists nothing, because a silent empty list would read as a node with nothing to adopt.
|
|
88
|
+
*/
|
|
89
|
+
export type TClusterCorestoreLegacyResourceInventory =
|
|
90
|
+
| { nodeId: string; checkedAt: number; reachable: true; services: ICorestoreLegacyServiceResources[] }
|
|
91
|
+
| {
|
|
92
|
+
nodeId: string;
|
|
93
|
+
checkedAt: number;
|
|
94
|
+
reachable: false;
|
|
95
|
+
errorCode: 'CORESTORE_ENDPOINT_UNKNOWN' | 'CORESTORE_UNREACHABLE';
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** One resource an administrator selects for adoption. */
|
|
99
|
+
export interface ICorestoreLegacyResourceSelection {
|
|
100
|
+
serviceId: string;
|
|
101
|
+
capability: TCorestoreLegacyCapability;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* One entry of Corestore's offline adoption plan, exactly the object its
|
|
106
|
+
* `legacy-resource-adoption` migration reads: the service, the capability and the binding that may
|
|
107
|
+
* adopt its legacy resource. The legacy identity is Corestore's own and is not restated here.
|
|
108
|
+
*/
|
|
109
|
+
export interface ICorestoreLegacyResourceAdoptionPlanEntry {
|
|
110
|
+
serviceId: string;
|
|
111
|
+
capability: TCorestoreLegacyCapability;
|
|
112
|
+
bindingId: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Why `adoptCorestoreLegacyResources` wrote nothing:
|
|
117
|
+
*
|
|
118
|
+
* - `legacy-inventory-unreachable`: the relay could not read the node's Corestore (retryable);
|
|
119
|
+
* - `legacy-inventory-changed`: the inventory no longer has `expectedInventorySha256`;
|
|
120
|
+
* - `legacy-resource-absent`: a selected service has no legacy resource of that capability;
|
|
121
|
+
* - `legacy-resource-blocked`: a selected resource is unadopted with a blocker;
|
|
122
|
+
* - `legacy-resource-authorized-elsewhere`: a selected resource is authorized for a binding Cloudly
|
|
123
|
+
* does not hold as that resource's adoption;
|
|
124
|
+
* - `service-absent`: Cloudly has no such service;
|
|
125
|
+
* - `binding-exists`: the service already has a binding of that capability that adopts nothing,
|
|
126
|
+
* or adopts another resource.
|
|
127
|
+
*/
|
|
128
|
+
export type TCorestoreLegacyAdoptionRefusal =
|
|
129
|
+
| 'legacy-inventory-unreachable'
|
|
130
|
+
| 'legacy-inventory-changed'
|
|
131
|
+
| 'legacy-resource-absent'
|
|
132
|
+
| 'legacy-resource-blocked'
|
|
133
|
+
| 'legacy-resource-authorized-elsewhere'
|
|
134
|
+
| 'service-absent'
|
|
135
|
+
| 'binding-exists';
|
|
136
|
+
|
|
137
|
+
/** The named refusal of `adoptCorestoreLegacyResources`, sent as `TypedResponseError.errorData`. */
|
|
138
|
+
export interface ICorestoreLegacyAdoptionErrorData {
|
|
139
|
+
code: TCorestoreLegacyAdoptionRefusal;
|
|
140
|
+
/** True for `legacy-inventory-unreachable` only; every other refusal needs a new read first. */
|
|
141
|
+
retryable: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const corestoreLegacyAdoptionContract = Object.freeze({
|
|
145
|
+
/** Corestore's control path for its legacy inventory, bearer-authenticated like every other. */
|
|
146
|
+
inventoryPath: '/control/legacy-resources',
|
|
147
|
+
/** Corestore's own plan bound, which also bounds a selection and an inventory. */
|
|
148
|
+
maximumPlanEntries: 4096,
|
|
149
|
+
maximumServices: 4096,
|
|
150
|
+
maximumNameLength: 255,
|
|
151
|
+
digestDomain: 'serve.zone/corestore-legacy-resources',
|
|
152
|
+
} as const);
|
|
153
|
+
|
|
154
|
+
const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
|
|
155
|
+
const printableNamePattern = /^[\x21-\x7e]+$/;
|
|
156
|
+
const bareSha256Pattern = /^[a-f0-9]{64}$/;
|
|
157
|
+
const blockers: readonly TCorestoreLegacyResourceBlocker[] = [
|
|
158
|
+
'not-adoptable', 'ordinary-credentials-rotated', 'owned-by-binding',
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
const isIdentifier = (valueArg: unknown): valueArg is string => (
|
|
162
|
+
typeof valueArg === 'string' && identifierPattern.test(valueArg)
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const isLegacyName = (valueArg: unknown): valueArg is string => (
|
|
166
|
+
typeof valueArg === 'string'
|
|
167
|
+
&& valueArg.length <= corestoreLegacyAdoptionContract.maximumNameLength
|
|
168
|
+
&& printableNamePattern.test(valueArg)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const isCapability = (valueArg: unknown): valueArg is TCorestoreLegacyCapability => (
|
|
172
|
+
valueArg === 'database' || valueArg === 'objectstorage'
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const validateAdoption = (valueArg: unknown, pathArg: string): string[] => {
|
|
176
|
+
if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
|
|
177
|
+
if (valueArg.state === 'unadopted') {
|
|
178
|
+
if (!hasExactKeys(valueArg, ['state', 'blocker'])) return [`${pathArg} must use its exact schema`];
|
|
179
|
+
return valueArg.blocker === null || (blockers as readonly unknown[]).includes(valueArg.blocker)
|
|
180
|
+
? []
|
|
181
|
+
: [`${pathArg} blocker must be null or a named blocker`];
|
|
182
|
+
}
|
|
183
|
+
if (valueArg.state === 'authorized') {
|
|
184
|
+
if (!hasExactKeys(valueArg, ['state', 'bindingId'])) return [`${pathArg} must use its exact schema`];
|
|
185
|
+
return isIdentifier(valueArg.bindingId) ? [] : [`${pathArg} bindingId must be a canonical identifier`];
|
|
186
|
+
}
|
|
187
|
+
return [`${pathArg} state must be unadopted or authorized`];
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** An adoptable resource is one the offline adoption could authorize or already did. */
|
|
191
|
+
const isAdoptable = (adoptionArg: unknown): boolean => (
|
|
192
|
+
isPlainRecord(adoptionArg) && (adoptionArg.state === 'authorized' || adoptionArg.blocker === null)
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const validateResource = (valueArg: unknown, pathArg: string): string[] => {
|
|
196
|
+
if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
|
|
197
|
+
if (valueArg.capability === 'database') {
|
|
198
|
+
if (!hasExactKeys(valueArg, ['capability', 'databaseName', 'adoption'])) {
|
|
199
|
+
return [`${pathArg} must use its exact schema`];
|
|
200
|
+
}
|
|
201
|
+
const errors = validateAdoption(valueArg.adoption, `${pathArg} adoption`);
|
|
202
|
+
if (!isLegacyName(valueArg.databaseName)) errors.push(`${pathArg} databaseName must be a bounded printable name`);
|
|
203
|
+
return errors;
|
|
204
|
+
}
|
|
205
|
+
if (valueArg.capability === 'objectstorage') {
|
|
206
|
+
if (!hasExactKeys(valueArg, ['capability', 'bucketName', 'retention', 'adoption'])) {
|
|
207
|
+
return [`${pathArg} must use its exact schema`];
|
|
208
|
+
}
|
|
209
|
+
const errors = validateAdoption(valueArg.adoption, `${pathArg} adoption`);
|
|
210
|
+
if (!isLegacyName(valueArg.bucketName)) {
|
|
211
|
+
errors.push(`${pathArg} bucketName must be a bounded printable name`);
|
|
212
|
+
} else if (errors.length === 0 && isAdoptable(valueArg.adoption)) {
|
|
213
|
+
// A binding request carries only a canonical bucket, so an adoptable bucket has to be one.
|
|
214
|
+
errors.push(...validatePlatformObjectStorageBucketName(valueArg.bucketName, `${pathArg} bucketName`));
|
|
215
|
+
}
|
|
216
|
+
if (valueArg.retention !== null) {
|
|
217
|
+
errors.push(...validateObjectStorageRetentionIntent(valueArg.retention, `${pathArg} retention`));
|
|
218
|
+
}
|
|
219
|
+
return errors;
|
|
220
|
+
}
|
|
221
|
+
return [`${pathArg} capability must be database or objectstorage`];
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const validateServices = (valueArg: unknown, pathArg: string): string[] => {
|
|
225
|
+
if (!Array.isArray(valueArg) || valueArg.length > corestoreLegacyAdoptionContract.maximumServices) {
|
|
226
|
+
return [`${pathArg} must be a bounded array`];
|
|
227
|
+
}
|
|
228
|
+
const errors: string[] = [];
|
|
229
|
+
let previousServiceId: string | undefined;
|
|
230
|
+
for (const [index, service] of valueArg.entries()) {
|
|
231
|
+
const servicePath = `${pathArg}[${index}]`;
|
|
232
|
+
if (!isPlainRecord(service) || !hasExactKeys(service, ['serviceId', 'resources'])) {
|
|
233
|
+
errors.push(`${servicePath} must use its exact schema`);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (!isIdentifier(service.serviceId)) {
|
|
237
|
+
errors.push(`${servicePath} serviceId must be a canonical identifier`);
|
|
238
|
+
} else {
|
|
239
|
+
if (previousServiceId !== undefined && compareWireTokens(previousServiceId, service.serviceId) >= 0) {
|
|
240
|
+
errors.push(`${pathArg} must be sorted by serviceId without repeats`);
|
|
241
|
+
}
|
|
242
|
+
previousServiceId = service.serviceId;
|
|
243
|
+
}
|
|
244
|
+
if (!Array.isArray(service.resources) || service.resources.length < 1 || service.resources.length > 2) {
|
|
245
|
+
errors.push(`${servicePath} resources must list one or two resources`);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
for (const [resourceIndex, resource] of service.resources.entries()) {
|
|
249
|
+
errors.push(...validateResource(resource, `${servicePath} resources[${resourceIndex}]`));
|
|
250
|
+
}
|
|
251
|
+
if (service.resources.length === 2
|
|
252
|
+
&& !(isPlainRecord(service.resources[0]) && service.resources[0].capability === 'database'
|
|
253
|
+
&& isPlainRecord(service.resources[1]) && service.resources[1].capability === 'objectstorage')) {
|
|
254
|
+
errors.push(`${servicePath} resources must hold one database before one objectstorage resource`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return errors;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** Validates Corestore's answer on its legacy inventory path and names every reason it is refused. */
|
|
261
|
+
export const validateCorestoreLegacyResourceInventory = (
|
|
262
|
+
valueArg: unknown,
|
|
263
|
+
pathArg = 'corestore legacy resource inventory',
|
|
264
|
+
): string[] => {
|
|
265
|
+
if (!isPlainRecord(valueArg) || !hasExactKeys(valueArg, ['services'])) {
|
|
266
|
+
return [`${pathArg} must use its exact schema`];
|
|
267
|
+
}
|
|
268
|
+
return validateServices(valueArg.services, `${pathArg} services`);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/** Validates one node's legacy inventory as the relay reports it. Shape only. */
|
|
272
|
+
export const validateClusterCorestoreLegacyResourceInventory = (
|
|
273
|
+
valueArg: unknown,
|
|
274
|
+
pathArg = 'cluster corestore legacy resource inventory',
|
|
275
|
+
): string[] => {
|
|
276
|
+
if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
|
|
277
|
+
const reachable = valueArg.reachable;
|
|
278
|
+
if (reachable === true
|
|
279
|
+
? !hasExactKeys(valueArg, ['nodeId', 'checkedAt', 'reachable', 'services'])
|
|
280
|
+
: reachable !== false || !hasExactKeys(valueArg, ['nodeId', 'checkedAt', 'reachable', 'errorCode'])) {
|
|
281
|
+
return [`${pathArg} must use its exact schema`];
|
|
282
|
+
}
|
|
283
|
+
const errors: string[] = [];
|
|
284
|
+
if (!isClusterNodeId(valueArg.nodeId)) errors.push(`${pathArg} nodeId must be a node id`);
|
|
285
|
+
if (!Number.isSafeInteger(valueArg.checkedAt) || (valueArg.checkedAt as number) < 0) {
|
|
286
|
+
errors.push(`${pathArg} checkedAt must be a non-negative safe integer`);
|
|
287
|
+
}
|
|
288
|
+
if (reachable === true) {
|
|
289
|
+
errors.push(...validateServices(valueArg.services, `${pathArg} services`));
|
|
290
|
+
} else if (valueArg.errorCode !== 'CORESTORE_ENDPOINT_UNKNOWN' && valueArg.errorCode !== 'CORESTORE_UNREACHABLE') {
|
|
291
|
+
errors.push(`${pathArg} errorCode must name why the node could not be read`);
|
|
292
|
+
}
|
|
293
|
+
return errors;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const failDigest = (reasonArg: string): never => {
|
|
297
|
+
throw new Error(reasonArg);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The digest an adoption is checked against: the node and its services, not the read time, so two
|
|
302
|
+
* reads of an unchanged Corestore agree. Throws for an invalid or unreachable inventory.
|
|
303
|
+
*/
|
|
304
|
+
export const computeClusterCorestoreLegacyResourceInventorySha256 = async (
|
|
305
|
+
inventoryArg: TClusterCorestoreLegacyResourceInventory,
|
|
306
|
+
): Promise<string> => {
|
|
307
|
+
const errors = validateClusterCorestoreLegacyResourceInventory(inventoryArg);
|
|
308
|
+
if (errors.length > 0) throw new Error(errors[0]);
|
|
309
|
+
if (inventoryArg.reachable !== true) throw new Error('an unreachable legacy inventory has no digest');
|
|
310
|
+
return createCanonicalJsonSha256Hex(canonicalizeStrictJson({
|
|
311
|
+
domain: corestoreLegacyAdoptionContract.digestDomain,
|
|
312
|
+
nodeId: inventoryArg.nodeId,
|
|
313
|
+
services: inventoryArg.services,
|
|
314
|
+
}, failDigest, 'corestore legacy resource inventory'), failDigest);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const selectionKey = (entryArg: { serviceId: string; capability: string }): string =>
|
|
318
|
+
`${entryArg.serviceId}\u0000${entryArg.capability}`;
|
|
319
|
+
|
|
320
|
+
/** Validates an administrator's selection: 1..4096 exact entries, sorted by service then capability. */
|
|
321
|
+
export const validateCorestoreLegacyResourceSelections = (
|
|
322
|
+
valueArg: unknown,
|
|
323
|
+
pathArg = 'corestore legacy resource selection',
|
|
324
|
+
): string[] => {
|
|
325
|
+
if (!Array.isArray(valueArg) || valueArg.length < 1
|
|
326
|
+
|| valueArg.length > corestoreLegacyAdoptionContract.maximumPlanEntries) {
|
|
327
|
+
return [`${pathArg} must be a non-empty bounded array`];
|
|
328
|
+
}
|
|
329
|
+
const errors: string[] = [];
|
|
330
|
+
let previous: string | undefined;
|
|
331
|
+
for (const [index, entry] of valueArg.entries()) {
|
|
332
|
+
if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability'])
|
|
333
|
+
|| !isIdentifier(entry.serviceId) || !isCapability(entry.capability)) {
|
|
334
|
+
errors.push(`${pathArg}[${index}] must be an exact { serviceId, capability }`);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const key = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
|
|
338
|
+
if (previous !== undefined && compareWireTokens(previous, key) >= 0) {
|
|
339
|
+
errors.push(`${pathArg} must be sorted by serviceId then capability without repeats`);
|
|
340
|
+
}
|
|
341
|
+
previous = key;
|
|
342
|
+
}
|
|
343
|
+
return errors;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Validates an adoption plan by the rules Corestore's migration applies: a non-empty array of at
|
|
348
|
+
* most 4096 exact `{ serviceId, capability, bindingId }` entries, canonical identifiers, and no
|
|
349
|
+
* service capability or binding id twice. Order is free.
|
|
350
|
+
*/
|
|
351
|
+
export const validateCorestoreLegacyResourceAdoptionPlan = (
|
|
352
|
+
valueArg: unknown,
|
|
353
|
+
pathArg = 'adoption plan',
|
|
354
|
+
): string[] => {
|
|
355
|
+
if (!Array.isArray(valueArg) || valueArg.length === 0
|
|
356
|
+
|| valueArg.length > corestoreLegacyAdoptionContract.maximumPlanEntries) {
|
|
357
|
+
return [`${pathArg} must be a non-empty bounded array`];
|
|
358
|
+
}
|
|
359
|
+
const errors: string[] = [];
|
|
360
|
+
const serviceCapabilities = new Set<string>();
|
|
361
|
+
const bindingIds = new Set<string>();
|
|
362
|
+
for (const [index, entry] of valueArg.entries()) {
|
|
363
|
+
if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability', 'bindingId'])
|
|
364
|
+
|| !isIdentifier(entry.serviceId) || !isIdentifier(entry.bindingId) || !isCapability(entry.capability)) {
|
|
365
|
+
errors.push(`${pathArg} entry ${index} must be an exact { serviceId, capability, bindingId }`);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const serviceCapability = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
|
|
369
|
+
if (serviceCapabilities.has(serviceCapability) || bindingIds.has(entry.bindingId as string)) {
|
|
370
|
+
errors.push(`${pathArg} entry ${index} repeats a service capability or binding id`);
|
|
371
|
+
}
|
|
372
|
+
serviceCapabilities.add(serviceCapability);
|
|
373
|
+
bindingIds.add(entry.bindingId as string);
|
|
374
|
+
}
|
|
375
|
+
return errors;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
/** The binding fields an adoption judges; a full `IPlatformBinding` satisfies it. */
|
|
379
|
+
export interface ICorestoreLegacyAdoptionBindingView {
|
|
380
|
+
id: string;
|
|
381
|
+
serviceId: string;
|
|
382
|
+
capability: string;
|
|
383
|
+
objectstorageBucketName?: string;
|
|
384
|
+
objectstorageRetention?: { intent: IObjectStorageRetentionIntent };
|
|
385
|
+
corestoreLegacyAdoption?: { nodeId: string; resourceName: string; inventorySha256: string };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Content check of one adopting binding against the inventory it was adopted at, and the one rule
|
|
390
|
+
* that lets a binding carry a legacy bucket name: the binding names this node, this inventory
|
|
391
|
+
* digest and the legacy resource's name; the resource is unadopted without a blocker or authorized
|
|
392
|
+
* for exactly this binding; an adopted bucket's `objectstorageBucketName` is the legacy bucket and
|
|
393
|
+
* its retention intent the legacy intent exactly, absent when the legacy bucket has none; a
|
|
394
|
+
* database binding carries neither. Whether the digest is current is the caller's to check.
|
|
395
|
+
*/
|
|
396
|
+
export const validatePlatformBindingCorestoreLegacyAdoption = (
|
|
397
|
+
bindingArg: ICorestoreLegacyAdoptionBindingView,
|
|
398
|
+
inventoryArg: TClusterCorestoreLegacyResourceInventory,
|
|
399
|
+
inventorySha256Arg: string,
|
|
400
|
+
pathArg = 'platform binding corestoreLegacyAdoption',
|
|
401
|
+
): string[] => {
|
|
402
|
+
if (validateClusterCorestoreLegacyResourceInventory(inventoryArg).length > 0 || inventoryArg.reachable !== true
|
|
403
|
+
|| typeof inventorySha256Arg !== 'string' || !bareSha256Pattern.test(inventorySha256Arg)) {
|
|
404
|
+
return [`${pathArg} needs a valid reachable inventory and its digest`];
|
|
405
|
+
}
|
|
406
|
+
const adoption = bindingArg.corestoreLegacyAdoption;
|
|
407
|
+
if (!isPlainRecord(adoption) || !hasExactKeys(adoption, ['nodeId', 'resourceName', 'inventorySha256'])) {
|
|
408
|
+
return [`${pathArg} must use its exact schema`];
|
|
409
|
+
}
|
|
410
|
+
if (adoption.nodeId !== inventoryArg.nodeId || adoption.inventorySha256 !== inventorySha256Arg) {
|
|
411
|
+
return [`${pathArg} must name the inventory's node and digest`];
|
|
412
|
+
}
|
|
413
|
+
if (!isCapability(bindingArg.capability)) return [`${pathArg} needs a database or objectstorage binding`];
|
|
414
|
+
const resource = inventoryArg.services.find((serviceArg) => serviceArg.serviceId === bindingArg.serviceId)
|
|
415
|
+
?.resources.find((resourceArg) => resourceArg.capability === bindingArg.capability);
|
|
416
|
+
if (!resource) return [`${pathArg} names no legacy resource of the service and capability`];
|
|
417
|
+
const errors: string[] = [];
|
|
418
|
+
const legacyName = resource.capability === 'database' ? resource.databaseName : resource.bucketName;
|
|
419
|
+
if (adoption.resourceName !== legacyName) errors.push(`${pathArg} resourceName must be the legacy resource's name`);
|
|
420
|
+
if (resource.adoption.state === 'unadopted' ? resource.adoption.blocker !== null
|
|
421
|
+
: resource.adoption.bindingId !== bindingArg.id) {
|
|
422
|
+
errors.push(`${pathArg} names a resource that is blocked or authorized for another binding`);
|
|
423
|
+
}
|
|
424
|
+
if (resource.capability === 'objectstorage') {
|
|
425
|
+
if (bindingArg.objectstorageBucketName !== resource.bucketName) {
|
|
426
|
+
errors.push(`${pathArg} objectstorageBucketName must be the legacy bucket`);
|
|
427
|
+
}
|
|
428
|
+
if (resource.retention === null
|
|
429
|
+
? bindingArg.objectstorageRetention !== undefined
|
|
430
|
+
: !objectStorageRetentionIntentsEqual(bindingArg.objectstorageRetention?.intent, resource.retention)) {
|
|
431
|
+
errors.push(`${pathArg} retention intent must be the legacy bucket's exactly`);
|
|
432
|
+
}
|
|
433
|
+
} else if (bindingArg.objectstorageBucketName !== undefined || bindingArg.objectstorageRetention !== undefined) {
|
|
434
|
+
errors.push(`${pathArg} database binding must carry no bucket or retention`);
|
|
435
|
+
}
|
|
436
|
+
return errors;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* The plan for every adopting binding, sorted by service then capability, in the exact entry shape
|
|
441
|
+
* Corestore's migration reads. Throws unless every binding adopts a legacy resource and the result
|
|
442
|
+
* is a valid plan.
|
|
443
|
+
*/
|
|
444
|
+
export const createCorestoreLegacyResourceAdoptionPlan = (
|
|
445
|
+
bindingsArg: readonly ICorestoreLegacyAdoptionBindingView[],
|
|
446
|
+
): ICorestoreLegacyResourceAdoptionPlanEntry[] => {
|
|
447
|
+
const plan = bindingsArg.map((bindingArg) => {
|
|
448
|
+
if (bindingArg.corestoreLegacyAdoption === undefined || !isCapability(bindingArg.capability)) {
|
|
449
|
+
throw new Error(`binding ${bindingArg.id} adopts no legacy Corestore resource`);
|
|
450
|
+
}
|
|
451
|
+
return { serviceId: bindingArg.serviceId, capability: bindingArg.capability, bindingId: bindingArg.id };
|
|
452
|
+
}).sort((leftArg, rightArg) => compareWireTokens(selectionKey(leftArg), selectionKey(rightArg)));
|
|
453
|
+
const errors = validateCorestoreLegacyResourceAdoptionPlan(plan);
|
|
454
|
+
if (errors.length > 0) throw new Error(errors[0]);
|
|
455
|
+
return plan;
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* The binding status reason a Corestore control answer names: a 409 whose body is
|
|
460
|
+
* `{ ok: false, error, code }` with `code` one of the legacy adoption reasons. Every other answer,
|
|
461
|
+
* including a 409 with another code, names none and keeps its ordinary failure handling.
|
|
462
|
+
*/
|
|
463
|
+
export const readCorestoreLegacyAdoptionRefusal = (
|
|
464
|
+
statusCodeArg: number,
|
|
465
|
+
bodyArg: unknown,
|
|
466
|
+
): TPlatformBindingStatusReason | null => (
|
|
467
|
+
statusCodeArg === 409 && isPlainRecord(bodyArg) && bodyArg.ok === false
|
|
468
|
+
&& (platformBindingStatusReasons as readonly unknown[]).includes(bodyArg.code)
|
|
469
|
+
? bodyArg.code as TPlatformBindingStatusReason
|
|
470
|
+
: null
|
|
471
|
+
);
|
package/ts/data/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './clusteringressdesignation.js';
|
|
|
7
7
|
export * from './clusterrelaycredential.js';
|
|
8
8
|
export * from './config.js';
|
|
9
9
|
export * from './corestore.js';
|
|
10
|
+
export * from './corestorelegacyadoption.js';
|
|
10
11
|
export * from './coremail.js';
|
|
11
12
|
export * from './coremail.runtime.js';
|
|
12
13
|
export * from './deployment.js';
|
|
@@ -67,6 +68,7 @@ export * from './service.js';
|
|
|
67
68
|
export * from './servicecredential.js';
|
|
68
69
|
export * from './serviceports.js';
|
|
69
70
|
export * from './serviceruntime.js';
|
|
71
|
+
export * from './servicevolumeinitialization.js';
|
|
70
72
|
export * from './status.js';
|
|
71
73
|
export * from './taskexecution.js';
|
|
72
74
|
export * from './traffic.js';
|
|
@@ -42,6 +42,18 @@ export interface IReportRuntimeNetworkProtectionRequest {
|
|
|
42
42
|
* Absent from a node that has not stated one; never defaulted, never guessed.
|
|
43
43
|
*/
|
|
44
44
|
uplinkAddress?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Every IPv4 address the node's host carries on interfaces the node does not manage itself, as
|
|
47
|
+
* the node observed them: sorted as strings, unique, never empty when present, at most
|
|
48
|
+
* `runtimeNetworkProtectionContract.maximumHostAddresses`, and each one an address
|
|
49
|
+
* `runtimeNodeUplinkAddress` admits. Workload bridges and the managed VPN interface are the
|
|
50
|
+
* node's own and are left out.
|
|
51
|
+
*
|
|
52
|
+
* Cloudly names a platform endpoint in the node's `hostPlatformEndpointIds` when its address is
|
|
53
|
+
* one of these, which is how a host without a relay registration (a Corestore beside the node on
|
|
54
|
+
* one machine) states that an endpoint is local. Absent states nothing; never defaulted.
|
|
55
|
+
*/
|
|
56
|
+
hostAddresses?: string[];
|
|
45
57
|
}
|
|
46
58
|
export interface IReportRuntimeNetworkProtectionResponse {
|
|
47
59
|
status: 'accepted' | 'replay';
|
|
@@ -57,6 +69,7 @@ export const runtimeNetworkProtectionContract = Object.freeze({
|
|
|
57
69
|
unavailable: 'null-native-barrier-removes-allocation-eligibility',
|
|
58
70
|
historical: 'retain-for-outbox-replay-never-current-allocation-eligibility',
|
|
59
71
|
quarantine: 'no-release-authority',
|
|
72
|
+
maximumHostAddresses: 32,
|
|
60
73
|
} as const);
|
|
61
74
|
|
|
62
75
|
const scopeOf = (value: IRuntimeNetworkNodeScope): IRuntimeNetworkNodeScope =>
|
|
@@ -123,7 +136,7 @@ export const admitRuntimeNetworkProtectionReceipt = async (
|
|
|
123
136
|
};
|
|
124
137
|
|
|
125
138
|
export const snapshotReportRuntimeNetworkProtectionRequest = (value: unknown): IReportRuntimeNetworkProtectionRequest => networkSafe(() => {
|
|
126
|
-
const item = networkRecord(captureNetwork(value), ['session', 'receipt'], ['uplinkAddress']);
|
|
139
|
+
const item = networkRecord(captureNetwork(value), ['session', 'receipt'], ['uplinkAddress', 'hostAddresses']);
|
|
127
140
|
const request: IReportRuntimeNetworkProtectionRequest = {
|
|
128
141
|
session: snapshotRuntimeSessionBinding(item.session),
|
|
129
142
|
receipt: snapshotRuntimeNetworkProtectionReceipt(item.receipt),
|
|
@@ -131,6 +144,12 @@ export const snapshotReportRuntimeNetworkProtectionRequest = (value: unknown): I
|
|
|
131
144
|
if (Object.hasOwn(item, 'uplinkAddress')) {
|
|
132
145
|
request.uplinkAddress = runtimeNodeUplinkAddress(item.uplinkAddress);
|
|
133
146
|
}
|
|
147
|
+
if (Object.hasOwn(item, 'hostAddresses')) {
|
|
148
|
+
const hostAddresses = networkSorted(networkList(item.hostAddresses,
|
|
149
|
+
runtimeNetworkProtectionContract.maximumHostAddresses, runtimeNodeUplinkAddress), (address) => address);
|
|
150
|
+
requireNetwork(hostAddresses.length > 0);
|
|
151
|
+
request.hostAddresses = hostAddresses;
|
|
152
|
+
}
|
|
134
153
|
return request;
|
|
135
154
|
});
|
|
136
155
|
|
package/ts/data/service.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
IServiceSecretConfiguration,
|
|
18
18
|
IServiceSecretDeploymentPlan,
|
|
19
19
|
} from './secret.js';
|
|
20
|
+
import type { TServiceVolumeInitialization } from './servicevolumeinitialization.js';
|
|
20
21
|
|
|
21
22
|
export interface IServiceVolume {
|
|
22
23
|
/** Stable Docker volume name. If omitted, Coreflow derives one from service id and mount path. */
|
|
@@ -32,8 +33,17 @@ export interface IServiceVolume {
|
|
|
32
33
|
backup?: boolean;
|
|
33
34
|
/** Driver-specific options forwarded to Docker's VolumeDriver.Create request. */
|
|
34
35
|
options?: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Server-managed: how the volume's node-local storage claim starts on a Pallet cluster. Only
|
|
38
|
+
* `setServiceVolumeInitialization` writes it; a volume without one is refused as
|
|
39
|
+
* `volume-initialization-unknown` instead of being created empty.
|
|
40
|
+
*/
|
|
41
|
+
initialization?: TServiceVolumeInitialization;
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
/** Caller-writable volume declaration. Its initialization has its own fenced request. */
|
|
45
|
+
export type TServiceWritableVolume = Omit<IServiceVolume, 'initialization'>;
|
|
46
|
+
|
|
37
47
|
const organizationIdRegex = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
|
|
38
48
|
|
|
39
49
|
/** Validates the canonical organization authority used by service operations. */
|
|
@@ -255,12 +265,18 @@ export type TServiceWritableData = Omit<
|
|
|
255
265
|
| 'secretConfiguration'
|
|
256
266
|
| 'secretDeployment'
|
|
257
267
|
| 'mail'
|
|
268
|
+
| 'volumes'
|
|
258
269
|
> & {
|
|
259
270
|
/**
|
|
260
271
|
* Mail configuration stays caller-writable, except for the CoreMail binding
|
|
261
272
|
* metadata Cloudly derives from reconciliation.
|
|
262
273
|
*/
|
|
263
274
|
mail?: TServiceMailWritableConfig;
|
|
275
|
+
/**
|
|
276
|
+
* Volumes stay caller-writable, except for their initialization, which Cloudly refuses here.
|
|
277
|
+
* A stored initialization stays with the volume of the same mount path and goes with it.
|
|
278
|
+
*/
|
|
279
|
+
volumes?: TServiceWritableVolume[];
|
|
264
280
|
};
|
|
265
281
|
|
|
266
282
|
/** Caller-writable update data. Null explicitly removes an existing argument vector. */
|
|
@@ -78,6 +78,7 @@ export const serviceRuntimeContract = Object.freeze({
|
|
|
78
78
|
|
|
79
79
|
const serviceRuntimeWaitingReasons = [
|
|
80
80
|
'node-network-pending', 'conflict', 'failure-backoff', 'storage-import-pending', 'bindings-pending',
|
|
81
|
+
'legacy-adoption-pending',
|
|
81
82
|
] as const;
|
|
82
83
|
const serviceRuntimeRefusals = [
|
|
83
84
|
'cluster-runtime-missing', 'organization-missing', 'image-plan-missing', 'platform-unsupported',
|
|
@@ -86,7 +87,7 @@ const serviceRuntimeRefusals = [
|
|
|
86
87
|
'node-authority-unsupported', 'network-policy-missing', 'network-policy-mismatch',
|
|
87
88
|
'network-workload-pool-missing', 'network-workload-pool-exhausted',
|
|
88
89
|
'volume-driver-unsupported', 'volume-options-unsupported', 'volume-shared-unsupported',
|
|
89
|
-
'volume-placement-unsupported',
|
|
90
|
+
'volume-placement-unsupported', 'volume-initialization-unknown', 'volume-ownership-unknown',
|
|
90
91
|
] as const;
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -94,7 +95,9 @@ const serviceRuntimeRefusals = [
|
|
|
94
95
|
* `node-network-pending` waits for a node's network readiness, `conflict` for a sweep over inputs
|
|
95
96
|
* that changed while it ran, `failure-backoff` for a failed replica's backoff to elapse,
|
|
96
97
|
* `storage-import-pending` for an `import` local storage claim whose bytes have not arrived on its
|
|
97
|
-
* node,
|
|
98
|
+
* node, `bindings-pending` for the secret manifest to cover every enabled binding of the service, and
|
|
99
|
+
* `legacy-adoption-pending` for a Corestore binding whose legacy resource waits for the offline
|
|
100
|
+
* adoption Corestore requires (the binding's `statusReason` of the same name).
|
|
98
101
|
*/
|
|
99
102
|
export type TServiceRuntimeWaitingReason = typeof serviceRuntimeWaitingReasons[number];
|
|
100
103
|
|
|
@@ -112,6 +115,9 @@ export type TServiceRuntimeWaitingReason = typeof serviceRuntimeWaitingReasons[n
|
|
|
112
115
|
* a volume of a driver other than a node-local directory, `volume-options-unsupported` driver or
|
|
113
116
|
* mount options, `volume-shared-unsupported` one volume mounted by more than one replica or service,
|
|
114
117
|
* and `volume-placement-unsupported` a placement that does not pin each volume to one node.
|
|
118
|
+
* `volume-initialization-unknown` is a volume without an initialization and
|
|
119
|
+
* `volume-ownership-unknown` a `run-as` ownership under `runAs: null`
|
|
120
|
+
* (`deriveServiceVolumeClaimInitialization`); neither is defaulted.
|
|
115
121
|
*/
|
|
116
122
|
export type TServiceRuntimeRefusal = typeof serviceRuntimeRefusals[number];
|
|
117
123
|
|