Skip to content

feat(volcengine): Phase 2 - veFaaS Function Service Support #181

@Blankll

Description

@Blankll

Phase 2: veFaaS Function Service Support

Parent Epic: #179
Depends on: Phase 1 (#PHASE1)

Overview

Implement full CRUD support for Volcengine's Function Service (veFaaS), enabling deploy, update, and destroy of serverless functions.

Service Information

Property Value
Service Name 函数服务 (veFaaS)
Documentation https://www.volcengine.com/docs/6662
SDK Package @volcengine/vefaas
API Version 2024-06-06

Supported Runtimes

python/3.10, python/3.9, python/3.8
nodejs/18, nodejs/16, nodejs/14
golang/1
java/11, java/8

Tasks

1. Type Definitions (vefaasTypes.ts)

// src/stack/volcengineStack/vefaasTypes.ts

export type VefaasFunctionConfig = {
  functionName: string;
  runtime: string;
  handler: string;
  memoryMb: number;
  requestTimeout: number;
  environmentVariables?: Record<string, string>;
  description?: string;
  vpcConfig?: {
    vpcId: string;
    subnetIds: string[];
    securityGroupIds: string[];
  };
  tosMountConfig?: {
    bucketName: string;
    mountPath: string;
  };
};

export type VefaasFunctionInfo = {
  functionId: string;
  functionName: string;
  runtime: string;
  handler: string;
  memoryMb: number;
  requestTimeout: number;
  environmentVariables?: Record<string, string>;
  status: string;
  createdTime: string;
  lastModifiedTime: string;
};

2. Client Operations (vefaasOperations.ts)

// src/common/volcengineClient/vefaasOperations.ts

export const createVefaasOperations = (client: VefaasClient) => ({
  createFunction: async (config: VefaasFunctionConfig, codePath: string): Promise<void> => {
    const code = fs.readFileSync(codePath);
    const command = new CreateFunctionCommand({
      Name: config.functionName,
      Runtime: config.runtime,
      Handler: config.handler,
      MemoryMb: config.memoryMb,
      RequestTimeout: config.requestTimeout,
      Code: { ZipFile: code.toString('base64') },
      Envs: config.environmentVariables,
    });
    await client.send(command);
  },
  
  getFunction: async (functionName: string): Promise<VefaasFunctionInfo | null> => {
    // Implement with error handling for NotFound
  },
  
  updateFunctionConfiguration: async (config: VefaasFunctionConfig): Promise<void> => { ... },
  updateFunctionCode: async (functionName: string, codePath: string): Promise<void> => { ... },
  deleteFunction: async (functionName: string): Promise<void> => { ... },
  listFunctions: async (): Promise<VefaasFunctionInfo[]> => { ... },
});

3. Resource Implementation (vefaasResource.ts)

Implement four lifecycle functions:

export const createResource = async (
  context: Context,
  fn: FunctionDomain,
  state: StateFile,
): Promise<StateFile> => {
  // 1. Create dependent resources (IAM role if needed)
  // 2. Upload code to TOS if large
  // 3. Create function
  // 4. Update state
};

export const readResource = async (
  context: Context, 
  functionName: string
): Promise<VefaasFunctionInfo | null> => { ... };

export const updateResource = async (
  context: Context,
  fn: FunctionDomain,
  state: StateFile,
): Promise<StateFile> => { ... };

export const deleteResource = async (
  context: Context,
  functionName: string,
  logicalId: string,
  state: StateFile,
): Promise<StateFile> => { ... };

4. Planner (vefaasPlanner.ts)

  • Implement generateVefaasPlan() function
  • Compare desired state vs current state
  • Generate CREATE/UPDATE/DELETE actions
  • Handle code hash comparison for code changes

5. Executor (vefaasExecutor.ts)

  • Implement executeVefaasPlan() function
  • Execute plans in order
  • Handle partial failures
  • Update state after each operation

6. Integration

  • Update volcengineStack/planner.ts to include vefaas planner
  • Update volcengineStack/deployer.ts to execute vefaas plan
  • Update volcengineStack/destroyer.ts to delete functions

Function Configuration Mapping

YAML Field veFaaS API Field Notes
name Name Required
code.runtime Runtime e.g., "nodejs/18"
code.handler Handler e.g., "index.handler"
code.path Code.ZipFile Base64 encoded
memory MemoryMb Default: 128
timeout RequestTimeout Default: 30
environment Envs Key-value pairs
network.vpc_id VpcConfig.VpcId Optional
network.subnet_ids VpcConfig.SubnetIds Optional

Sample Configuration

# samples/volcengine-poc-function.yml
version: 0.1.0
provider:
  name: volcengine
  region: cn-beijing

app: insight-poc
service: insight-poc-vefaas

functions:
  hello_function:
    name: insight-poc-hello
    code:
      runtime: nodejs/18
      handler: index.handler
      path: ./artifacts/function.zip
    memory: 256
    timeout: 30
    environment:
      NODE_ENV: production

Acceptance Criteria

Must Have

  • si deploy -f samples/volcengine-poc-function.yml creates function in Volcengine
  • si deploy (second run) detects no changes
  • si deploy with code changes updates function code
  • si deploy with config changes updates function configuration
  • si destroy removes function and cleans up state
  • State file correctly stores function metadata
  • Error messages are i18n formatted
  • npm test passes for vefaas-related tests

Should Have

  • VPC configuration support
  • Environment variable updates work correctly
  • Code hash used for change detection
  • Partial failure recovery works

Nice to Have

  • TOS mount configuration
  • NAS storage mounting
  • GPU function support

Test Cases

describe('vefaasResource', () => {
  it('should create a function with minimal config', async () => { ... });
  it('should create a function with environment variables', async () => { ... });
  it('should update function configuration', async () => { ... });
  it('should update function code', async () => { ... });
  it('should delete a function', async () => { ... });
  it('should handle function not found on delete', async () => { ... });
  it('should handle partial failure and save state', async () => { ... });
});

References

Estimated Effort

Large (5-7 days)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions