Skip to content

Commit 5ce7e95

Browse files
committed
docs: clarify golden-test, interface, and file-mode behavior
Add behavioral details verified against the SDK source: - testing: Kptfile counted as input, non-YAML files ignored, inputs read in sorted order, and WRITE_GOLDEN_OUTPUT intentionally fails the writing run - interfaces: note the ConfigMap .data functionConfig path and that the Runner no-add/remove rule is a convention, not a compile-time restriction - containerizing: note file mode uses an empty functionConfig Refs #4725 Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
1 parent ca9cd64 commit 5ce7e95

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

documentation/content/en/guides/krm-functions/containerizing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ docker run --rm -i ghcr.io/kptdev/krm-functions-catalog/my-function:v0.1 < input
9292
docker run --rm -v $(pwd):/data ghcr.io/kptdev/krm-functions-catalog/my-function:v0.1 /data/deployment.yaml
9393
```
9494

95+
Note: file mode assembles the given files into a ResourceList with an **empty
96+
functionConfig**. Functions that require configuration should be run via STDIN
97+
(or a `kpt` pipeline) so the functionConfig is provided.
98+
9599
### Help and doc flags
96100

97101
```bash

documentation/content/en/guides/krm-functions/interfaces.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ type Runner interface {
2828
```
2929

3030
Characteristics:
31-
- The SDK automatically parses `functionConfig` into your struct's exported fields (via JSON tags).
32-
- You can **modify** existing items, but you cannot add or remove items from the slice.
31+
- The SDK automatically parses `functionConfig` into your struct's exported fields.
32+
A typed functionConfig (its `kind` matching your struct name) is unmarshaled via
33+
JSON tags; alternatively, a `ConfigMap` functionConfig has its `.data` map assigned
34+
to a `map[string]string` field on your struct.
35+
- You can **modify** existing items, but adding or removing items is not supported.
36+
This is a convention, not a compile-time restriction: the SDK does not read back
37+
items appended inside `Run`, so adds and removes are effectively dropped. Use
38+
`fn.ResourceListProcessor` when you need to add or remove items.
3339
- Return `true` for success, `false` for failure.
3440
- Use `results` to report structured info/warning/error messages.
3541

documentation/content/en/guides/krm-functions/testing.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ Conventions:
3434
- Files prefixed with `_` are special — they are not included in the input items.
3535
- `_fnconfig.yaml` contains the functionConfig passed to your function.
3636
- `_expected.yaml` contains the expected ResourceList output.
37-
- All other `.yaml` files in the directory are parsed as input resources.
37+
- All other `.yaml`/`.yml` files (and a `Kptfile`, if present) are parsed as input
38+
resources. Files with any other extension are ignored.
3839
- You can have multiple input files (e.g., `deployments.yaml`, `services.yaml`).
40+
Input files are read in sorted (alphabetical) order, so the assembled item
41+
ordering is deterministic.
3942

4043
### Writing a Golden Test
4144

@@ -51,7 +54,7 @@ import (
5154
)
5255

5356
func TestFunction(t *testing.T) {
54-
runner := fn.WithContext(context.TODO(), &YourFunction{})
57+
runner := fn.WithContext(context.TODO(), &SetLabels{})
5558
testhelpers.RunGoldenTests(t, "testdata", runner)
5659
}
5760
```
@@ -136,8 +139,12 @@ When your function's output changes intentionally, regenerate the expected files
136139
WRITE_GOLDEN_OUTPUT=1 go test ./...
137140
```
138141

139-
This overwrites all `_expected.yaml` files with the actual output. Review the
140-
diffs in version control before committing.
142+
This overwrites any `_expected.yaml` that differs from the actual output. Any
143+
non-empty value enables write mode (`WRITE_GOLDEN_OUTPUT=1`, `=true`, etc.).
144+
Note that the run which writes a golden file is reported as a **test failure**
145+
(`wrote output to ...`) — this is intentional, so a rewrite never silently
146+
passes in CI. Re-run the tests without the env var to confirm they pass, and
147+
review the diffs in version control before committing.
141148

142149
**Caution:** `WRITE_GOLDEN_OUTPUT` accepts whatever the function currently
143150
produces as "correct." If the function has a bug, you have just blessed buggy

0 commit comments

Comments
 (0)