Skip to content

Docs/wasm function support#4419

Open
SurbhiAgarwal1 wants to merge 3 commits intokptdev:mainfrom
SurbhiAgarwal1:docs/wasm-function-support
Open

Docs/wasm function support#4419
SurbhiAgarwal1 wants to merge 3 commits 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 46f7f9a
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69a90aa01d05b600084db938
😎 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
Contributor

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 +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.
Copilot AI review requested due to automatic review settings February 28, 2026 17:45
Copy link
Contributor

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 +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.
@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
@liamfallon liamfallon requested a review from Copilot March 4, 2026 18:58
Copy link
Contributor

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 1 out of 1 changed files in this pull request and generated 3 comments.


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

You can also share your feedback on Copilot code review. Take the survey.


What this does:
1. Compresses the WASM file into a tar archive
2. Creates an OCI image with `wasm/js` platform
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The same incorrect wasm/js platform identifier is used here. It should be js/wasm to match the OCI convention of OS/Architecture, consistent with the code in pkg/wasm/client.go:122-124 where OS: "js" and Architecture: "wasm".

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +151
Here's how to build a Go KRM function for WASM. You need two files - one for regular builds and one for WASM:

`main.go` (regular build):

```go
//go:build !(js && wasm)

package main

import (
"os"

"github.com/kptdev/krm-functions-sdk/go/fn"
)

func main() {
if err := fn.AsMain(fn.ResourceListProcessorFunc(process)); err != nil {
os.Exit(1)
}
}

func process(rl *fn.ResourceList) (bool, error) {
for i := range rl.Items {
// Your transformation logic
rl.Items[i].SetAnnotation("processed-by", "my-fn")
}
return true, nil
}
```
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The code example has a compilation issue: main.go defines the process function with the build tag //go:build !(js && wasm), meaning it is excluded during WASM builds. However, main_js.go (with build tag //go:build js && wasm) references process on line 184 via fn.ResourceListProcessorFunc(process). Since process is not available during WASM builds, this code will fail to compile with GOOS=js GOARCH=wasm.

The process function should be placed in a third file (e.g., process.go) without any build tags, so it's available for both regular and WASM builds. This is the typical pattern used in the referenced krm-functions-catalog.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 4, 2026 19:25
Copy link
Contributor

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 1 out of 1 changed files in this pull request and generated 2 comments.


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

Comment on lines +95 to +96
2. Creates an OCI image with `wasm/js` platform
3. Pushes to the registry
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The platform format wasm/js here is inconsistent with OCI conventions. The OCI platform format is OS/Architecture, and looking at pkg/wasm/client.go:122-125, the platform is {OS: "js", Architecture: "wasm"}. This should be written as js/wasm to match the standard OCI platform format.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 5, 2026 04:11
Copy link
Contributor

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 1 out of 1 changed files in this pull request and generated 1 comment.


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

Comment on lines +186 to +187
// TODO: copy the implementation from main.go so behavior is consistent.
return false, nil
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

This example process function in the WASM build file has a TODO comment and returns false, nil without implementing any transformation logic. A user copying this documentation example would get a WASM function that does nothing (and returns false indicating no changes). The main.go version adds an annotation, but this version doesn't.

For a documentation example, the implementation should be consistent between the two files. Either duplicate the logic (adding the annotation) here, or refactor the example to show the recommended pattern of extracting shared logic into a separate file (e.g., processor.go) with no build tags, so both builds share the same process function. The latter pattern avoids the exact problem this code demonstrates — divergent implementations in WASM and non-WASM builds.

Suggested change
// TODO: copy the implementation from main.go so behavior is consistent.
return false, nil
changed := false
const annotationKey = "example.com/wasm"
const annotationValue = "processed"
for _, obj := range rl.Items {
if obj == nil {
continue
}
annotations := obj.GetAnnotations()
if existing, ok := annotations[annotationKey]; ok && existing == annotationValue {
continue
}
obj.SetAnnotation(annotationKey, annotationValue)
changed = true
}
return changed, nil

Copilot uses AI. Check for mistakes.
SurbhiAgarwal1 and others added 3 commits March 5, 2026 10:15
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>
…s.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
…s.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
@SurbhiAgarwal1 SurbhiAgarwal1 force-pushed the docs/wasm-function-support branch from 5b119ee to 46f7f9a Compare March 5, 2026 04:46
@SurbhiAgarwal1 SurbhiAgarwal1 requested a review from Copilot March 5, 2026 04:48
Copy link
Contributor

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 1 out of 1 changed files in this pull request and generated no new comments.


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

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