Skip to content

Docs/wasm function support#4419

Open
SurbhiAgarwal1 wants to merge 1 commit intokptdev:mainfrom
SurbhiAgarwal1:docs/wasm-function-support
Open

Docs/wasm function support#4419
SurbhiAgarwal1 wants to merge 1 commit intokptdev:mainfrom
SurbhiAgarwal1:docs/wasm-function-support

Conversation

@SurbhiAgarwal1
Copy link
Contributor

Description

WASM functions are supported in kpt but there's no documentation on how to run, develop, or deploy them. This PR adds a comprehensive guide covering the complete WASM function workflow.

Motivation

Users need documentation to understand:

  • How to run WASM functions with the --allow-alpha-wasm flag
  • How to publish WASM modules using kpt alpha wasm push/pull
  • How to develop WASM functions with proper build tags
  • The benefits and limitations of WASM functions vs container-based functions

Without this documentation, users have to dig through code or CLI help to figure out WASM support.

Changes

Added documentation/content/en/book/04-using-functions/wasm-functions.md covering:

  • Running WASM functions with fn render and fn eval
  • Publishing and pulling WASM modules to/from OCI registries
  • Developing Go-based WASM functions with complete code examples
  • Benefits (faster startup, smaller size, better security)
  • Limitations (alpha status, sandboxed execution, compatibility)

The code examples are based on actual WASM functions in krm-functions-catalog (set-namespace, set-labels, starlark) and follow the same pattern with separate build tags for regular and WASM builds.

Fixes #4296

Copilot AI review requested due to automatic review settings February 28, 2026 17:38
@netlify
Copy link

netlify bot commented Feb 28, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 1abf41f
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69a32e0dad545d000849f0e2
😎 Deploy Preview https://deploy-preview-4419--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. documentation Improvements or additions to documentation labels Feb 28, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-user documentation for running/developing/publishing WASM functions in kpt, and (in the same change set) introduces a new CEL-based condition field on Kptfile pipeline functions to enable conditional function execution.

Changes:

  • Adds a comprehensive “Using WASM Functions” guide (run, eval, push/pull, Go build tags, limitations).
  • Extends kptfile.v1.Function with a condition field and evaluates it before executing a function.
  • Adds a CEL evaluator implementation + unit/E2E-style tests, and updates Go module dependencies for CEL.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/api/kptfile/v1/types.go Adds Function.Condition (CEL) field to the Kptfile API.
internal/fnruntime/runner.go Initializes and uses a CEL evaluator to skip function execution when condition is false.
internal/fnruntime/celeval.go New CEL evaluator implementation for evaluating conditions against resource inputs.
internal/fnruntime/celeval_test.go Unit tests for CEL evaluator behavior and errors.
internal/fnruntime/conditional_e2e_test.go End-to-end style tests for conditional execution behavior in FunctionRunner.
go.mod / go.sum Adds github.com/google/cel-go and related transitive dependencies.
documentation/content/en/book/04-using-functions/wasm-functions.md New documentation page describing the WASM function workflow in kpt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 58 to 92
// Create the program with cost tracking to prevent resource exhaustion
// This enforces a runtime cost limit similar to Kubernetes ValidatingAdmissionPolicy
prg, err := env.Program(ast, cel.CostTracking(nil))
if err != nil {
return nil, fmt.Errorf("failed to create CEL program: %w", err)
}

evaluator.prg = prg
}

return evaluator, nil
}


// EvaluateCondition evaluates a CEL condition expression against a list of resources
// Returns true if the condition is met, false otherwise
// The program is pre-compiled, so this just evaluates it with the given resources
func (e *CELEvaluator) EvaluateCondition(_ context.Context, resources []*yaml.RNode) (bool, error) {
if e.prg == nil {
return true, nil
}

// Convert resources to a format suitable for CEL
resourceList, err := e.resourcesToList(resources)
if err != nil {
return false, fmt.Errorf("failed to convert resources: %w", err)
}

// Evaluate the expression
out, _, err := e.prg.Eval(map[string]interface{}{
"resources": resourceList,
})
if err != nil {
return false, fmt.Errorf("failed to evaluate CEL expression: %w", err)
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code comment claims a “runtime cost limit” is enforced, but evaluation currently ignores the returned evaluation details/cost and does not apply any explicit limit. For untrusted packages, a pathological CEL expression could still cause high CPU/memory usage during kpt fn render. Consider enforcing an explicit cost limit (and failing closed when exceeded) and/or bounding input size, and update the comment accordingly.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +96
1. Compresses the WASM file into a tar archive
2. Creates an OCI image with `wasm/js` platform
3. Pushes to the registry
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same platform string issue as above: “wasm/js” is ambiguous; prefer “OS=js, arch=wasm” (or the correct OS/arch ordering) so users can match what registries/tools display.

Copilot uses AI. Check for mistakes.
Comment on lines 343 to 355
// `Condition` is an optional CEL expression that determines whether this
// function should be executed. The expression is evaluated against the KRM
// resources in the package and should return a boolean value.
// If omitted or evaluates to true, the function executes normally.
// If evaluates to false, the function is skipped.
//
// Example: Check if a specific ConfigMap exists:
// condition: "resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'my-config')"
//
// Example: Check resource count:
// condition: "resources.filter(r, r.kind == 'Deployment').size() > 0"
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"`
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title/description is about documenting WASM function support, but this change introduces a new condition field (CEL-based conditional execution) in the public Kptfile API and wires it into function execution. Either update the PR metadata/scope to include this feature (and its docs), or split the conditional-execution changes into a separate PR so reviewers/users can evaluate the API/behavior change independently.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 28, 2026 17:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 343 to 346
// `Condition` is an optional CEL expression that determines whether this
// function should be executed. The expression is evaluated against the KRM
// resources selected for this function (after applying Selectors and Exclusions)
// and should return a boolean value.
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The struct comment says the CEL expression is evaluated against the KRM resources in the package, but the current implementation evaluates the condition on the (potentially selector/exclusion-filtered) input passed to the function runner. Either adjust the implementation to evaluate against the full package pipeline input, or update this comment to match the actual semantics.

Copilot uses AI. Check for mistakes.
Comment on lines 58 to 59
// Create the program with cost tracking to prevent resource exhaustion
// This enforces a runtime cost limit similar to Kubernetes ValidatingAdmissionPolicy
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says cost tracking is used “to prevent resource exhaustion” / enforce a runtime cost limit, but the code only enables CostTracking without any explicit cost limit or enforcement. Either add an actual cost limit (and fail evaluation when exceeded) or adjust the comment so it doesn’t claim protections that aren’t implemented.

Suggested change
// Create the program with cost tracking to prevent resource exhaustion
// This enforces a runtime cost limit similar to Kubernetes ValidatingAdmissionPolicy
// Create the program with cost tracking enabled for observability and analysis.

Copilot uses AI. Check for mistakes.
Comment on lines +282 to +287
### Security

WASM functions run in a sandbox:
- No network access
- No filesystem access (except input/output resources)
- Can't execute system commands
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Security” section states WASM functions have no network/filesystem access and no host access by default. kpt supports both wasmtime (default) and node.js-based runtimes (selectable via KPT_FN_WASM_RUNTIME), and the node.js runtime can expose broader host capabilities to Go WASM via syscall/js. Please qualify these claims (e.g., “with wasmtime runtime…”) to avoid overstating the sandbox guarantees.

Copilot uses AI. Check for mistakes.
Comment on lines 348 to 349
// If evaluates to false, the function is skipped.
//
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a blank comment line with trailing whitespace here (// ). Please remove the trailing space to avoid whitespace-only diffs / lint noise.

Copilot uses AI. Check for mistakes.
Add comprehensive documentation for WASM function support in kpt,
covering how to run, develop, and deploy WASM functions.

Closes kptdev#4296

Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
@SurbhiAgarwal1 SurbhiAgarwal1 force-pushed the docs/wasm-function-support branch from e979fbb to 1abf41f Compare February 28, 2026 18:03
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document WASM function support in kpt

2 participants