@geek-fun/serverlessinsight 0.8.2 → 0.8.4
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 +15 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +5 -2
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +363 -30
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +90 -28
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +13 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +10 -4
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +186 -14
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +43 -2
- package/dist/src/common/tencentClient/scfOperations.js +266 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +91 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +305 -171
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +107 -1
- package/dist/src/lang/zh-CN.js +107 -1
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +16 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +27 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +416 -94
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +58 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +15 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +21 -3
- package/dist/src/stack/scfStack/scfResource.js +686 -24
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +434 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +13 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +78 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +32 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
|
@@ -6,10 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.deleteResource = exports.updateResource = exports.readResource = exports.createResource = void 0;
|
|
7
7
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
8
8
|
const common_1 = require("../../common");
|
|
9
|
+
const types_1 = require("../../types");
|
|
9
10
|
const tosTypes_1 = require("./tosTypes");
|
|
10
11
|
const logger_1 = require("../../common/logger");
|
|
11
12
|
const lang_1 = require("../../lang");
|
|
12
13
|
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
15
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
13
16
|
const buildTosBucketPolicyJson = (iam) => {
|
|
14
17
|
if (!iam?.resource?.statements || iam.resource.statements.length === 0)
|
|
15
18
|
return null;
|
|
@@ -42,26 +45,80 @@ const applyBucketPolicy = async (client, bucket) => {
|
|
|
42
45
|
logger_1.logger.info(lang_1.lang.__('BUCKET_POLICY_APPLIED', { bucketName: bucket.name }));
|
|
43
46
|
};
|
|
44
47
|
const deleteBucketPolicy = async (client, bucketName) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logger_1.logger.info(lang_1.lang.__('BUCKET_POLICY_DELETED', { bucketName }));
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// Best effort cleanup
|
|
51
|
-
}
|
|
48
|
+
await client.tos.deleteBucketPolicy(bucketName);
|
|
49
|
+
logger_1.logger.info(lang_1.lang.__('BUCKET_POLICY_DELETED', { bucketName }));
|
|
52
50
|
};
|
|
53
51
|
const createResource = async (context, bucket, state) => {
|
|
54
52
|
const config = (0, tosTypes_1.bucketToTosConfig)(bucket);
|
|
55
53
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
56
|
-
const bucketInfo = await client.tos.createBucket(config);
|
|
57
54
|
const sid = (0, common_1.buildSid)('volcengine', 'tos', context.stage, bucket.name);
|
|
58
55
|
const logicalId = `buckets.${bucket.key}`;
|
|
56
|
+
// Stamp the ownership tag (sent as the x-tos-tagging header on CreateBucket)
|
|
57
|
+
// so a later run can idempotently adopt this bucket, and an unrelated
|
|
58
|
+
// same-named bucket is never adopted.
|
|
59
|
+
config.Tags = [{ Key: ownershipTag_1.OWNERSHIP_TAG_KEY, Value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
59
60
|
const websiteCodeHash = bucket.website?.code
|
|
60
61
|
? (0, common_1.computeDirectoryHash)(node_path_1.default.resolve(process.cwd(), bucket.website.code))
|
|
61
62
|
: undefined;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const existingResourceState = (0, common_1.getResource)(state, logicalId);
|
|
64
|
+
const isTainted = existingResourceState?.status === 'tainted';
|
|
65
|
+
const existingBucketOnRetry = isTainted ? await client.tos.getBucket(bucket.name) : null;
|
|
66
|
+
if (existingBucketOnRetry) {
|
|
67
|
+
logger_1.logger.info(`Bucket ${bucket.name} already exists in provider (tainted recovery), skipping create`);
|
|
68
|
+
}
|
|
69
|
+
const taintedResourceState = {
|
|
70
|
+
mode: 'managed',
|
|
71
|
+
region: context.region,
|
|
72
|
+
definition: (0, tosTypes_1.extractTosBucketDefinition)(config, websiteCodeHash),
|
|
73
|
+
instances: existingBucketOnRetry
|
|
74
|
+
? [(0, tosTypes_1.buildTosInstanceFromProvider)(existingBucketOnRetry, sid)]
|
|
75
|
+
: [
|
|
76
|
+
{
|
|
77
|
+
type: 'VOLCENGINE_TOS_BUCKET',
|
|
78
|
+
sid,
|
|
79
|
+
id: bucket.name,
|
|
80
|
+
bucketName: bucket.name,
|
|
81
|
+
attributes: {},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
status: 'tainted',
|
|
85
|
+
lastUpdated: new Date().toISOString(),
|
|
86
|
+
};
|
|
87
|
+
const stateAfterDependents = (0, common_1.setResource)(state, logicalId, taintedResourceState);
|
|
88
|
+
try {
|
|
89
|
+
let bucketInfo;
|
|
90
|
+
if (existingBucketOnRetry) {
|
|
91
|
+
bucketInfo = existingBucketOnRetry;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
try {
|
|
95
|
+
await client.tos.createBucket(config);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
// TOS CreateBucket may be idempotent for the same account; a collision
|
|
99
|
+
// (BucketAlreadyExists) surfaces only for a bucket owned by another
|
|
100
|
+
// account. Treat it as non-fatal and fall through to the ownership probe
|
|
101
|
+
// below — an untagged pre-existing bucket is refused there.
|
|
102
|
+
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['BucketAlreadyExists'])) {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
logger_1.logger.info(`Bucket ${bucket.name} already exists in provider, verifying ownership tag before adopting`);
|
|
106
|
+
}
|
|
107
|
+
// CreateBucket succeeding does NOT prove the bucket is ours: a pre-existing
|
|
108
|
+
// bucket is returned idempotently. Only a bucket carrying our ownership tag
|
|
109
|
+
// may be adopted; an untagged one may belong to another project and must
|
|
110
|
+
// fail loudly rather than be silently taken over.
|
|
111
|
+
const probe = await client.tos.getBucket(bucket.name);
|
|
112
|
+
if (!probe) {
|
|
113
|
+
throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
|
|
114
|
+
}
|
|
115
|
+
if (!(0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.Tags)) {
|
|
116
|
+
throw new types_1.PartialResourceError(stateAfterDependents, 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 adopt — resolve manually.`));
|
|
117
|
+
}
|
|
118
|
+
bucketInfo = probe;
|
|
119
|
+
}
|
|
120
|
+
const instances = [(0, tosTypes_1.buildTosInstanceFromProvider)(bucketInfo, sid)];
|
|
121
|
+
if (bucket.website?.code) {
|
|
65
122
|
const codePath = node_path_1.default.resolve(process.cwd(), bucket.website.code);
|
|
66
123
|
await client.tos.uploadFiles(bucket.name, codePath);
|
|
67
124
|
const refreshedInfo = await client.tos.getBucket(bucket.name);
|
|
@@ -69,23 +126,21 @@ const createResource = async (context, bucket, state) => {
|
|
|
69
126
|
instances[0] = (0, tosTypes_1.buildTosInstanceFromProvider)(refreshedInfo, sid);
|
|
70
127
|
}
|
|
71
128
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
129
|
+
// Apply IAM bucket policy if configured
|
|
130
|
+
await applyBucketPolicy(client, bucket);
|
|
131
|
+
const resourceState = {
|
|
132
|
+
mode: 'managed',
|
|
133
|
+
region: context.region,
|
|
134
|
+
definition: (0, tosTypes_1.extractTosBucketDefinition)(config, websiteCodeHash),
|
|
135
|
+
instances,
|
|
136
|
+
status: 'ready',
|
|
137
|
+
lastUpdated: new Date().toISOString(),
|
|
138
|
+
};
|
|
139
|
+
return (0, common_1.setResource)(stateAfterDependents, logicalId, resourceState);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
78
143
|
}
|
|
79
|
-
// Apply IAM bucket policy if configured
|
|
80
|
-
await applyBucketPolicy(client, bucket);
|
|
81
|
-
const resourceState = {
|
|
82
|
-
mode: 'managed',
|
|
83
|
-
region: context.region,
|
|
84
|
-
definition: (0, tosTypes_1.extractTosBucketDefinition)(config, websiteCodeHash),
|
|
85
|
-
instances,
|
|
86
|
-
lastUpdated: new Date().toISOString(),
|
|
87
|
-
};
|
|
88
|
-
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
89
144
|
};
|
|
90
145
|
exports.createResource = createResource;
|
|
91
146
|
const readResource = async (context, bucketName) => {
|
|
@@ -67,6 +67,18 @@ const buildTosInstanceFromProvider = (info, sid) => {
|
|
|
67
67
|
errorDocument: info.websiteConfig.errorDocument ?? null,
|
|
68
68
|
}
|
|
69
69
|
: null,
|
|
70
|
+
Tags: info.Tags ?? null,
|
|
71
|
+
owner: info.owner ?? null,
|
|
72
|
+
projectName: info.projectName ?? null,
|
|
73
|
+
bucketType: info.type ?? null,
|
|
74
|
+
azRedundancy: info.azRedundancy ?? null,
|
|
75
|
+
extranetS3Endpoint: info.extranetS3Endpoint ?? null,
|
|
76
|
+
intranetS3Endpoint: info.intranetS3Endpoint ?? null,
|
|
77
|
+
versioning: info.versioning ?? null,
|
|
78
|
+
crossRegionReplication: info.crossRegionReplication ?? null,
|
|
79
|
+
transferAcceleration: info.transferAcceleration ?? null,
|
|
80
|
+
accessMonitor: info.accessMonitor ?? null,
|
|
81
|
+
serverSideEncryptionConfiguration: info.serverSideEncryptionConfiguration ?? null,
|
|
70
82
|
};
|
|
71
83
|
};
|
|
72
84
|
exports.buildTosInstanceFromProvider = buildTosInstanceFromProvider;
|
|
@@ -5,6 +5,7 @@ const types_1 = require("../../types");
|
|
|
5
5
|
const vefaasResource_1 = require("./vefaasResource");
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
7
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
8
9
|
const lang_1 = require("../../lang");
|
|
9
10
|
const executeCreateAction = async (context, fn, currentState) => {
|
|
10
11
|
common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', { resourceType: 'function', name: fn.name }));
|
|
@@ -62,21 +63,43 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
|
|
|
62
63
|
const successfulItems = [];
|
|
63
64
|
let currentState = initialState;
|
|
64
65
|
for (const item of plan.items) {
|
|
66
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
67
|
+
type: 'resource_pre',
|
|
68
|
+
logicalId: item.logicalId,
|
|
69
|
+
resourceType: item.resourceType,
|
|
70
|
+
action: item.action,
|
|
71
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
72
|
+
});
|
|
73
|
+
const startedAt = Date.now();
|
|
65
74
|
try {
|
|
66
75
|
const newState = await executeSingleItem(context, item, functionsMap, currentState);
|
|
67
76
|
if (newState !== null) {
|
|
68
77
|
currentState = newState;
|
|
69
78
|
successfulItems.push(item);
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_complete',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
durationMs: Date.now() - startedAt,
|
|
83
|
+
});
|
|
70
84
|
if (onStateChange) {
|
|
71
|
-
onStateChange(currentState);
|
|
85
|
+
await onStateChange(currentState);
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
catch (error) {
|
|
90
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
91
|
+
type: 'resource_failed',
|
|
92
|
+
logicalId: item.logicalId,
|
|
93
|
+
severity: 'error',
|
|
94
|
+
durationMs: Date.now() - startedAt,
|
|
95
|
+
error: {
|
|
96
|
+
message: error instanceof Error ? error.message : String(error),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
76
99
|
if (error instanceof types_1.PartialResourceError) {
|
|
77
100
|
const updatedState = error.updatedState;
|
|
78
101
|
if (onStateChange) {
|
|
79
|
-
onStateChange(updatedState);
|
|
102
|
+
await onStateChange(updatedState);
|
|
80
103
|
}
|
|
81
104
|
return {
|
|
82
105
|
state: updatedState,
|
|
@@ -5,6 +5,7 @@ const common_1 = require("../../common");
|
|
|
5
5
|
const stateManager_1 = require("../../common/stateManager");
|
|
6
6
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
7
7
|
const vefaasTypes_1 = require("./vefaasTypes");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
const planFunctionDeletion = (logicalId, definition) => ({
|
|
9
10
|
logicalId,
|
|
10
11
|
action: 'delete',
|
|
@@ -25,10 +26,64 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
25
26
|
const currentState = (0, common_1.getResource)(state, logicalId);
|
|
26
27
|
const config = (0, vefaasTypes_1.functionToVefaasConfig)(fn);
|
|
27
28
|
const codePath = fn.code.path;
|
|
28
|
-
const desiredCodeHash = (0, common_1.
|
|
29
|
+
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
30
|
+
// Mirror the executor's auto-role behavior: when the YAML omits
|
|
31
|
+
// `iam.role`, the executor reuses the IAM role recorded in state
|
|
32
|
+
// (createDependentResources persists a VOLCENGINE_IAM_ROLE instance and
|
|
33
|
+
// reuses it on subsequent deploys). Deriving the same trn here keeps the
|
|
34
|
+
// plan's desired definition in sync with what the executor will apply —
|
|
35
|
+
// otherwise every plan shows a phantom `role: <trn> -> null` drift.
|
|
36
|
+
if (!fn.iam && currentState?.instances?.length) {
|
|
37
|
+
const roleInstance = currentState.instances.find((i) => i.type === 'VOLCENGINE_IAM_ROLE');
|
|
38
|
+
if (roleInstance?.trn) {
|
|
39
|
+
config.role = roleInstance.trn;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Mirror the executor's TLS log-resource behavior: functionToVefaasConfig(fn)
|
|
43
|
+
// never sets logConfig on its own (it's only populated via the second
|
|
44
|
+
// `options` argument), so without this the diff below always compares
|
|
45
|
+
// desiredDefinition.logConfig === undefined regardless of `fn.log` in the
|
|
46
|
+
// YAML — meaning `log: true` could never be detected as drift and the
|
|
47
|
+
// planner would report `noop` forever, so `UpdateFunction`'s `TlsConfig`
|
|
48
|
+
// never gets sent. Derive the same project/topic names the executor
|
|
49
|
+
// would use (shared stage slot → tracked topic instance → deterministic
|
|
50
|
+
// shared names `${app}-${stage}-tls` / `${service}-${stage}-fn-logs`) so
|
|
51
|
+
// the diff can see the field change without phantom drift.
|
|
52
|
+
if (fn.log) {
|
|
53
|
+
const tlsTopicInstance = currentState?.instances?.find((i) => i.type === 'VOLCENGINE_TLS_TOPIC');
|
|
54
|
+
const shared = (0, stateManager_1.getSharedResource)(state, context.stage, 'logs.project');
|
|
55
|
+
if (tlsTopicInstance?.id) {
|
|
56
|
+
const [projectName, topicName] = tlsTopicInstance.id.split('/');
|
|
57
|
+
config.logConfig = { project: projectName, topic: topicName };
|
|
58
|
+
}
|
|
59
|
+
else if (shared) {
|
|
60
|
+
const projectName = shared.instances?.[0]?.id;
|
|
61
|
+
if (projectName) {
|
|
62
|
+
config.logConfig = {
|
|
63
|
+
project: projectName,
|
|
64
|
+
topic: `${context.service}-${context.stage}-fn-logs`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
config.logConfig = {
|
|
70
|
+
project: `${context.app}-${context.stage}-tls`,
|
|
71
|
+
topic: `${context.service}-${context.stage}-fn-logs`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
29
75
|
const baseDefinition = (0, vefaasTypes_1.extractVefaasDefinition)(config, desiredCodeHash);
|
|
30
76
|
const desiredDefinition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
31
77
|
if (!currentState || currentState.status === 'tainted') {
|
|
78
|
+
// No usable local state: probe the provider before planning create.
|
|
79
|
+
// If a same-named function already exists WITHOUT our ownership tag it
|
|
80
|
+
// may belong to another project — fail fast in the plan instead of
|
|
81
|
+
// letting the executor discover it mid-deploy.
|
|
82
|
+
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
83
|
+
const remoteFunction = await client.vefaas.getFunction(fn.name);
|
|
84
|
+
if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.Tags)) {
|
|
85
|
+
throw new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
86
|
+
}
|
|
32
87
|
return {
|
|
33
88
|
logicalId,
|
|
34
89
|
action: 'create',
|
|
@@ -53,7 +108,28 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
53
108
|
}
|
|
54
109
|
const currentDefinition = currentState.definition || {};
|
|
55
110
|
const definitionChanged = !(0, common_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
56
|
-
|
|
111
|
+
// Drift detection against the LIVE provider: compare the remote
|
|
112
|
+
// function's actual attributes (runtime/handler/memory/timeout/env)
|
|
113
|
+
// against the desired definition. Console edits would otherwise go
|
|
114
|
+
// undetected — definitionChanged only sees local-vs-desired.
|
|
115
|
+
const remoteAttributes = {
|
|
116
|
+
runtime: remoteFunction.runtime,
|
|
117
|
+
handler: remoteFunction.handler,
|
|
118
|
+
memorySize: remoteFunction.memoryMb,
|
|
119
|
+
timeout: remoteFunction.requestTimeout,
|
|
120
|
+
environment: remoteFunction.environmentVariables,
|
|
121
|
+
// Provider responses carry `null` for unset fields while the desired
|
|
122
|
+
// definition carries `undefined` — normalize null → undefined so the
|
|
123
|
+
// comparison ignores the representation difference.
|
|
124
|
+
description: remoteFunction.description ?? undefined,
|
|
125
|
+
role: remoteFunction.role ?? undefined,
|
|
126
|
+
vpcConfig: remoteFunction.vpcConfig ?? undefined,
|
|
127
|
+
logConfig: remoteFunction.logConfig
|
|
128
|
+
? { project: remoteFunction.logConfig.project, topic: remoteFunction.logConfig.topic }
|
|
129
|
+
: undefined,
|
|
130
|
+
};
|
|
131
|
+
const remoteMatchesDesired = (0, common_1.attributesEqual)(remoteAttributes, desiredDefinition);
|
|
132
|
+
if (definitionChanged || !remoteMatchesDesired) {
|
|
57
133
|
return {
|
|
58
134
|
logicalId,
|
|
59
135
|
action: 'update',
|