@geek-fun/serverlessinsight 0.8.7 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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 +94 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +36 -16
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +35 -73
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +148 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/deploy.js +1 -0
- package/dist/src/commands/index.js +6 -2
- package/dist/src/commands/plan.js +1 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
- package/dist/src/common/aliyunClient/index.js +44 -35
- package/dist/src/common/aliyunClient/nasOperations.js +21 -0
- package/dist/src/common/aliyunClient/ramOperations.js +32 -20
- package/dist/src/common/aliyunClient/slsOperations.js +16 -3
- package/dist/src/common/concurrency.js +30 -0
- package/dist/src/common/constants.js +5 -1
- package/dist/src/common/context.js +3 -0
- package/dist/src/common/dependencyGraph/graph.js +5 -0
- package/dist/src/common/imsClient.js +2 -2
- package/dist/src/common/index.js +5 -0
- package/dist/src/common/planCompare.js +62 -0
- package/dist/src/common/planFormatter.js +15 -3
- package/dist/src/common/refreshCache.js +32 -0
- package/dist/src/common/refreshPlanner.js +105 -0
- package/dist/src/common/tencentClient/clsOperations.js +27 -3
- package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
- package/dist/src/common/throttleRetry.js +56 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
- package/dist/src/lang/en.js +16 -0
- package/dist/src/lang/zh-CN.js +16 -0
- package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
- package/dist/src/stack/aliyunStack/apigwTypes.js +67 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +221 -30
- package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
- package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
- package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
- package/dist/src/stack/scfStack/cosPlanner.js +30 -50
- package/dist/src/stack/scfStack/cosTypes.js +29 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
- package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
- package/dist/src/stack/scfStack/scfExecutor.js +5 -3
- package/dist/src/stack/scfStack/scfPlanner.js +71 -50
- package/dist/src/stack/scfStack/scfResource.js +37 -2
- package/dist/src/stack/scfStack/scfTypes.js +35 -1
- package/dist/src/stack/scfStack/sharedLogset.js +3 -2
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
- package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +54 -7
- package/dist/src/stack/volcengineStack/apigwTypes.js +26 -1
- package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
- package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +114 -6
- package/dist/src/stack/volcengineStack/vefaasResource.js +40 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ const lang_1 = require("../../lang");
|
|
|
14
14
|
const ownershipTag_1 = require("../ownershipTag");
|
|
15
15
|
const alreadyExists_1 = require("../alreadyExists");
|
|
16
16
|
const sharedLogset_1 = require("./sharedLogset");
|
|
17
|
+
const clsOperations_1 = require("../../common/tencentClient/clsOperations");
|
|
17
18
|
/**
|
|
18
19
|
* Build the Function URL trigger description for Tencent CreateTrigger
|
|
19
20
|
* (Type: 'http'). Format per official docs (创建函数 URL / Creating a Function
|
|
@@ -659,7 +660,7 @@ const readResource = async (context, functionName) => {
|
|
|
659
660
|
return await client.scf.getFunction(functionName);
|
|
660
661
|
};
|
|
661
662
|
exports.readResource = readResource;
|
|
662
|
-
const updateResource = async (context, fn, state) => {
|
|
663
|
+
const updateResource = async (context, fn, state, options) => {
|
|
663
664
|
const logicalId = `functions.${fn.key}`;
|
|
664
665
|
const existingState = (0, stateManager_1.getResource)(state, logicalId);
|
|
665
666
|
const existingInstances = (existingState?.instances ?? []);
|
|
@@ -674,6 +675,37 @@ const updateResource = async (context, fn, state) => {
|
|
|
674
675
|
(legacyLogsetId && legacyTopicId));
|
|
675
676
|
const hasCamRole = existingInstances.some((i) => i.type === types_1.ResourceTypeEnum.TENCENT_SCF_ROLE);
|
|
676
677
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
678
|
+
// Issue #234 M3: nested repair — only on a drifted plan item (force):
|
|
679
|
+
// reconcile topic attributes against si's creation defaults; a deleted
|
|
680
|
+
// topic is recreated under the shared logset when it is still recorded.
|
|
681
|
+
if (options?.force && fn.log && existingClsTopicInstance) {
|
|
682
|
+
const liveTopic = await client.cls.getTopicById(existingClsTopicInstance.id).catch(() => null);
|
|
683
|
+
if (!liveTopic) {
|
|
684
|
+
const sharedBefore = (0, stateManager_1.getSharedResource)(state, context.stage, sharedLogset_1.SHARED_LOGSET_KEY);
|
|
685
|
+
const sharedLogsetId = sharedBefore?.instances?.[0]?.id ??
|
|
686
|
+
existingClsTopicInstance.logsetId;
|
|
687
|
+
if (sharedLogsetId) {
|
|
688
|
+
logger_1.logger.warn(lang_1.lang.__('NESTED_TOPIC_RECREATED', { topicId: existingClsTopicInstance.id }));
|
|
689
|
+
await client.cls.createTopic(sharedLogsetId, (0, sharedLogset_1.buildFunctionTopicName)(context, fn.key), {
|
|
690
|
+
tags: [
|
|
691
|
+
{
|
|
692
|
+
key: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
693
|
+
value: (0, ownershipTag_1.buildOwnershipTagValue)(context, `functions.${fn.key}`),
|
|
694
|
+
},
|
|
695
|
+
],
|
|
696
|
+
});
|
|
697
|
+
await client.cls.createFulltextIndex(existingClsTopicInstance.id);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
else if (liveTopic.StorageType !== clsOperations_1.CLS_TOPIC_STORAGE_TYPE ||
|
|
701
|
+
liveTopic.Period !== clsOperations_1.CLS_TOPIC_PERIOD) {
|
|
702
|
+
await client.cls.modifyTopic(existingClsTopicInstance.id, {
|
|
703
|
+
period: clsOperations_1.CLS_TOPIC_PERIOD,
|
|
704
|
+
storageType: clsOperations_1.CLS_TOPIC_STORAGE_TYPE,
|
|
705
|
+
});
|
|
706
|
+
logger_1.logger.info(lang_1.lang.__('NESTED_TOPIC_UPDATED', { topicId: existingClsTopicInstance.id }));
|
|
707
|
+
}
|
|
708
|
+
}
|
|
677
709
|
const newIamRole = fn.iam?.role;
|
|
678
710
|
let role;
|
|
679
711
|
if (typeof newIamRole === 'string') {
|
|
@@ -810,7 +842,10 @@ const updateResource = async (context, fn, state) => {
|
|
|
810
842
|
// Disabling log always re-pushes config so the empty Cls ids reach the
|
|
811
843
|
// UpdateFunctionConfiguration unbind contract.
|
|
812
844
|
disableLog;
|
|
813
|
-
|
|
845
|
+
// `force` carries the plan's drifted flag: a live-drift update (state
|
|
846
|
+
// matches config, cloud edited in console) must re-push the config even
|
|
847
|
+
// though state-vs-desired sees no change.
|
|
848
|
+
if (configChanged || options?.force) {
|
|
814
849
|
await client.scf.updateFunctionConfiguration(config);
|
|
815
850
|
}
|
|
816
851
|
if (disableLog) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractFunctionDomainDefinition = exports.extractScfDefinition = exports.functionToScfConfig = void 0;
|
|
3
|
+
exports.cloudScfToDefinition = exports.extractFunctionDomainDefinition = exports.extractScfDefinition = exports.functionToScfConfig = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const functionToScfConfig = (fn, role) => {
|
|
6
6
|
const config = {
|
|
@@ -77,3 +77,37 @@ const extractFunctionDomainDefinition = (fn, codeHash) => {
|
|
|
77
77
|
return (0, exports.extractScfDefinition)(config, codeHash, fn.iam);
|
|
78
78
|
};
|
|
79
79
|
exports.extractFunctionDomainDefinition = extractFunctionDomainDefinition;
|
|
80
|
+
// issue #234 phase 2: cloud-side counterpart of extractScfDefinition. Mirrors
|
|
81
|
+
// the executor write shape key-for-key. Not refreshable (omitted so they can
|
|
82
|
+
// never phantom-drift): logConfig (GetFunction returns ClsLogsetId/ClsTopicId
|
|
83
|
+
// ids while the desired definition uses stable logset/topic names — ids churn
|
|
84
|
+
// across redeploys), diskSize (GetFunction does not report it), iam/role
|
|
85
|
+
// (planner-side role grant not reproduced for tencent in this phase).
|
|
86
|
+
const cloudScfToDefinition = (info) => {
|
|
87
|
+
const envMap = info.Environment?.Variables?.reduce((acc, v) => ({ ...acc, [v.Key]: v.Value }), {}) ?? {};
|
|
88
|
+
const cloudVpcConfig = info.VpcConfig;
|
|
89
|
+
const cloudCfsConfig = info.CfsConfig;
|
|
90
|
+
const cloudImageConfig = info.ImageConfig;
|
|
91
|
+
return {
|
|
92
|
+
functionName: info.FunctionName ?? null,
|
|
93
|
+
runtime: info.Runtime ?? null,
|
|
94
|
+
handler: info.Handler ?? null,
|
|
95
|
+
memorySize: info.MemorySize ?? null,
|
|
96
|
+
timeout: info.Timeout ?? null,
|
|
97
|
+
environment: envMap,
|
|
98
|
+
vpcConfig: cloudVpcConfig
|
|
99
|
+
? { VpcId: cloudVpcConfig.VpcId ?? null, SubnetId: cloudVpcConfig.SubnetId ?? null }
|
|
100
|
+
: null,
|
|
101
|
+
cfsConfig: cloudCfsConfig?.CfsInsList
|
|
102
|
+
? {
|
|
103
|
+
CfsInsList: cloudCfsConfig.CfsInsList.map((i) => ({
|
|
104
|
+
LocalMountDir: i.LocalMountDir ?? null,
|
|
105
|
+
RemoteMountDir: i.RemoteMountDir ?? null,
|
|
106
|
+
})),
|
|
107
|
+
}
|
|
108
|
+
: null,
|
|
109
|
+
useGpu: info.UseGpu ?? null,
|
|
110
|
+
imageConfig: cloudImageConfig ? { ImageUri: cloudImageConfig.ImageUri ?? null } : null,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
exports.cloudScfToDefinition = cloudScfToDefinition;
|
|
@@ -5,6 +5,7 @@ const common_1 = require("../../common");
|
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
6
|
const logger_1 = require("../../common/logger");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
|
+
const clsOperations_1 = require("../../common/tencentClient/clsOperations");
|
|
8
9
|
const ownershipTag_1 = require("../ownershipTag");
|
|
9
10
|
/**
|
|
10
11
|
* Issue #214: one shared CLS logset per app×stage, tracked in the stage-level
|
|
@@ -123,8 +124,8 @@ const ensureFunctionTopic = async (context, client, params) => {
|
|
|
123
124
|
}
|
|
124
125
|
logger_1.logger.info(lang_1.lang.__('CREATING_CLS_TOPIC', { topicName }));
|
|
125
126
|
const topic = await client.cls.createTopic(logsetId, topicName, {
|
|
126
|
-
period:
|
|
127
|
-
storageType:
|
|
127
|
+
period: clsOperations_1.CLS_TOPIC_PERIOD,
|
|
128
|
+
storageType: clsOperations_1.CLS_TOPIC_STORAGE_TYPE,
|
|
128
129
|
tags: [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
|
|
129
130
|
});
|
|
130
131
|
logger_1.logger.info(lang_1.lang.__('CREATING_CLS_INDEX', { topicName }));
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateDatabasePlan = void 0;
|
|
4
4
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
|
+
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
|
+
const concurrency_1 = require("../../common/concurrency");
|
|
5
7
|
const tdsqlcTypes_1 = require("./tdsqlcTypes");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
-
const
|
|
9
|
+
const refreshPlanner_1 = require("../../common/refreshPlanner");
|
|
8
10
|
const ownershipTag_1 = require("../ownershipTag");
|
|
9
11
|
const planDatabaseDeletion = (logicalId, definition) => ({
|
|
10
12
|
logicalId,
|
|
@@ -29,64 +31,44 @@ const generateDatabasePlan = async (context, state, databases) => {
|
|
|
29
31
|
return { items };
|
|
30
32
|
}
|
|
31
33
|
const desiredLogicalIds = new Set(tdsqlcDatabases.map((db) => `databases.${db.key}`));
|
|
32
|
-
const databaseItems = await
|
|
34
|
+
const databaseItems = await (0, concurrency_1.mapWithConcurrency)(tdsqlcDatabases, concurrency_1.PLAN_READ_CONCURRENCY, async (database) => {
|
|
33
35
|
const logicalId = `databases.${database.key}`;
|
|
34
36
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
35
37
|
const config = (0, tdsqlcTypes_1.databaseToTdsqlcConfig)(database);
|
|
36
38
|
const desiredDefinition = (0, tdsqlcTypes_1.extractTdsqlcDefinition)(config);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (definitionChanged) {
|
|
71
|
-
return {
|
|
72
|
-
logicalId,
|
|
73
|
-
action: 'update',
|
|
74
|
-
resourceType: 'TDSQL_C_SERVERLESS',
|
|
75
|
-
changes: { before: currentDefinition, after: desiredDefinition },
|
|
76
|
-
drifted: true,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return { logicalId, action: 'noop', resourceType: 'TDSQL_C_SERVERLESS' };
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
return {
|
|
83
|
-
logicalId,
|
|
84
|
-
action: 'create',
|
|
85
|
-
resourceType: 'TDSQL_C_SERVERLESS',
|
|
86
|
-
changes: { before: currentState.definition, after: desiredDefinition },
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}));
|
|
39
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
40
|
+
const clusterId = currentState?.metadata?.clusterId ||
|
|
41
|
+
currentState?.instances?.[0]?.id;
|
|
42
|
+
return (0, refreshPlanner_1.planRefreshedResource)({
|
|
43
|
+
logicalId,
|
|
44
|
+
resourceType: 'TDSQL_C_SERVERLESS',
|
|
45
|
+
currentState,
|
|
46
|
+
desiredDefinition,
|
|
47
|
+
probeRead: () => (0, refreshCache_1.cachedRefreshRead)(context, `tdsqlc.getClusterByName:${database.name}`, () => client.tdsqlc.getClusterByName(database.name)),
|
|
48
|
+
read: () => clusterId
|
|
49
|
+
? (0, refreshCache_1.cachedRefreshRead)(context, `tdsqlc.getCluster:${clusterId}`, () => client.tdsqlc.getCluster(clusterId))
|
|
50
|
+
: Promise.resolve(null),
|
|
51
|
+
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, (0, tdsqlcTypes_1.tdsqlcTagsToOwnershipTags)(remote.ResourceTags)),
|
|
52
|
+
foreignError: () => new Error(`Cluster ${database.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
|
|
53
|
+
cloudToDefinition: tdsqlcTypes_1.cloudTdsqlcToDefinition,
|
|
54
|
+
extraUpdate: async () => {
|
|
55
|
+
// AutoPause needs a dedicated read: DescribeClusters reports the
|
|
56
|
+
// running serverless state, not the configured idle-pause switch —
|
|
57
|
+
// DescribeServerlessStrategy does. Unreadable strategy is not drift.
|
|
58
|
+
const desiredAutoPause = desiredDefinition.autoPause;
|
|
59
|
+
if (typeof desiredAutoPause !== 'boolean' || !clusterId) {
|
|
60
|
+
return { update: false, drifted: false };
|
|
61
|
+
}
|
|
62
|
+
const strategy = await (0, refreshCache_1.cachedRefreshRead)(context, `tdsqlc.getServerlessStrategy:${clusterId}`, () => client.tdsqlc.getServerlessStrategy(clusterId));
|
|
63
|
+
if (!strategy || strategy.autoPause === undefined) {
|
|
64
|
+
return { update: false, drifted: false };
|
|
65
|
+
}
|
|
66
|
+
const drifted = strategy.autoPause !== desiredAutoPause;
|
|
67
|
+
return { update: drifted, drifted };
|
|
68
|
+
},
|
|
69
|
+
refresh: context.refresh,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
90
72
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
91
73
|
const deletionItems = Object.entries(allStates)
|
|
92
74
|
.filter(([logicalId, resourceState]) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractTdsqlcDefinition = exports.databaseToTdsqlcConfig = exports.tdsqlcTagsToOwnershipTags = void 0;
|
|
3
|
+
exports.cloudTdsqlcToDefinition = exports.extractTdsqlcDefinition = exports.databaseToTdsqlcConfig = exports.tdsqlcTagsToOwnershipTags = void 0;
|
|
4
4
|
// TDSQL-C tags are {TagKey,TagValue}; the ownership-tag matcher expects
|
|
5
5
|
// {Key,Value}. Convert once at the probe site.
|
|
6
6
|
const tdsqlcTagsToOwnershipTags = (tags) => (tags ?? []).map((t) => ({ Key: t.TagKey, Value: t.TagValue }));
|
|
@@ -61,3 +61,23 @@ const extractTdsqlcDefinition = (config) => {
|
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
exports.extractTdsqlcDefinition = extractTdsqlcDefinition;
|
|
64
|
+
// issue #234 phase 2: cloud-side counterpart of extractTdsqlcDefinition.
|
|
65
|
+
// Mirrors the executor write shape key-for-key. Not refreshable (omitted so
|
|
66
|
+
// they can never phantom-drift): autoPause/autoPauseDelay — DescribeClusters
|
|
67
|
+
// reports only the running serverless state; the configured switch is compared
|
|
68
|
+
// separately in the planner via DescribeServerlessStrategy (extraUpdate).
|
|
69
|
+
// port/projectId are not returned by any read API.
|
|
70
|
+
const cloudTdsqlcToDefinition = (info) => ({
|
|
71
|
+
clusterName: info.ClusterName,
|
|
72
|
+
dbType: info.DbType ?? null,
|
|
73
|
+
dbVersion: info.DbVersion ?? null,
|
|
74
|
+
dbMode: info.DbMode ?? null,
|
|
75
|
+
minCpu: info.MinCpu ?? null,
|
|
76
|
+
maxCpu: info.MaxCpu ?? null,
|
|
77
|
+
storagePayMode: info.StoragePayMode ?? null,
|
|
78
|
+
vpcId: info.VpcId ?? null,
|
|
79
|
+
subnetId: info.SubnetId ?? null,
|
|
80
|
+
minStorageSize: info.MinStorageSize ?? null,
|
|
81
|
+
maxStorageSize: info.MaxStorageSize ?? null,
|
|
82
|
+
});
|
|
83
|
+
exports.cloudTdsqlcToDefinition = cloudTdsqlcToDefinition;
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateApigwPlan = void 0;
|
|
4
4
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
5
|
+
const refreshCache_1 = require("../../common/refreshCache");
|
|
6
|
+
const concurrency_1 = require("../../common/concurrency");
|
|
5
7
|
const apigwTypes_1 = require("./apigwTypes");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
10
|
+
const common_1 = require("../../common");
|
|
11
|
+
const lang_1 = require("../../lang");
|
|
8
12
|
const ownershipTag_1 = require("../ownershipTag");
|
|
9
13
|
const planEventDeletion = (logicalId, definition) => ({
|
|
10
14
|
logicalId,
|
|
@@ -21,7 +25,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
21
25
|
return { items };
|
|
22
26
|
}
|
|
23
27
|
const desiredLogicalIds = new Set(events.map((e) => `events.${e.key}`));
|
|
24
|
-
const eventItems = await
|
|
28
|
+
const eventItems = await (0, concurrency_1.mapWithConcurrency)(events, concurrency_1.PLAN_READ_CONCURRENCY, async (event) => {
|
|
25
29
|
const logicalId = `events.${event.key}`;
|
|
26
30
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
27
31
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
@@ -36,7 +40,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
36
40
|
// may belong to another project — fail fast in the plan instead of
|
|
37
41
|
// letting the executor discover it mid-deploy. The serverless gateway
|
|
38
42
|
// is account-scoped, so only refuse when the NAMED one is foreign.
|
|
39
|
-
const remoteGateway = await client.apigw.findGatewayByName((0, apigwTypes_1.buildGatewayName)(serviceName, context.stage));
|
|
43
|
+
const remoteGateway = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.findGatewayByName:${serviceName}:${context.stage}`, () => client.apigw.findGatewayByName((0, apigwTypes_1.buildGatewayName)(serviceName, context.stage)));
|
|
40
44
|
if (remoteGateway?.gatewayId && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteGateway.tags)) {
|
|
41
45
|
throw new Error(`API Gateway ${(0, apigwTypes_1.buildGatewayName)(serviceName, context.stage)} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
42
46
|
}
|
|
@@ -48,9 +52,14 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
54
|
const serviceInstance = currentState.instances.find((i) => i.type === 'VOLCENGINE_APIGW_SERVICE');
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
// --no-refresh: no live reads, no drift claims — intent-diff only.
|
|
56
|
+
const refreshEnabled = context.refresh !== false;
|
|
57
|
+
let cloudService = null;
|
|
58
|
+
if (refreshEnabled && serviceInstance) {
|
|
59
|
+
// Keep the not-found swallow OUTSIDE the cached read: a cached rejection
|
|
60
|
+
// evicts its key so the next plan pass retries against the provider.
|
|
61
|
+
cloudService = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.getService:${serviceInstance.id}`, () => client.apigw.getService(serviceInstance.id)).catch(() => null);
|
|
62
|
+
if (!cloudService) {
|
|
54
63
|
return {
|
|
55
64
|
logicalId,
|
|
56
65
|
action: 'create',
|
|
@@ -62,16 +71,54 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
62
71
|
}
|
|
63
72
|
const currentDefinition = currentState.definition || {};
|
|
64
73
|
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
65
|
-
|
|
74
|
+
// Issue #234 phase 2: live trigger drift. The service record alone can be
|
|
75
|
+
// untouched while console edits reroute a trigger (method/path/upstream).
|
|
76
|
+
// Routes and upstreams are matched by the derived names the executor
|
|
77
|
+
// writes; a probe failure stays noop (best-effort detection) instead of
|
|
78
|
+
// fabricating drift from a transient read error.
|
|
79
|
+
let triggersDiffer = false;
|
|
80
|
+
if (refreshEnabled && !definitionChanged && serviceInstance && event.triggers.length > 0) {
|
|
81
|
+
try {
|
|
82
|
+
const desiredTriggers = (0, apigwTypes_1.buildDesiredTriggerMap)(event, context.stage);
|
|
83
|
+
const cloudRoutes = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.listRoutesByService:${serviceInstance.id}`, () => client.apigw.listRoutesByService(serviceInstance.id));
|
|
84
|
+
const matched = (cloudRoutes ?? []).filter((route) => route.routeName && desiredTriggers.has(route.routeName));
|
|
85
|
+
const upstreamNameById = new Map();
|
|
86
|
+
for (const route of matched) {
|
|
87
|
+
const upstreamId = route.upstreamIds?.[0];
|
|
88
|
+
if (upstreamId && !upstreamNameById.has(upstreamId)) {
|
|
89
|
+
const upstream = await (0, refreshCache_1.cachedRefreshRead)(context, `apigw.getUpstream:${upstreamId}`, () => client.apigw.getUpstream(upstreamId));
|
|
90
|
+
upstreamNameById.set(upstreamId, upstream?.upstreamName);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
triggersDiffer = (0, apigwTypes_1.cloudTriggerDiffers)(matched, upstreamNameById, desiredTriggers);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
common_1.logger.warn(lang_1.lang.__('PLAN_EVENT_TRIGGER_PROBE_FAILED', {
|
|
97
|
+
eventName: event.name,
|
|
98
|
+
error: String(error),
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Issue #234 phase 3: declared custom-domain drift — the service read
|
|
103
|
+
// already carries customDomains, so this costs no extra API call.
|
|
104
|
+
const desiredDomainName = desiredDefinition.domain
|
|
105
|
+
?.domainName;
|
|
106
|
+
let domainDiffers = false;
|
|
107
|
+
if (refreshEnabled && desiredDomainName) {
|
|
108
|
+
const cloudDomains = cloudService?.customDomains ?? [];
|
|
109
|
+
domainDiffers = !cloudDomains.some((d) => d.domain === desiredDomainName);
|
|
110
|
+
}
|
|
111
|
+
if (definitionChanged || triggersDiffer || domainDiffers) {
|
|
66
112
|
return {
|
|
67
113
|
logicalId,
|
|
68
114
|
action: 'update',
|
|
69
115
|
resourceType: 'VOLCENGINE_APIGW',
|
|
70
116
|
changes: { before: currentDefinition, after: desiredDefinition },
|
|
117
|
+
drifted: true,
|
|
71
118
|
};
|
|
72
119
|
}
|
|
73
120
|
return { logicalId, action: 'noop', resourceType: 'VOLCENGINE_APIGW' };
|
|
74
|
-
})
|
|
121
|
+
});
|
|
75
122
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
76
123
|
const deletionItems = Object.entries(allStates)
|
|
77
124
|
.filter(([logicalId]) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveFunctionReference = exports.buildEventResourceDefinition = exports.extractEventDomainDefinition = exports.triggerToApigwRouteConfig = exports.triggerToApigwUpstreamConfig = exports.eventToApigwServiceConfig = exports.eventToApigwGatewayConfig = exports.resolveFunctionKey = exports.buildRouteName = exports.buildUpstreamName = exports.buildServiceName = exports.buildGatewayName = void 0;
|
|
3
|
+
exports.resolveFunctionReference = exports.cloudTriggerDiffers = exports.buildDesiredTriggerMap = exports.buildEventResourceDefinition = exports.extractEventDomainDefinition = exports.triggerToApigwRouteConfig = exports.triggerToApigwUpstreamConfig = exports.eventToApigwServiceConfig = exports.eventToApigwGatewayConfig = exports.resolveFunctionKey = exports.buildRouteName = exports.buildUpstreamName = exports.buildServiceName = exports.buildGatewayName = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
const ownershipTag_1 = require("../ownershipTag");
|
|
@@ -128,3 +128,28 @@ const buildEventResourceDefinition = (event, logTopicOverride) => {
|
|
|
128
128
|
return (0, exports.extractEventDomainDefinition)(event, logTopicOverride);
|
|
129
129
|
};
|
|
130
130
|
exports.buildEventResourceDefinition = buildEventResourceDefinition;
|
|
131
|
+
const buildDesiredTriggerMap = (event, stage) => new Map(event.triggers.map((trigger) => {
|
|
132
|
+
const method = String(trigger.method);
|
|
133
|
+
const path = String(trigger.path);
|
|
134
|
+
return [
|
|
135
|
+
(0, exports.buildRouteName)(event, method, path),
|
|
136
|
+
{ method, path, upstreamName: (0, exports.buildUpstreamName)(event, String(trigger.backend), stage) },
|
|
137
|
+
];
|
|
138
|
+
}));
|
|
139
|
+
exports.buildDesiredTriggerMap = buildDesiredTriggerMap;
|
|
140
|
+
const cloudTriggerDiffers = (cloudRoutes, upstreamNameById, desiredTriggers) => [...desiredTriggers.keys()].some((routeName) => {
|
|
141
|
+
const desired = desiredTriggers.get(routeName);
|
|
142
|
+
const route = cloudRoutes.find((r) => r.routeName === routeName);
|
|
143
|
+
if (!desired || !route) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
if (desired.method !== route.method || desired.path !== route.path) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
const upstreamId = route.upstreamIds?.[0];
|
|
150
|
+
if (!upstreamId) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return desired.upstreamName !== upstreamNameById.get(upstreamId);
|
|
154
|
+
});
|
|
155
|
+
exports.cloudTriggerDiffers = cloudTriggerDiffers;
|
|
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.generateBucketPlan = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
9
|
+
const refreshCache_1 = require("../../common/refreshCache");
|
|
10
|
+
const concurrency_1 = require("../../common/concurrency");
|
|
11
|
+
const refreshPlanner_1 = require("../../common/refreshPlanner");
|
|
12
|
+
const planCompare_1 = require("../../common/planCompare");
|
|
9
13
|
const tosTypes_1 = require("./tosTypes");
|
|
10
14
|
const stateManager_1 = require("../../common/stateManager");
|
|
11
15
|
const common_1 = require("../../common");
|
|
@@ -25,7 +29,7 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
25
29
|
return { items };
|
|
26
30
|
}
|
|
27
31
|
const desiredLogicalIds = new Set(buckets.map((bucket) => `buckets.${bucket.key}`));
|
|
28
|
-
const bucketItems = await
|
|
32
|
+
const bucketItems = await (0, concurrency_1.mapWithConcurrency)(buckets, concurrency_1.PLAN_READ_CONCURRENCY, async (bucket) => {
|
|
29
33
|
const logicalId = `buckets.${bucket.key}`;
|
|
30
34
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
31
35
|
const config = (0, tosTypes_1.bucketToTosConfig)(bucket);
|
|
@@ -40,63 +44,32 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
40
44
|
}
|
|
41
45
|
})();
|
|
42
46
|
const desiredDefinition = (0, tosTypes_1.extractTosBucketDefinition)(config, websiteCodeHash);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
62
|
-
const remoteBucket = await client.tos.getBucket(bucket.name);
|
|
63
|
-
if (!remoteBucket) {
|
|
64
|
-
return {
|
|
65
|
-
logicalId,
|
|
66
|
-
action: 'create',
|
|
67
|
-
resourceType: 'VOLCENGINE_TOS_BUCKET',
|
|
68
|
-
changes: {
|
|
69
|
-
before: currentState.definition,
|
|
70
|
-
after: desiredDefinition,
|
|
71
|
-
},
|
|
72
|
-
drifted: true,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const currentDefinition = currentState.definition || {};
|
|
76
|
-
const definitionChanged = !(0, common_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
77
|
-
if (definitionChanged) {
|
|
47
|
+
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
48
|
+
return (0, refreshPlanner_1.planRefreshedResource)({
|
|
49
|
+
logicalId,
|
|
50
|
+
resourceType: 'VOLCENGINE_TOS_BUCKET',
|
|
51
|
+
currentState,
|
|
52
|
+
desiredDefinition,
|
|
53
|
+
read: () => (0, refreshCache_1.cachedRefreshRead)(context, `tos.getBucket:${bucket.name}`, () => client.tos.getBucket(bucket.name)),
|
|
54
|
+
isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
|
|
55
|
+
foreignError: () => new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
|
|
56
|
+
cloudToDefinition: tosTypes_1.cloudTosToDefinition,
|
|
57
|
+
extraUpdate: async () => {
|
|
58
|
+
// Policy needs a canonical compare: the cloud returns a parsed
|
|
59
|
+
// object while the config serializes it — see jsonDocumentDiffers.
|
|
60
|
+
const desiredPolicy = desiredDefinition.policy ?? null;
|
|
61
|
+
if (desiredPolicy === null) {
|
|
62
|
+
return { update: false, drifted: false };
|
|
63
|
+
}
|
|
64
|
+
const cloudPolicy = await (0, refreshCache_1.cachedRefreshRead)(context, `tos.getBucketPolicy:${bucket.name}`, () => client.tos.getBucketPolicy(bucket.name));
|
|
78
65
|
return {
|
|
79
|
-
|
|
80
|
-
action: 'update',
|
|
81
|
-
resourceType: 'VOLCENGINE_TOS_BUCKET',
|
|
82
|
-
changes: { before: currentDefinition, after: desiredDefinition },
|
|
66
|
+
update: (0, planCompare_1.jsonDocumentDiffers)(desiredPolicy, cloudPolicy),
|
|
83
67
|
drifted: true,
|
|
84
68
|
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
logicalId,
|
|
91
|
-
action: 'create',
|
|
92
|
-
resourceType: 'VOLCENGINE_TOS_BUCKET',
|
|
93
|
-
changes: {
|
|
94
|
-
before: currentState.definition,
|
|
95
|
-
after: desiredDefinition,
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}));
|
|
69
|
+
},
|
|
70
|
+
refresh: context.refresh,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
100
73
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
101
74
|
const deletionItems = Object.entries(allStates)
|
|
102
75
|
.filter(([logicalId]) => logicalId.startsWith('buckets.') && !desiredLogicalIds.has(logicalId))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTosInstanceFromProvider = exports.extractTosBucketDefinition = exports.bucketToTosConfig = void 0;
|
|
3
|
+
exports.buildTosInstanceFromProvider = exports.cloudTosToDefinition = exports.extractTosBucketDefinition = exports.bucketToTosConfig = void 0;
|
|
4
4
|
const aclMap = {
|
|
5
5
|
PRIVATE: 'private',
|
|
6
6
|
PUBLIC_READ: 'public-read',
|
|
@@ -49,6 +49,23 @@ const extractTosBucketDefinition = (config, websiteCodeHash) => {
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
exports.extractTosBucketDefinition = extractTosBucketDefinition;
|
|
52
|
+
// issue #234 phase 2: cloud-side counterpart of extractTosBucketDefinition.
|
|
53
|
+
// Mirrors the executor write shape key-for-key: acl/storageClass/websiteConfig
|
|
54
|
+
// are compared live; policy (GetBucket returns no bucket-policy document) and
|
|
55
|
+
// websiteCodeHash (local-only) are not refreshable and stay omitted so they can
|
|
56
|
+
// never trigger phantom drift.
|
|
57
|
+
const cloudTosToDefinition = (info) => ({
|
|
58
|
+
bucketName: info.name,
|
|
59
|
+
acl: info.acl ?? null,
|
|
60
|
+
storageClass: info.storageClass ?? null,
|
|
61
|
+
websiteConfiguration: info.websiteConfig
|
|
62
|
+
? {
|
|
63
|
+
indexDocument: info.websiteConfig.indexDocument ?? null,
|
|
64
|
+
errorDocument: info.websiteConfig.errorDocument ?? null,
|
|
65
|
+
}
|
|
66
|
+
: null,
|
|
67
|
+
});
|
|
68
|
+
exports.cloudTosToDefinition = cloudTosToDefinition;
|
|
52
69
|
const buildTosInstanceFromProvider = (info, sid) => {
|
|
53
70
|
return {
|
|
54
71
|
type: 'VOLCENGINE_TOS_BUCKET',
|
|
@@ -13,9 +13,11 @@ const executeCreateAction = async (context, fn, currentState) => {
|
|
|
13
13
|
common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'function', name: fn.name }));
|
|
14
14
|
return newState;
|
|
15
15
|
};
|
|
16
|
-
const executeUpdateAction = async (context, fn, currentState) => {
|
|
16
|
+
const executeUpdateAction = async (context, fn, currentState, drifted) => {
|
|
17
17
|
common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'function', name: fn.name }));
|
|
18
|
-
|
|
18
|
+
// A drifted plan item means the cloud left the config: force the config
|
|
19
|
+
// re-push even when state-vs-desired sees no change.
|
|
20
|
+
const newState = await (0, vefaasResource_1.updateResource)(context, fn, currentState, { force: drifted === true });
|
|
19
21
|
common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'function', name: fn.name }));
|
|
20
22
|
return newState;
|
|
21
23
|
};
|
|
@@ -42,7 +44,7 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
|
42
44
|
if (!fn) {
|
|
43
45
|
throw new Error(`Function not found for logical ID: ${item.logicalId}`);
|
|
44
46
|
}
|
|
45
|
-
return executeUpdateAction(context, fn, currentState);
|
|
47
|
+
return executeUpdateAction(context, fn, currentState, item.drifted);
|
|
46
48
|
}
|
|
47
49
|
case 'delete': {
|
|
48
50
|
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|