Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ s remove -y
rm -rf ./target
cd ..

echo "test php runtime with session config"
cd php
export fc_component_function_name=php-$(uname)-$(uname -m)-$RANDSTR
s deploy -y
s info
s remove -y
cd ..

echo "test custom go runtime ..."
cd custom
Expand Down
8 changes: 7 additions & 1 deletion __tests__/e2e/php/s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ resources:
code: ./code
timeout: 30
handler: index.handler
memorySize: 128
memorySize: 2048
instanceIsolationMode: SESSION_EXCLUSIVE
sessionAffinity: GENERATED_COOKIE
sessionAffinityConfig:
sessionConcurrencyPerInstance: 1
sessionIdleTimeoutInSeconds: 1800
sessionTTLInSeconds: 21600
4 changes: 4 additions & 0 deletions __tests__/it/integration_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ describe('Integration Tests', () => {
role: '',
runtime: 'python3.9',
timeout: 60,
instanceIsolationMode: "SHARE",
sessionAffinity: "NONE",
asyncInvokeConfig: undefined,
concurrencyConfig: undefined,
customDomain: undefined,
Expand Down Expand Up @@ -129,6 +131,8 @@ describe('Integration Tests', () => {
runtime: 'python3.9',
timeout: 60,
disableOndemand: false,
instanceIsolationMode: "SHARE",
sessionAffinity: "NONE",
triggers: [
{
description: 'xxxx',
Expand Down
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@alicloud/devs20230714": "^2.4.5",
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "4.3.4",
"@alicloud/fc20230330": "4.4.0",
"@alicloud/pop-core": "^1.8.0",
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
Expand Down
2 changes: 2 additions & 0 deletions src/default/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const FC_RESOURCES_EMPTY_CONFIG = {
},
environmentVariables: {},
layers: [],
instanceIsolationMode: 'SHARE',
sessionAffinity: 'NONE',
};

export const FC_TRIGGER_DEFAULT_CONFIG = {
Expand Down
10 changes: 10 additions & 0 deletions src/interface/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export interface ITracingConfig {
type?: string;
}

export interface ISessionAffinityConfig {
sessionConcurrencyPerInstance?: number;
sessionIdleTimeoutInSeconds?: number;
sessionTTLInSeconds?: number;
affinityHeaderFieldName?: string;
sseEndpointPath?: string;
}

export interface IVpcConfig {
securityGroupId: string;
vSwitchIds: string[] | 'auto';
Expand All @@ -126,6 +134,8 @@ export interface IFunction {
memorySize?: number;
timeout?: number;
sessionAffinity?: string;
sessionAffinityConfig?: ISessionAffinityConfig | string;
instanceIsolationMode?: string;
enableLongLiving?: boolean;

logConfig?: 'auto' | ILogConfig;
Expand Down
4 changes: 4 additions & 0 deletions src/resources/fc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ export default class FC extends FC_Client {
_.unset(body.customContainerConfig, 'entrypoint');
}

if (body.sessionAffinityConfig) {
body.sessionAffinityConfig = JSON.parse(body.sessionAffinityConfig);
}

if (body.layers) {
logger.debug(body.layers);
const newLayers = [];
Expand Down
33 changes: 33 additions & 0 deletions src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,26 @@
],
"type": "string"
},
"ISessionAffinityConfig": {
"properties": {
"affinityHeaderFieldName": {
"type": "string"
},
"sessionConcurrencyPerInstance": {
"type": "number"
},
"sessionIdleTimeoutInSeconds": {
"type": "number"
},
"sessionTTLInSeconds": {
"type": "number"
},
"sseEndpointPath": {
"type": "string"
}
},
"type": "object"
},
"ITags": {
"properties": {
"key": {
Expand Down Expand Up @@ -1173,6 +1193,9 @@
"handler": {
"type": "string"
},
"instanceIsolationMode": {
"type": "string"
},
"instanceLifecycleConfig": {
"properties": {
"initializer": {
Expand Down Expand Up @@ -1240,6 +1263,16 @@
"sessionAffinity": {
"type": "string"
},
"sessionAffinityConfig": {
"anyOf": [
{
"$ref": "#/definitions/ISessionAffinityConfig"
},
{
"type": "string"
}
]
},
"tags": {
"items": {
"$ref": "#/definitions/ITags"
Expand Down
18 changes: 16 additions & 2 deletions src/subCommands/deploy/impl/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ export default class Service extends Base {
await this._pushImage();
}
}

// 部署函数
const config = _.defaults(this.local, FC_RESOURCES_EMPTY_CONFIG);
if (
!_.isEmpty(config.sessionAffinityConfig) &&
typeof config.sessionAffinityConfig !== 'string'
) {
logger.debug('sessionAffinityConfig', config.sessionAffinityConfig);
config.sessionAffinityConfig = JSON.stringify(config.sessionAffinityConfig);
}
await this.fcSdk.deployFunction(config, {
slsAuto: !_.isEmpty(this.createResource.sls),
type: this.type,
Expand Down Expand Up @@ -146,6 +152,14 @@ export default class Service extends Base {
_.unset(this.remote, 'resourceGroupId');
}

if (_.get(this.remote, 'instanceIsolationMode') === 'SHARE') {
_.unset(this.remote, 'instanceIsolationMode');
}

if (_.get(this.remote, 'sessionAffinity') === 'NONE') {
_.unset(this.remote, 'sessionAffinity');
}

_.unset(this.local, 'endpoint');
const { code } = this.local;
_.unset(this.local, 'code');
Expand Down Expand Up @@ -390,7 +404,7 @@ vpcConfig:
_.set(this.local, 'vpcConfig', vpcConfig);
}
if (nasAuto) {
let modelConfig = supplement?.modelConfig || annotations?.modelConfig;
const modelConfig = supplement?.modelConfig || annotations?.modelConfig;

logger.write(
yellow(`Created nas resource succeeded, please replace nasConfig: auto in yaml with:
Expand Down
4 changes: 2 additions & 2 deletions src/subCommands/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ mountPoints:

private parseNasConfig(nasConfig: any) {
let nasMountDomain: string;
let nasMountPath: string = '';
let nasMountPath = '';

let serverAddr = nasConfig.mountPoints[0].serverAddr;
const { serverAddr } = nasConfig.mountPoints[0];
const parts = serverAddr.split(':', 2);

if (parts.length === 2) {
Expand Down
6 changes: 6 additions & 0 deletions src/subCommands/plan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export default class Plan {
if (_.get(remote, 'resourceGroupId')) {
_.unset(remote, 'resourceGroupId');
}
if (_.get(remote, 'instanceIsolationMode') === 'SHARE') {
_.unset(remote, 'instanceIsolationMode');
}
if (_.get(remote, 'sessionAffinity') === 'NONE') {
_.unset(remote, 'sessionAffinity');
}
const config = FC.replaceFunctionConfig(local, remote);
return diffConvertPlanYaml(config.remote, config.local, { deep: 0, complete: true });
}
Expand Down