@geek-fun/serverlessinsight 0.8.9 → 0.9.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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +123 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +93 -0
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +148 -0
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/CHANGELOG.md +29 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/deploy.js +3 -1
- package/dist/src/commands/index.js +25 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +5 -0
- package/dist/src/common/nameBuilder.js +13 -1
- package/dist/src/common/planCompare.js +31 -1
- package/dist/src/common/planFormatter.js +69 -54
- package/dist/src/common/refreshPlanner.js +31 -8
- package/dist/src/lang/en.js +20 -6
- package/dist/src/lang/zh-CN.js +20 -6
- package/dist/src/stack/aliyunStack/apigwPlanner.js +26 -5
- package/dist/src/stack/aliyunStack/databasePlanner.js +6 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +10 -2
- package/dist/src/stack/aliyunStack/deployer.js +30 -13
- package/dist/src/stack/aliyunStack/fc3Planner.js +46 -25
- package/dist/src/stack/aliyunStack/fc3Resource.js +49 -20
- package/dist/src/stack/aliyunStack/ossPlanner.js +6 -1
- package/dist/src/stack/aliyunStack/ossResource.js +9 -2
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +2 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +2 -1
- package/dist/src/stack/deploy.js +10 -4
- package/dist/src/stack/scfStack/cosPlanner.js +6 -1
- package/dist/src/stack/scfStack/cosResource.js +6 -2
- package/dist/src/stack/scfStack/deployer.js +21 -6
- package/dist/src/stack/scfStack/esServerlessPlanner.js +6 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +5 -1
- package/dist/src/stack/scfStack/scfPlanner.js +26 -27
- package/dist/src/stack/scfStack/scfResource.js +6 -2
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +6 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +5 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +5 -1
- package/dist/src/stack/volcengineStack/deployer.js +15 -4
- package/dist/src/stack/volcengineStack/tosPlanner.js +6 -1
- package/dist/src/stack/volcengineStack/tosResource.js +10 -3
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +39 -11
- package/dist/src/stack/volcengineStack/vefaasResource.js +5 -1
- package/dist/src/validator/semanticValidation.js +24 -0
- package/package.json +1 -1
|
@@ -124,19 +124,21 @@ const parseRolePolicyDocument = (raw) => {
|
|
|
124
124
|
* - logConfig must be derivable from state: with logging on but no recorded
|
|
125
125
|
* logstore instance the executor creates one during update and derives the
|
|
126
126
|
* grant from that new logstore, which the planner cannot know → skip.
|
|
127
|
+
* Returns an i18n drift-reason key (issue #246) instead of a boolean so the
|
|
128
|
+
* plan can say WHICH dimension drifted; null means no drift.
|
|
127
129
|
*/
|
|
128
130
|
const detectRolePolicyDrift = async (context, state, fn, currentState, roleName, cloudRole) => {
|
|
129
131
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
130
132
|
const logicalId = `functions.${fn.key}`;
|
|
131
133
|
const iamRole = fn.iam?.role;
|
|
132
134
|
if (!iamRole || typeof iamRole === 'string') {
|
|
133
|
-
return
|
|
135
|
+
return null;
|
|
134
136
|
}
|
|
135
137
|
const roleInstance = currentState.instances?.find((i) => i.type === 'ALIYUN_RAM_ROLE' &&
|
|
136
138
|
i.id === roleName &&
|
|
137
139
|
!i.external);
|
|
138
140
|
if (!roleInstance) {
|
|
139
|
-
return
|
|
141
|
+
return null;
|
|
140
142
|
}
|
|
141
143
|
// Conservative ownership scan (mirrors collectRolePeers semantics without
|
|
142
144
|
// requiring context.iac): any OTHER function in state recording the same
|
|
@@ -147,13 +149,13 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
147
149
|
i.id === roleName &&
|
|
148
150
|
!i.external));
|
|
149
151
|
if (sharedRole) {
|
|
150
|
-
return
|
|
152
|
+
return null;
|
|
151
153
|
}
|
|
152
154
|
let logConfig;
|
|
153
155
|
if (fn.log) {
|
|
154
156
|
const logstoreInstance = currentState.instances?.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
155
157
|
if (!logstoreInstance?.id) {
|
|
156
|
-
return
|
|
158
|
+
return null;
|
|
157
159
|
}
|
|
158
160
|
const [project, logstore] = logstoreInstance.id.split('/');
|
|
159
161
|
logConfig = { project, logstore };
|
|
@@ -172,7 +174,7 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
172
174
|
],
|
|
173
175
|
};
|
|
174
176
|
if (cloudTrust && !(0, common_1.attributesEqual)(cloudTrust, desiredTrust)) {
|
|
175
|
-
return
|
|
177
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
176
178
|
}
|
|
177
179
|
// b. execution + custom policy (the `<roleName>-policy` custom document). An
|
|
178
180
|
// absent/unreadable cloud document is drift: the executor recreates it on
|
|
@@ -183,7 +185,7 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
183
185
|
if (!cloudPolicy ||
|
|
184
186
|
!desiredPolicyDocument ||
|
|
185
187
|
!(0, common_1.attributesEqual)(cloudPolicy, desiredPolicyDocument)) {
|
|
186
|
-
return
|
|
188
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
187
189
|
}
|
|
188
190
|
// c. managed (system) policies as sorted name sets; desired ARNs strip the
|
|
189
191
|
// `acs:ram::<uid>:policy/` prefix.
|
|
@@ -191,15 +193,16 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
191
193
|
const cloudManagedNames = await (0, refreshCache_1.cachedRefreshRead)(context, `ram.listAttachedRolePolicies:${roleName}`, () => client.ram.listAttachedRolePolicies(roleName));
|
|
192
194
|
const asSortedSetKey = (names) => [...names].sort().join(',');
|
|
193
195
|
if (asSortedSetKey(desiredManagedNames) !== asSortedSetKey(cloudManagedNames ?? [])) {
|
|
194
|
-
return
|
|
196
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
195
197
|
}
|
|
196
|
-
return
|
|
198
|
+
return null;
|
|
197
199
|
};
|
|
198
200
|
/**
|
|
199
201
|
* Issue #234 M1: nested log-drift probe — logstore ttl/shards and index
|
|
200
202
|
* presence for functions that declare logging. The logstore is per-function
|
|
201
203
|
* (buildFunctionLogstoreName), so this lives in the function flow. Aliyun
|
|
202
204
|
* cannot shrink shards, so only a shard deficit counts as drift.
|
|
205
|
+
* Returns an i18n drift-reason key (issue #246); null means no drift.
|
|
203
206
|
*/
|
|
204
207
|
const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
205
208
|
// Each declared dimension contributes its own probe; undeclared dimensions
|
|
@@ -211,18 +214,18 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
211
214
|
if (projectName && logstoreName) {
|
|
212
215
|
const logstore = await (0, refreshCache_1.cachedRefreshRead)(context, `sls.getLogstore:${projectName}:${logstoreName}`, () => client.sls.getLogstore(projectName, logstoreName));
|
|
213
216
|
if (!logstore) {
|
|
214
|
-
return
|
|
217
|
+
return 'PLAN_DRIFT_LOGSTORE'; // logstore deleted out-of-band
|
|
215
218
|
}
|
|
216
219
|
if (logstore.ttl !== slsOperations_1.SLS_LOGSTORE_TTL) {
|
|
217
|
-
return
|
|
220
|
+
return 'PLAN_DRIFT_LOGSTORE';
|
|
218
221
|
}
|
|
219
222
|
// Aliyun cannot shrink shards — only a deficit counts as drift.
|
|
220
223
|
if ((logstore.shardCount ?? 0) < slsOperations_1.SLS_LOGSTORE_SHARDS) {
|
|
221
|
-
return
|
|
224
|
+
return 'PLAN_DRIFT_LOGSTORE';
|
|
222
225
|
}
|
|
223
226
|
const index = await (0, refreshCache_1.cachedRefreshRead)(context, `sls.getIndex:${projectName}:${logstoreName}`, () => client.sls.getIndex(projectName, logstoreName));
|
|
224
227
|
if (!index) {
|
|
225
|
-
return
|
|
228
|
+
return 'PLAN_DRIFT_LOGSTORE'; // index deleted out-of-band
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
}
|
|
@@ -256,7 +259,7 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
256
259
|
liveIngress.some((l) => !desired.ingress.includes(l)) ||
|
|
257
260
|
desired.egress.some((d) => !liveEgress.includes(d)) ||
|
|
258
261
|
liveEgress.some((l) => !desired.egress.includes(l))) {
|
|
259
|
-
return
|
|
262
|
+
return 'PLAN_DRIFT_SG_RULES';
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
}
|
|
@@ -271,11 +274,11 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
271
274
|
}
|
|
272
275
|
const targets = await (0, refreshCache_1.cachedRefreshRead)(context, `nas.listMountTargets:${fsId}`, () => client.nas.listMountTargets(fsId));
|
|
273
276
|
if (!targets || targets.length === 0) {
|
|
274
|
-
return
|
|
277
|
+
return 'PLAN_DRIFT_NAS_MOUNT'; // mount target deleted out-of-band
|
|
275
278
|
}
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
|
-
return
|
|
281
|
+
return null;
|
|
279
282
|
};
|
|
280
283
|
const generateFunctionPlan = async (context, state, functions) => {
|
|
281
284
|
if (!functions || functions.length === 0) {
|
|
@@ -302,7 +305,11 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
302
305
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
303
306
|
const remoteFunction = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.getFunction:${fn.name}`, () => client.fc3.getFunction(fn.name));
|
|
304
307
|
if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.tags)) {
|
|
305
|
-
throw new Error(
|
|
308
|
+
throw new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
309
|
+
resourceType: 'Function',
|
|
310
|
+
resourceName: fn.name,
|
|
311
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
312
|
+
}));
|
|
306
313
|
}
|
|
307
314
|
return {
|
|
308
315
|
logicalId,
|
|
@@ -346,15 +353,21 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
346
353
|
// (memory/timeout/env/...). One-directional: only mapper-emitted keys
|
|
347
354
|
// the desired definition declares are compared, so cloud-only extras
|
|
348
355
|
// the config never asked for are ignored (desired-declared contract).
|
|
356
|
+
// Issue #246: the diff baseline is cloud reality — live attributes
|
|
357
|
+
// merged over the stored definition — and revertKeys marks the fields
|
|
358
|
+
// whose difference is purely an out-of-config cloud edit.
|
|
349
359
|
const remoteAttributes = (0, fc3Types_1.cloudFc3ToDefinition)(remoteFunction);
|
|
350
360
|
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(remoteAttributes, desiredDefinition);
|
|
361
|
+
const liveBefore = normalizeDefinitionForComparison((0, planCompare_1.mergeLiveBefore)(currentState.definition || {}, remoteAttributes));
|
|
362
|
+
const revertKeys = (0, planCompare_1.computeRevertKeys)(normalizedCurrent, normalizeDefinitionForComparison(remoteAttributes), normalizedDesired);
|
|
351
363
|
if (definitionChanged || remoteDiffers) {
|
|
352
364
|
return {
|
|
353
365
|
logicalId,
|
|
354
366
|
action: 'update',
|
|
355
367
|
resourceType: 'ALIYUN_FC3',
|
|
356
|
-
changes: { before:
|
|
368
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
357
369
|
drifted: true,
|
|
370
|
+
...(revertKeys.length ? { revertKeys } : {}),
|
|
358
371
|
};
|
|
359
372
|
}
|
|
360
373
|
const roleProbe = resolveManagedRoleProbe(context, fn, currentState);
|
|
@@ -370,18 +383,20 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
370
383
|
logicalId,
|
|
371
384
|
action: 'update',
|
|
372
385
|
resourceType: 'ALIYUN_FC3',
|
|
373
|
-
changes: { before:
|
|
386
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
374
387
|
drifted: true,
|
|
388
|
+
driftReasons: ['PLAN_DRIFT_ROLE_MISSING'],
|
|
375
389
|
};
|
|
376
390
|
}
|
|
377
|
-
const
|
|
378
|
-
if (
|
|
391
|
+
const roleDriftReason = await detectRolePolicyDrift(context, state, fn, currentState, roleProbe.roleName, cloudRole);
|
|
392
|
+
if (roleDriftReason) {
|
|
379
393
|
return {
|
|
380
394
|
logicalId,
|
|
381
395
|
action: 'update',
|
|
382
396
|
resourceType: 'ALIYUN_FC3',
|
|
383
|
-
changes: { before:
|
|
397
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
384
398
|
drifted: true,
|
|
399
|
+
driftReasons: [roleDriftReason],
|
|
385
400
|
};
|
|
386
401
|
}
|
|
387
402
|
}
|
|
@@ -396,14 +411,15 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
396
411
|
// Issue #234 M1/M2: nested drift probe — the probe itself skips
|
|
397
412
|
// dimensions the config does not declare.
|
|
398
413
|
try {
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
414
|
+
const nestedDriftReason = await detectFunctionNestedDrift(context, client, fn, currentState);
|
|
415
|
+
if (nestedDriftReason) {
|
|
401
416
|
return {
|
|
402
417
|
logicalId,
|
|
403
418
|
action: 'update',
|
|
404
419
|
resourceType: 'ALIYUN_FC3',
|
|
405
|
-
changes: { before:
|
|
420
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
406
421
|
drifted: true,
|
|
422
|
+
driftReasons: [nestedDriftReason],
|
|
407
423
|
};
|
|
408
424
|
}
|
|
409
425
|
}
|
|
@@ -415,7 +431,11 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
415
431
|
}
|
|
416
432
|
return { logicalId, action: 'noop', resourceType: 'ALIYUN_FC3' };
|
|
417
433
|
}
|
|
418
|
-
catch {
|
|
434
|
+
catch (error) {
|
|
435
|
+
common_1.logger.warn(lang_1.lang.__('PLAN_LIVE_READ_FAILED', {
|
|
436
|
+
logicalId,
|
|
437
|
+
error: error instanceof Error ? error.message : String(error),
|
|
438
|
+
}));
|
|
419
439
|
return {
|
|
420
440
|
logicalId,
|
|
421
441
|
action: 'create',
|
|
@@ -424,6 +444,7 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
424
444
|
before: normalizeDefinitionForComparison(currentState.definition),
|
|
425
445
|
after: normalizeDefinitionForComparison(desiredDefinition),
|
|
426
446
|
},
|
|
447
|
+
drifted: true,
|
|
427
448
|
};
|
|
428
449
|
}
|
|
429
450
|
});
|
|
@@ -449,8 +449,7 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
449
449
|
else {
|
|
450
450
|
const mountPoints = [];
|
|
451
451
|
for (const nasItem of fn.storage.nas) {
|
|
452
|
-
const
|
|
453
|
-
const accessGroupName = `${fn.name}-${context.stage}-nas-access-${mountPath}`;
|
|
452
|
+
const accessGroupName = (0, common_1.buildNasAccessGroupName)(fn.name, context.stage, nasItem.mount_path);
|
|
454
453
|
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_ACCESS_GROUP', { accessGroupName }));
|
|
455
454
|
const accessGroup = await client.nas.createAccessGroup(accessGroupName);
|
|
456
455
|
logger_1.logger.info(lang_1.lang.__('CREATING_NAS_ACCESS_RULE', { accessGroupName }));
|
|
@@ -611,8 +610,10 @@ const createResource = async (context, fn, state) => {
|
|
|
611
610
|
},
|
|
612
611
|
};
|
|
613
612
|
}
|
|
614
|
-
|
|
615
|
-
|
|
613
|
+
// Container-only functions have no code block — mirror the planner's null
|
|
614
|
+
// codeHash (PR #237); the image lives in customContainerConfig, no zip push.
|
|
615
|
+
const codePath = fn.code?.path;
|
|
616
|
+
const codeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
|
|
616
617
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
617
618
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
618
619
|
const dependentInstances = dependentResources.instances.map((dep) => ({
|
|
@@ -637,11 +638,13 @@ const createResource = async (context, fn, state) => {
|
|
|
637
638
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
638
639
|
const existingFunctionOnRetry = isTainted ? await client.fc3.getFunction(fn.name) : null;
|
|
639
640
|
if (existingFunctionOnRetry) {
|
|
640
|
-
logger_1.logger.info(
|
|
641
|
+
logger_1.logger.info(lang_1.lang.__('TAINTED_RECOVERY_SKIP_CREATE', { resourceType: 'Function', resourceName: fn.name }));
|
|
641
642
|
}
|
|
642
643
|
try {
|
|
643
644
|
if (!existingFunctionOnRetry) {
|
|
644
|
-
const ossCode =
|
|
645
|
+
const ossCode = codePath
|
|
646
|
+
? await ensureOssCodeUpload(client, codePath, context.region, fn.name)
|
|
647
|
+
: undefined;
|
|
645
648
|
await client.fc3.createFunction(config, codePath, ossCode);
|
|
646
649
|
}
|
|
647
650
|
}
|
|
@@ -681,7 +684,11 @@ const createResource = async (context, fn, state) => {
|
|
|
681
684
|
logger_1.logger.info(`Function ${fn.name} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
682
685
|
}
|
|
683
686
|
else {
|
|
684
|
-
throw new types_1.PartialResourceError(stateAfterDependents, new Error(
|
|
687
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
688
|
+
resourceType: 'Function',
|
|
689
|
+
resourceName: fn.name,
|
|
690
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
691
|
+
})));
|
|
685
692
|
}
|
|
686
693
|
}
|
|
687
694
|
else {
|
|
@@ -761,6 +768,17 @@ const readResource = async (context, functionName) => {
|
|
|
761
768
|
return await client.fc3.getFunction(functionName);
|
|
762
769
|
};
|
|
763
770
|
exports.readResource = readResource;
|
|
771
|
+
/** Rewrite mount-target instance ids recorded before the M4 repair recreated
|
|
772
|
+
* their targets, so the returned state (and later destroy) tracks the live
|
|
773
|
+
* domains. */
|
|
774
|
+
const withRecreatedMountTargets = (instances, recreated) => instances.map((instance) => {
|
|
775
|
+
if (instance.type !== 'ALIYUN_NAS_MOUNT_TARGET') {
|
|
776
|
+
return instance;
|
|
777
|
+
}
|
|
778
|
+
const fileSystemId = instance.id.split('/')[0];
|
|
779
|
+
const liveDomain = recreated[fileSystemId];
|
|
780
|
+
return liveDomain ? { ...instance, id: `${fileSystemId}/${liveDomain}` } : instance;
|
|
781
|
+
});
|
|
764
782
|
const updateResource = async (context, fn, state, options) => {
|
|
765
783
|
const ctx = (0, common_1.getContext)();
|
|
766
784
|
const serviceName = `${ctx.app}-${ctx.service}`;
|
|
@@ -779,6 +797,10 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
779
797
|
let role;
|
|
780
798
|
let securityGroup;
|
|
781
799
|
let nasConfig;
|
|
800
|
+
// File system id -> live mount target domain, captured by the M4 nested
|
|
801
|
+
// repair below; applied to the function config and the returned state so
|
|
802
|
+
// both track the target that actually exists after recreation.
|
|
803
|
+
const recreatedMountTargets = {};
|
|
782
804
|
// SLS dependent-instance types to drop from the resulting state when
|
|
783
805
|
// function logging is disabled (true -> false).
|
|
784
806
|
const droppedSlsDependentTypes = [];
|
|
@@ -1026,9 +1048,10 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1026
1048
|
failingFsId = fsEntry.id;
|
|
1027
1049
|
const liveTargets = await client.nas.listMountTargets(fsEntry.id);
|
|
1028
1050
|
if (!liveTargets || liveTargets.length === 0) {
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1051
|
+
const mountTarget = await client.nas.createMountTarget(fsEntry.id, (0, common_1.buildNasAccessGroupName)(fn.name, context.stage, nasStorageItems[0]?.mount_path ?? '/mnt/nas'), fn.network.vpc_id, fn.network.subnet_ids[0]);
|
|
1052
|
+
if (mountTarget?.mountTargetDomain) {
|
|
1053
|
+
recreatedMountTargets[fsEntry.id] = mountTarget.mountTargetDomain;
|
|
1054
|
+
}
|
|
1032
1055
|
logger_1.logger.warn(lang_1.lang.__('NESTED_MOUNT_TARGET_RECREATED', { fileSystemId: fsEntry.id }));
|
|
1033
1056
|
}
|
|
1034
1057
|
}
|
|
@@ -1039,10 +1062,16 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1039
1062
|
}
|
|
1040
1063
|
if (mountTargetInstances.length > 0 && nasStorageItems.length > 0) {
|
|
1041
1064
|
nasConfig = {
|
|
1042
|
-
mountPoints: mountTargetInstances.map((mt, idx) =>
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1065
|
+
mountPoints: mountTargetInstances.map((mt, idx) => {
|
|
1066
|
+
const [fileSystemId, recordedDomain] = mt.id.split('/');
|
|
1067
|
+
// Mount the target that now exists — a just-recreated domain replaces
|
|
1068
|
+
// the stale one recorded in state.
|
|
1069
|
+
const liveDomain = recreatedMountTargets[fileSystemId] ?? recordedDomain;
|
|
1070
|
+
return {
|
|
1071
|
+
serverAddr: `${liveDomain}:/`,
|
|
1072
|
+
mountDir: nasStorageItems[idx]?.mount_path ?? '/mnt/nas',
|
|
1073
|
+
};
|
|
1074
|
+
}),
|
|
1046
1075
|
};
|
|
1047
1076
|
}
|
|
1048
1077
|
}
|
|
@@ -1084,10 +1113,10 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1084
1113
|
},
|
|
1085
1114
|
};
|
|
1086
1115
|
}
|
|
1087
|
-
const codePath = fn.code
|
|
1116
|
+
const codePath = fn.code?.path;
|
|
1088
1117
|
const currentCodeHash = existingState?.definition?.codeHash;
|
|
1089
|
-
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
1090
|
-
const codeChanged = currentCodeHash !== desiredCodeHash;
|
|
1118
|
+
const desiredCodeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
|
|
1119
|
+
const codeChanged = codePath ? currentCodeHash !== desiredCodeHash : false;
|
|
1091
1120
|
const existingConfig = existingState?.definition;
|
|
1092
1121
|
const desiredDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
|
|
1093
1122
|
const { codeHash: _existingCodeHash, iam: _existingIam, ...existingConfigOnly } = existingConfig || {};
|
|
@@ -1099,7 +1128,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1099
1128
|
if (configChanged || roleBindingChanged || options?.force) {
|
|
1100
1129
|
await client.fc3.updateFunctionConfiguration(config);
|
|
1101
1130
|
}
|
|
1102
|
-
if (codeChanged) {
|
|
1131
|
+
if (codeChanged && codePath) {
|
|
1103
1132
|
const ossCode = await ensureOssCodeUpload(client, codePath, context.region, fn.name);
|
|
1104
1133
|
await client.fc3.updateFunctionCode(fn.name, codePath, ossCode);
|
|
1105
1134
|
}
|
|
@@ -1245,7 +1274,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1245
1274
|
if (!functionInfo) {
|
|
1246
1275
|
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
1247
1276
|
}
|
|
1248
|
-
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
1277
|
+
const codeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
|
|
1249
1278
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
1250
1279
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
1251
1280
|
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
@@ -1300,7 +1329,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
1300
1329
|
instances: [
|
|
1301
1330
|
fcInstance,
|
|
1302
1331
|
...lifecycleInstances,
|
|
1303
|
-
...existingDependentInstances,
|
|
1332
|
+
...withRecreatedMountTargets(existingDependentInstances, recreatedMountTargets),
|
|
1304
1333
|
...newDependentInstancesMapped,
|
|
1305
1334
|
],
|
|
1306
1335
|
lastUpdated: new Date().toISOString(),
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateBucketPlan = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const lang_1 = require("../../lang");
|
|
8
9
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
9
10
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
10
11
|
const concurrency_1 = require("../../common/concurrency");
|
|
@@ -60,7 +61,11 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
60
61
|
desiredDefinition,
|
|
61
62
|
read: () => (0, refreshCache_1.cachedRefreshRead)(context, `oss.getBucket:${bucket.name}`, () => client.oss.getBucket(bucket.name)),
|
|
62
63
|
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTags(remote.tags)),
|
|
63
|
-
foreignError: () => new Error(
|
|
64
|
+
foreignError: () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
65
|
+
resourceType: 'Bucket',
|
|
66
|
+
resourceName: bucket.name,
|
|
67
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
68
|
+
})),
|
|
64
69
|
cloudToDefinition: ossTypes_1.cloudOssToDefinition,
|
|
65
70
|
normalizeForDisplay: normalizeDefinitionForDisplay,
|
|
66
71
|
extraUpdate: () => Promise.resolve({ update: domainBindingPending, drifted: false }),
|
|
@@ -195,7 +195,10 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
195
195
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
196
196
|
let existingBucketOnRetry = isTainted ? await client.oss.getBucket(config.bucketName) : null;
|
|
197
197
|
if (existingBucketOnRetry) {
|
|
198
|
-
logger_1.logger.info(
|
|
198
|
+
logger_1.logger.info(lang_1.lang.__('TAINTED_RECOVERY_SKIP_CREATE', {
|
|
199
|
+
resourceType: 'Bucket',
|
|
200
|
+
resourceName: config.bucketName,
|
|
201
|
+
}));
|
|
199
202
|
}
|
|
200
203
|
const instances = existingBucketOnRetry
|
|
201
204
|
? [buildOssInstanceFromProvider(existingBucketOnRetry, sid)]
|
|
@@ -216,7 +219,11 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
216
219
|
const isCdnEnabled = getIsCdnEnabled(bucket);
|
|
217
220
|
const isAccelerateEnabled = getIsAccelerateEnabled(bucket);
|
|
218
221
|
let cnameInfo;
|
|
219
|
-
const refuseAdoptionError = () => new Error(
|
|
222
|
+
const refuseAdoptionError = () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
223
|
+
resourceType: 'Bucket',
|
|
224
|
+
resourceName: config.bucketName,
|
|
225
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
226
|
+
}));
|
|
220
227
|
try {
|
|
221
228
|
if (!existingBucketOnRetry) {
|
|
222
229
|
try {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTablePlan = void 0;
|
|
4
|
+
const lang_1 = require("../../lang");
|
|
4
5
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
6
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
7
|
const concurrency_1 = require("../../common/concurrency");
|
|
@@ -38,7 +39,7 @@ const generateTablePlan = async (context, state, tables) => {
|
|
|
38
39
|
// TableStore has no table-level tags: an existing same-named table can
|
|
39
40
|
// never be verified as ours, so it is always refused on the probe path.
|
|
40
41
|
isOwned: () => false,
|
|
41
|
-
foreignError: () => new Error(
|
|
42
|
+
foreignError: () => new Error(lang_1.lang.__('TABLESTORE_EXISTS_UNVERIFIABLE_PROBE', { tableName: config.tableName })),
|
|
42
43
|
cloudToDefinition: tablestoreTypes_1.cloudTableStoreToDefinition,
|
|
43
44
|
refresh: context.refresh,
|
|
44
45
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteTableResource = exports.updateTableResource = exports.readTableResource = exports.createTableResource = void 0;
|
|
4
4
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
5
6
|
const common_1 = require("../../common");
|
|
6
7
|
const types_1 = require("../../types");
|
|
7
8
|
const tablestoreTypes_1 = require("./tablestoreTypes");
|
|
@@ -99,7 +100,7 @@ const createTableResource = async (context, table, state) => {
|
|
|
99
100
|
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['OTSObjectAlreadyExist', 'OTSInstanceAlreadyExist'])) {
|
|
100
101
|
const existingTable = await tablestoreClient.getTable(config.tableName);
|
|
101
102
|
if (existingTable) {
|
|
102
|
-
throw new types_1.PartialResourceError(stateAfterDependents, new Error(
|
|
103
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('TABLESTORE_EXISTS_UNVERIFIABLE', { tableName: config.tableName })));
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
package/dist/src/stack/deploy.js
CHANGED
|
@@ -10,18 +10,24 @@ const deployHuawei = async () => {
|
|
|
10
10
|
'The provider currently generates HCL templates but does not deploy them. ' +
|
|
11
11
|
'Please use Aliyun or Tencent providers, or contribute Huawei deployment support.');
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* `plan` (issue #246): the exact plan shown to the user for approval is the
|
|
15
|
+
* plan executed — deployers partition its items by resourceType instead of
|
|
16
|
+
* re-probing the cloud and re-deciding. Omit it to fall back to per-provider
|
|
17
|
+
* plan generation (legacy path kept for direct deployer callers).
|
|
18
|
+
*/
|
|
19
|
+
const deployStack = async (iac, backend, plan) => {
|
|
14
20
|
if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
|
|
15
|
-
await (0, scfStack_1.deployTencentStack)(iac, backend);
|
|
21
|
+
await (0, scfStack_1.deployTencentStack)(iac, backend, plan);
|
|
16
22
|
}
|
|
17
23
|
else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
|
|
18
|
-
await (0, aliyunStack_1.deployAliyunStack)(iac, backend);
|
|
24
|
+
await (0, aliyunStack_1.deployAliyunStack)(iac, backend, plan);
|
|
19
25
|
}
|
|
20
26
|
else if (iac.provider.name === common_1.ProviderEnum.HUAWEI) {
|
|
21
27
|
await deployHuawei();
|
|
22
28
|
}
|
|
23
29
|
else if (iac.provider.name === common_1.ProviderEnum.VOLCENGINE) {
|
|
24
|
-
await (0, volcengineStack_1.deployVolcengineStack)(iac, backend);
|
|
30
|
+
await (0, volcengineStack_1.deployVolcengineStack)(iac, backend, plan);
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
33
|
exports.deployStack = deployStack;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateBucketPlan = void 0;
|
|
4
|
+
const lang_1 = require("../../lang");
|
|
4
5
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
6
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
7
|
const concurrency_1 = require("../../common/concurrency");
|
|
@@ -38,7 +39,11 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
38
39
|
desiredDefinition,
|
|
39
40
|
read: readBucket,
|
|
40
41
|
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
|
|
41
|
-
foreignError: () => new Error(
|
|
42
|
+
foreignError: () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
43
|
+
resourceType: 'Bucket',
|
|
44
|
+
resourceName: bucket.name,
|
|
45
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
46
|
+
})),
|
|
42
47
|
cloudToDefinition: cosTypes_1.cloudCosToDefinition,
|
|
43
48
|
extraUpdate: async () => {
|
|
44
49
|
// Policy needs a canonical compare: the cloud returns a parsed
|
|
@@ -254,7 +254,7 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
254
254
|
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['BucketAlreadyExists', 'BucketAlreadyOwnedByYou'])) {
|
|
255
255
|
throw error;
|
|
256
256
|
}
|
|
257
|
-
logger_1.logger.info(
|
|
257
|
+
logger_1.logger.info(lang_1.lang.__('OWNERSHIP_VERIFYING', { resourceType: 'Bucket', resourceName: bucket.name }));
|
|
258
258
|
}
|
|
259
259
|
const bucketInfo = await client.cos.getBucket(bucket.name, context.region);
|
|
260
260
|
if (!bucketInfo) {
|
|
@@ -266,7 +266,11 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
266
266
|
// one may belong to another project and must fail loudly rather than be
|
|
267
267
|
// silently taken over (destroy would then remove a resource never ours).
|
|
268
268
|
if (!(0, ownershipTag_1.isOwnedByStack)(context, logicalId, bucketInfo.Tags)) {
|
|
269
|
-
throw new types_1.PartialResourceError(stateAfterDependents, new Error(
|
|
269
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
270
|
+
resourceType: 'Bucket',
|
|
271
|
+
resourceName: bucket.name,
|
|
272
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
273
|
+
})));
|
|
270
274
|
}
|
|
271
275
|
const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
|
|
272
276
|
const instances = [
|
|
@@ -28,18 +28,33 @@ const handlePartialFailure = (failure) => {
|
|
|
28
28
|
throw error;
|
|
29
29
|
};
|
|
30
30
|
const collectSuccessfulItems = (results) => results.flatMap((result) => result.partialFailure?.successfulItems ?? []);
|
|
31
|
-
|
|
31
|
+
// Issue #246: when the approved plan is passed through, the executor runs
|
|
32
|
+
// exactly the displayed items — partitioned by resourceType, no re-probe.
|
|
33
|
+
const partitionPlan = (plan, types) => ({
|
|
34
|
+
items: plan.items.filter((item) => types.includes(item.resourceType)),
|
|
35
|
+
});
|
|
36
|
+
const deployTencentStack = async (iac, backend, approvedPlan) => {
|
|
32
37
|
const context = (0, common_1.getContext)();
|
|
33
38
|
common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK_PUBLISHING_ASSETS'));
|
|
34
39
|
let state = await backend.loadState(iac.provider.name, iac.app, iac.service, context.stage);
|
|
35
40
|
const onStateChange = createSaveStateFn(backend, iac, context.stage);
|
|
36
41
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
|
|
37
|
-
const functionPlan =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
42
|
+
const functionPlan = approvedPlan
|
|
43
|
+
? partitionPlan(approvedPlan, ['SCF'])
|
|
44
|
+
: await (0, scfPlanner_1.generateFunctionPlan)(context, state, iac.functions);
|
|
45
|
+
const bucketPlan = approvedPlan
|
|
46
|
+
? partitionPlan(approvedPlan, ['COS_BUCKET'])
|
|
47
|
+
: await (0, cosPlanner_1.generateBucketPlan)(context, state, iac.buckets);
|
|
48
|
+
const databasePlan = approvedPlan
|
|
49
|
+
? partitionPlan(approvedPlan, ['TDSQL_C_SERVERLESS'])
|
|
50
|
+
: await (0, tdsqlcPlanner_1.generateDatabasePlan)(context, state, iac.databases);
|
|
51
|
+
const esPlan = approvedPlan
|
|
52
|
+
? partitionPlan(approvedPlan, ['TENCENT_ES_SERVERLESS'])
|
|
53
|
+
: await (0, esServerlessPlanner_1.generateEsPlan)(context, state, iac.databases);
|
|
41
54
|
const combinedPlan = {
|
|
42
|
-
items:
|
|
55
|
+
items: approvedPlan
|
|
56
|
+
? [...approvedPlan.items]
|
|
57
|
+
: [...functionPlan.items, ...bucketPlan.items, ...databasePlan.items, ...esPlan.items],
|
|
43
58
|
};
|
|
44
59
|
common_1.logger.info(`${lang_1.lang.__('PLAN_GENERATED')}: ${combinedPlan.items.length} ${lang_1.lang.__('ACTIONS')}`);
|
|
45
60
|
combinedPlan.items.forEach((item) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateEsPlan = void 0;
|
|
4
|
+
const lang_1 = require("../../lang");
|
|
4
5
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
6
|
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
7
|
const concurrency_1 = require("../../common/concurrency");
|
|
@@ -44,7 +45,11 @@ const generateEsPlan = async (context, state, databases) => {
|
|
|
44
45
|
? (0, refreshCache_1.cachedRefreshRead)(context, `es.getSpace:${spaceId}`, () => client.es.getSpace(spaceId))
|
|
45
46
|
: Promise.resolve(null),
|
|
46
47
|
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
|
|
47
|
-
foreignError: () => new Error(
|
|
48
|
+
foreignError: () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
49
|
+
resourceType: 'ES space',
|
|
50
|
+
resourceName: config.SpaceName,
|
|
51
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
52
|
+
})),
|
|
48
53
|
cloudToDefinition: esServerlessTypes_1.cloudTencentEsToDefinition,
|
|
49
54
|
refresh: context.refresh,
|
|
50
55
|
});
|
|
@@ -113,7 +113,11 @@ const createEsResource = async (context, database, state) => {
|
|
|
113
113
|
logger_1.logger.info(`ES space ${config.SpaceName} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
114
114
|
return (0, stateManager_1.setResource)(state, logicalId, buildResourceState(probe));
|
|
115
115
|
}
|
|
116
|
-
throw new types_1.PartialResourceError(stateAfterDependents, new Error(
|
|
116
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
117
|
+
resourceType: 'ES space',
|
|
118
|
+
resourceName: config.SpaceName,
|
|
119
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
120
|
+
})));
|
|
117
121
|
}
|
|
118
122
|
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
119
123
|
}
|