Skip to content

Commit 2547c99

Browse files
committed
copy suggestions from Dosu with some changes
Co-authored-by: dosubot
1 parent 2053c84 commit 2547c99

8 files changed

Lines changed: 928 additions & 84 deletions

File tree

docs/content/en/docs/2_concepts/functions.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: |
99
## What are Functions in Porch?
1010

1111
**Functions** in Porch are [KRM (Kubernetes Resource Model) functions](https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md) -
12-
containerized programs that transform or validate Kubernetes resource manifests within a package's files. Functions are
12+
programs (usually containerized) that transform or validate Kubernetes resource manifests within a package's files. Functions are
1313
declared in a package's Kptfile and executed by Porch when rendering the package.
1414

1515
Functions enable:
@@ -20,9 +20,68 @@ Functions enable:
2020

2121
For details on how to declare and configure functions in the Kptfile pipeline, see the [kpt functions documentation](https://kpt.dev/book/04-using-functions/).
2222

23+
## Function Configuration
24+
25+
Porch uses **FunctionConfig** custom resources to configure how functions execute. These configurations specify which executor type should handle specific function images and provide executor-specific settings.
26+
27+
Each FunctionConfig specifies:
28+
- **Image and prefixes**: The function image name and optional registry prefixes
29+
- **Executor configurations**: One or more executor types (pod, binary, or go) with associated settings
30+
- **Version-specific settings**: Different executors and configurations for different image tags
31+
32+
Example FunctionConfig:
33+
34+
```yaml
35+
apiVersion: config.porch.kpt.dev/v1alpha1
36+
kind: FunctionConfig
37+
metadata:
38+
name: set-namespace
39+
namespace: porch-fn-system
40+
spec:
41+
image: set-namespace
42+
prefixes:
43+
- ""
44+
- ghcr.io/kptdev/krm-functions-catalog
45+
podExecutor:
46+
tags:
47+
- v0.4.1
48+
timeToLive: 30m
49+
binaryExecutor:
50+
tags:
51+
- v0.4.2
52+
path: set-namespace
53+
goExecutor:
54+
id: set-namespace
55+
tags:
56+
- v0.4
57+
- v0.4.5
58+
```
59+
60+
Both the function-runner and porch-server components include an embedded FunctionConfig reconciler that watches FunctionConfig resources and populates an internal cache. This cache determines which executor to use for each function invocation.
61+
2362
## Function Execution in Porch
2463
25-
Porch executes functions through a **function runner** component that calls kpt to orchestrate containerized function execution. The functions run in isolated containers (Kubernetes pods managed by the `function-runner` microservice). Porch passes the package's resources to kpt, which passes the resources on as a [ResourceList](https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md#resourcelist) to each function in the pipeline in turn. kpt executes the functions sequentially in the order declared in the Kptfile pipeline and passes the function results back to Porch, which stores them in the PackageRevisionResources's `status.renderStatus` field. Execution is triggered automatically following creation or clone of a package revision, update of a package revision, and when a package revision is proposed.
64+
Porch executes functions using multiple executor types, determined by FunctionConfig settings.
65+
66+
**Pod Executor**: Runs functions in isolated containerized pods (the traditional approach):
67+
- Functions execute in Kubernetes pods managed by the `function-runner` microservice
68+
- Configurable with pod templates, resource limits, TTL settings, and maximum parallel executions
69+
- Suitable for functions requiring container isolation or external dependencies
70+
71+
**Binary Executor**: Substitutes specific function image tags with local binary executables:
72+
- Executes pre-built function binaries directly on the host system
73+
- Provides improved performance by avoiding container overhead
74+
- Configured with the file path to the function binary
75+
76+
**Go Executor**: Executes certain functions as native Go function calls within the porch-server process:
77+
- Functions run in-process for maximum efficiency
78+
- Only available for functions integrated as Go libraries
79+
- No container or process overhead
80+
81+
Regardless of executor type, Porch passes the package's resources to kpt, which passes the resources on as a [ResourceList](https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md#resourcelist) to each function in the pipeline in turn.
82+
kpt executes the functions sequentially in the order declared in the Kptfile pipeline and passes the function results back to Porch, which stores them in the PackageRevisionResources's `status.renderStatus` field.
83+
Execution is triggered automatically following creation or clone of a package revision, update of a package revision, and when a package revision is proposed.
84+
kpt passes the function results back to Porch and Porch stores them in the PackageRevisionResources's `status.renderStatus` field.
2685

2786
## When Functions Execute
2887

@@ -77,7 +136,9 @@ enabling iterative development on incomplete packages.
77136
## Key Points
78137
79138
- Functions are standard KRM functions declared in the Kptfile pipeline (see [kpt functions docs](https://kpt.dev/book/04-using-functions/))
80-
- Porch invokes kpt to execute functions via a function-runner component using containerized execution
139+
- Function execution behavior is configured using FunctionConfig custom resources that specify executor types (pod, binary, or go)
140+
- Both function-runner and porch-server include FunctionConfig reconcilers that populate internal caches to determine which executor handles each function
141+
- Functions can execute via pod containers, local binaries, or in-process Go calls depending on configuration
81142
- Functions automatically execute during package rendering on Draft package revisions
82143
- Function results are stored in `status.renderStatus` of the PackageRevisionResources view of a package revision
83144
- Published packages are immutable - functions don't re-execute after publication

docs/content/en/docs/3_getting_started/installing-porch.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,54 @@ kubectl api-resources | grep porch
7272
You should see Porch API resources:
7373

7474
```bash
75+
functionconfigs config.porch.kpt.dev/v1alpha1 true FunctionConfig
7576
packagerevs config.porch.kpt.dev/v1alpha1 true PackageRev
7677
packagevariants config.porch.kpt.dev/v1alpha1 true PackageVariant
7778
packagevariantsets config.porch.kpt.dev/v1alpha2 true PackageVariantSet
7879
repositories config.porch.kpt.dev/v1alpha1 true Repository
80+
servicetemplates config.porch.kpt.dev/v1alpha1 true ServiceTemplate
7981
packagerevisionresources porch.kpt.dev/v1alpha1 true PackageRevisionResources
8082
packagerevisions porch.kpt.dev/v1alpha1 true PackageRevision
8183
packages porch.kpt.dev/v1alpha1 true PorchPackage
8284
```
8385

86+
Verify that FunctionConfig resources are deployed:
87+
88+
```bash
89+
kubectl get functionconfigs -n porch-fn-system
90+
```
91+
92+
You should see several pre-configured FunctionConfig resources for common KRM functions:
93+
94+
```bash
95+
NAME SERVER APPLIED FNRUNNER APPLIED
96+
apply-replacements 1 1
97+
apply-setters 1 1
98+
create-setters 1 1
99+
ensure-name-substring 1 1
100+
gatekeeper 1 1
101+
kubeconform 1 1
102+
search-replace 1 1
103+
set-annotations 1 1
104+
set-enforcement-action 1 1
105+
set-image 1 1
106+
set-labels 1 1
107+
set-namespace 1 1
108+
starlark 1 1
109+
upsert-resource 1 1
110+
enable-gcp-services 1 1
111+
export-terraform 1 1
112+
generate-folders 1 1
113+
remove-local-config-resources 1 1
114+
set-project-id 1 1
115+
```
116+
117+
**About these new resources:**
118+
119+
- **FunctionConfig**: Defines how KRM functions are executed (pod, binary, or go executors) and replaces the older ConfigMap-based configuration approach. The function-runner and porch-server both include embedded FunctionConfig reconcilers that populate an internal cache used to determine which executor to use and with what configuration.
120+
121+
- **ServiceTemplate**: Defines pod and service templates for pod-based function execution. These templates are referenced by FunctionConfig resources that use the pod executor.
122+
84123
## Troubleshooting
85124

86125
### Pods not starting

docs/content/en/docs/5_architecture_and_components/function-runner/functionality/_index.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: |
66
Overview of function runner functionality and detailed documentation pages.
77
---
88

9-
The Function Runner provides three core functional areas that work together to execute KRM functions in isolated environments:
9+
The Function Runner provides four core functional areas that work together to execute KRM functions in isolated environments:
1010

1111
## Functional Areas
1212

@@ -22,6 +22,19 @@ Executes KRM functions through pluggable evaluator strategies:
2222

2323
For detailed architecture and process flows, see [Function Evaluation]({{% relref "/docs/5_architecture_and_components/function-runner/functionality/function-evaluation.md" %}}).
2424

25+
### Function Configuration Management
26+
27+
Provides declarative configuration of function executors through Kubernetes CRDs:
28+
- **FunctionConfig Reconciler**: Embedded controller watches FunctionConfig resources and maintains internal cache
29+
- **Executor Selection Cache**: Maps function images to executor types and configuration settings
30+
- **Pod Executor Configuration**: Template overrides, TTL settings, and maximum parallel executions per function
31+
- **Binary Executor Configuration**: Path mapping for substituting container images with local executables
32+
- **Go Executor Configuration**: Function ID registration for native go function execution
33+
- **Image Prefix Matching**: Supports multiple image prefixes and tags per function configuration
34+
- **Template Customization**: Per-function pod and service template overrides including security context, resources, and environment variables
35+
36+
For detailed configuration examples, see [Function Runner Configuration]({{% relref "/docs/5_architecture_and_components/function-runner/function-runner-config.md" %}}). For integration with executor selection, see [Function Runner Interactions]({{% relref "/docs/5_architecture_and_components/function-runner/interactions.md" %}}).
37+
2538
### Pod Lifecycle Management
2639

2740
Manages function execution pods with caching and garbage collection:
@@ -32,6 +45,7 @@ Manages function execution pods with caching and garbage collection:
3245
- **TTL-Based Caching**: Reuses pods with configurable expiration and extension on use
3346
- **Garbage Collection**: Periodic cleanup of expired pods and failed pod handling
3447
- **Pod Warming**: Pre-creates pods for frequently-used functions
48+
- **Template Overrides**: Applies FunctionConfig-specified customizations to pod and service templates
3549

3650
For detailed architecture and process flows, see [Pod Lifecycle Management]({{% relref "/docs/5_architecture_and_components/function-runner/functionality/pod-lifecycle-management.md" %}}).
3751

@@ -52,7 +66,20 @@ For detailed architecture and process flows, see [Image and Registry Management]
5266
```
5367
┌─────────────────────────────────────────────────────────┐
5468
│ Function Runner Service │
55-
│ │
69+
│ ┌──────────────────┐ │
70+
│ │ Function │ │
71+
│ │ Configuration │ │
72+
│ │ Management │ │
73+
│ │ │ │
74+
│ │ • FunctionConfig │ │
75+
│ │ Reconciler │ │
76+
│ │ • Executor Cache │ │
77+
│ │ • Image Prefix │ │
78+
│ │ Matching │ │
79+
│ └──────────────────┘ │
80+
│ │ │
81+
│ ┌────────────┴─────────────┐ │
82+
│ ↓ ↓ │
5683
│ ┌──────────────────┐ ┌──────────────────┐ │
5784
│ │ Function │ │ Pod │ │
5885
│ │ Evaluation │ ───> │ Lifecycle │ │
@@ -84,15 +111,18 @@ For detailed architecture and process flows, see [Image and Registry Management]
84111

85112
**Integration flow:**
86113
1. **Function Evaluation** receives gRPC request from Task Handler
87-
2. **Multi-Evaluator** tries executable evaluator first (fast path)
88-
3. **If NotFound**, falls back to pod evaluator (container execution)
89-
4. **Pod Lifecycle Management** checks pod cache for existing pod
90-
5. **If cache miss**, creates new pod with wrapper server via Pod Manager
91-
6. **Image & Registry Management** resolves image metadata and authentication
92-
7. **Pod Manager** creates pod with image pull secrets and service frontend
93-
8. **Pod Cache Manager** stores pod with TTL for reuse
94-
9. **Function Evaluation** connects to pod via service and executes function
95-
10. **Wrapper Server** executes function binary and returns structured results
96-
11. **Garbage Collection** periodically removes expired pods from cache
97-
114+
2. **Function Configuration Management** queries cache for function-specific configuration
115+
3. **Multi-Evaluator** selects appropriate evaluator based on FunctionConfig settings
116+
4. **If binary executor configured**, executes local function binary (fast path)
117+
5. **If go executor configured**, invokes registered native go function
118+
6. **If pod executor configured or no match**, falls back to pod evaluator (container execution)
119+
7. **Pod Lifecycle Management** checks pod cache for existing pod matching configuration
120+
8. **If cache miss**, creates new pod with FunctionConfig template overrides via Pod Manager
121+
9. **Image & Registry Management** resolves image metadata and authentication
122+
10. **Pod Manager** creates pod with image pull secrets and service frontend
123+
11. **Pod Cache Manager** stores pod with FunctionConfig-specified TTL for reuse
124+
12. **Function Evaluation** connects to pod via service and executes function
125+
13. **Wrapper Server** executes function binary and returns structured results
126+
14. **Garbage Collection** periodically removes expired pods based on TTL settings
127+
98128
Each functional area is documented in detail on its own page with architecture diagrams, process flows, and implementation specifics.

0 commit comments

Comments
 (0)