Skip to content

feat: add builtin runtime support#4430

Open
abdulrahman11a wants to merge 2 commits intokptdev:mainfrom
abdulrahman11a:feature/builtin-runtime
Open

feat: add builtin runtime support#4430
abdulrahman11a wants to merge 2 commits intokptdev:mainfrom
abdulrahman11a:feature/builtin-runtime

Conversation

@abdulrahman11a
Copy link
Copy Markdown

Summary

Closes #4307

This PR implements a built-in runtime for curated KRM functions inside kpt itself,
allowing apply-replacements and starlark to run without pulling images from Docker Hub.

Approach

As discussed in the issue thread, this implementation avoids reintroducing a circular
dependency between Porch and kpt by moving the built-in runtime concept into kpt directly.
The architecture is intentionally simple and extensible — new functions can be added
incrementally by registering them in the builtin registry.

How it works

A thread-safe self-registration registry (internal/builtins/registry) allows KRM function
implementations to register themselves via init(). The fnruntime runner checks this
registry before falling back to Docker or WASM, so existing behavior is fully preserved
for unregistered functions.

Priority order in fnruntime/runner.go:

  1. pkg-context builtin (existing)
  2. Builtin registry ← new, no Docker needed
  3. Docker / WASM (fallback, unchanged)

Functions included

Function Image
apply-replacements ghcr.io/kptdev/krm-functions-catalog/apply-replacements
starlark ghcr.io/kptdev/krm-functions-catalog/starlark

Files changed

File Description
internal/builtins/registry/registry.go Thread-safe self-registration registry
internal/builtins/applyreplacements/apply_replacements.go Built-in apply-replacements implementation
internal/builtins/starlark/starlark.go Built-in starlark entry point
internal/builtins/starlark/config.go Starlark config parser (accepts StarlarkRun and Run kinds)
internal/builtins/starlark/processor.go Starlark processor
internal/builtins/BuiltinRuntime.go Blank-imports all builtins to trigger init()
internal/fnruntime/runner.go Wires builtin registry lookup before Docker fallback

Verified locally

[PASS] "ghcr.io/kptdev/krm-functions-catalog/apply-replacements:v0.1.1" in 0s
[PASS] "ghcr.io/kptdev/krm-functions-catalog/starlark:v0.5.0" in 0s

Both functions execute without Docker running.
image

Next steps

  • More curated functions can be gradually inlined following the same pattern
  • WASM support remains a separate investigation track as suggested in the issue

Copilot AI review requested due to automatic review settings March 12, 2026 21:22
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 12, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 267c21e
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69cc4b303a6f7e0008ed332f
😎 Deploy Preview https://deploy-preview-4430--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. area/fn-runtime KRM function runtime labels Mar 12, 2026
Copy link
Copy Markdown
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 implements a built-in runtime for curated KRM functions (apply-replacements and starlark) inside kpt itself, allowing them to run without Docker by registering them in a thread-safe in-process registry. When a function image matches a registered builtin (by normalized name, ignoring tags/digests), the builtin is used; otherwise the existing Docker/WASM fallback is preserved.

Changes:

  • New self-registration registry (internal/builtins/registry/) with thread-safe Register/Lookup using image name normalization
  • Built-in implementations for apply-replacements and starlark functions, wired via init() blank imports
  • Integration into fnruntime/runner.go to check the builtin registry before falling back to Docker/WASM

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/builtins/registry/registry.go Thread-safe builtin function registry with image name normalization
internal/builtins/applyreplacements/apply_replacements.go Built-in apply-replacements KRM function implementation
internal/builtins/starlark/starlark.go Built-in starlark KRM function entry point
internal/builtins/starlark/config.go Starlark config parser supporting StarlarkRun, Run, and ConfigMap kinds
internal/builtins/starlark/processor.go Starlark processing logic
internal/builtins/starlark/config_test.go Tests for starlark config parsing
internal/builtins/BuiltinRuntime.go Blank-imports all builtins to trigger init() registration
internal/fnruntime/runner.go Wires builtin registry lookup between pkg-context and Docker/WASM
go.mod / go.sum Adds starlark catalog dependency and upgrades fn SDK to v1.0.2

💡 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.

Signed-off-by: Abdulrahman Fikry <abdulrahmanfikry1@gmail.com>
@abdulrahman11a abdulrahman11a force-pushed the feature/builtin-runtime branch from 446b055 to 4bdb97c Compare March 12, 2026 21:33
Copilot AI review requested due to automatic review settings March 24, 2026 14:26
Copy link
Copy Markdown
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 9 out of 10 changed files in this pull request and generated 5 comments.


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

Signed-off-by: Abdulrahman Fikry <abdulrahmanfikry1@gmail.com>
Signed-off-by: abdulrahman11a <abdulrahmanfikry1@gmail.com>
@abdulrahman11a abdulrahman11a force-pushed the feature/builtin-runtime branch from d83136d to 267c21e Compare March 31, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/fn-runtime KRM function runtime size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

maintain a set of curated kpt functions which can be run without pulling stuff from docker hub

2 participants