Skip to content

docs: SDK documentation cleanup and examples fix#753

Open
efiacor wants to merge 7 commits into
kptdev:mainfrom
Nordix:docs/sdk-documentation-cleanup
Open

docs: SDK documentation cleanup and examples fix#753
efiacor wants to merge 7 commits into
kptdev:mainfrom
Nordix:docs/sdk-documentation-cleanup

Conversation

@efiacor
Copy link
Copy Markdown
Contributor

@efiacor efiacor commented May 7, 2026

Summary

Documentation overhaul and examples fix for the SDK repository.

Changes

New documentation:

  • docs/tutorial.md — end-to-end function development workflow
  • docs/interfaces.md — Runner vs ResourceListProcessor with code examples
  • docs/testing.md — golden test patterns, WRITE_GOLDEN_OUTPUT, e2e testing pointers
  • docs/containerizing.md — Dockerfile patterns, building, running locally
  • CONTRIBUTING.md — DCO, copyright, code review, AI disclosure (aligned with kpt/catalog)

Removed:

  • Legacy docs/ directory (TypeScript API docs, Jekyll artifacts)

Fixed:

  • go/get-started/ — uses //go:embed + fn.WithDocs, added metadata.yaml
  • go/fn/examples/ — updated go.mod to compile against current SDK
  • Root README.md — rewritten with better flow, accurate descriptions, pkg.go.dev link

Other:

  • Renamed testdata/test1/testdata/noop-passthrough/
  • Updated gcr.io/kpt-fn/ghcr.io/kptdev/krm-functions-catalog/ across all files
  • Added replace directive comments in go.mod files

Dependencies

This PR is based on #752 (feat/asmain-help-doc-filemode) for the fn.WithDocs API.

AI Disclosure

I have used AI in the creation of this PR.

I have used the following AI tools:

  • Kiro for documentation generation, code fixes, and review iteration

Copilot AI review requested due to automatic review settings May 7, 2026 22:09
@efiacor efiacor requested a review from CsatariGergely May 7, 2026 22:09
@efiacor efiacor self-assigned this May 7, 2026
@efiacor efiacor added documentation Improvements or additions to documentation go Pull requests that update Go code labels May 7, 2026
Copy link
Copy Markdown

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

efiacor added 5 commits May 25, 2026 13:07
Extend fn.AsMain with functional options to support:
- --help: renders human-readable docs from embedded README markers
- --doc: outputs machine-readable JSON for catalog tooling
- Standalone file mode: accepts positional file args for local debugging

New fn.WithDocs(readme, meta) option registers embedded content.
Existing callers with no options are unaffected (backward-compatible).

Adds internal/docs package with:
- ParseMarkers: extracts mdtogo Short/Long/Examples sections
- ParseMetadata: parses metadata.yaml content
- RenderHelp/RenderDoc: formats output for --help and --doc

Includes property-based tests (rapid) and unit tests for all new code.

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Mechanical changes from 'go fix ./...':
- interface{} → any (Go 1.18+ type alias)
- reflect.Ptr → reflect.Pointer (deprecated constant)
- strings.Index+slice → strings.Cut (Go 1.18+ idiom)

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
- Replace manual loops with slices.Contains for --help/--doc checks
  (matches what 'go fix' produces)
- Change test file permissions from 0644 to 0600 (gosec G306)

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
…tches catalog READMEs)

The catalog functions use <- All existing tests continue tomdtogo--> (bare) as the section end marker,
not <- All existing tests continue tomdtogo:End-->. Updated the parser and all tests to match the
real-world README format.

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
@efiacor efiacor force-pushed the docs/sdk-documentation-cleanup branch from d67a0af to 8f9b6a2 Compare May 25, 2026 12:15
efiacor added 2 commits May 25, 2026 13:23
Go test runner passes -test.* flags via os.Args. The file mode arg
parser must skip all flag-like arguments (starting with -), not just
those starting with --.

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
- Delete legacy docs/ directory (TypeScript API docs, Jekyll artifacts)
- Add docs/tutorial.md — end-to-end function development workflow
- Add docs/interfaces.md — Runner vs ResourceListProcessor guide
- Add docs/testing.md — golden test patterns with testhelpers
- Add docs/containerizing.md — Dockerfile patterns and local testing
- Add CONTRIBUTING.md aligned with kpt/catalog conventions
- Rewrite README.md with better flow and accurate descriptions
- Fix go/get-started/ to use //go:embed + fn.WithDocs
- Fix go/fn/examples/ go.mod
- Rename testdata/test1/ to testdata/noop-passthrough/
- Update gcr.io/kpt-fn/ references to ghcr.io/kptdev/krm-functions-catalog/
- Add replace directive comments in go.mod files
- Update .gitignore for compiled binary

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
@efiacor efiacor force-pushed the docs/sdk-documentation-cleanup branch from 8f9b6a2 to 293bc1f Compare May 25, 2026 12:23
Comment thread docs/containerizing.md
functions use. It accepts `BUILDER_IMAGE` and `BASE_IMAGE` as build args.

For standalone functions or local development, use a multi-stage build with a
minimal base image. The function binary should be statically linked (no CGO) so
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

statically linked (no CGO) so -> statically linked (no CGO), so

Comment thread docs/containerizing.md
```

Note: the image must be published and accessible from the machine running
`kpt fn render`. For local development, build the image locally first and it
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

build the image locally first and it will be used

->

build the image locally first. It will be used

Comment thread docs/interfaces.md
# Interfaces

The SDK provides two interfaces for implementing KRM functions. Choose based on
what your function needs to do.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose based on what your function needs to do.

->

Choose according to your function requirements.

Comment thread docs/interfaces.md

Characteristics:
- The SDK automatically parses `functionConfig` into your struct's exported fields (via JSON tags).
- You can **modify** existing items but cannot add or remove items from the slice.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can modify existing items but cannot add or remove

->

You can modify existing items, but you cannot add or remove

Comment thread docs/interfaces.md
// runner implements ResourceListProcessor and can be passed to fn.AsMain
```

This wrapper handles:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This wrapper handles: -> This wrapper handles the following:

Comment thread docs/testing.md

## Golden Test Pattern

Golden tests compare function output against expected baseline files. This
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Golden tests compare function output against expected baseline files.

->

Golden tests compare the function output against the expected baseline files.

Comment thread docs/testing.md
go test ./...
```

If the function output doesn't match `_expected.yaml`, the test fails with a
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the function output doesn't match -> If the function output does not match

Comment thread docs/testing.md
diffs in version control before committing.

**Caution:** `WRITE_GOLDEN_OUTPUT` accepts whatever the function currently
produces as "correct." If the function has a bug, you've just blessed buggy
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you've just blessed -> you have just blessed

Comment thread docs/testing.md
- Keep test cases focused — one behavior per test directory.
- Use descriptive directory names (e.g., `empty-input`, `missing-namespace`, `multiple-resources`).
- The `_fnconfig.yaml` can be empty if your function doesn't require configuration.
- Golden tests catch unintentional formatting changes too, which helps maintain stable output.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Golden tests catch unintentional formatting changes too, which helps maintain stable output.

->

Golden tests also catch unintentional formatting changes. This helps to maintain a stable output.

Comment thread docs/testing.md
The e2e runner uses a different test structure (`.expected/` directories with
`config.yaml`, `diff.patch`, `results.yaml`) and is used by the
[krm-functions-catalog](https://github.com/kptdev/krm-functions-catalog) `tests/`
directory to validate functions running inside containers against `kpt fn render`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

to validate functions running inside containers -> to validate the functions running inside the containers

Comment thread docs/tutorial.md
# Tutorial: Developing a KRM Function

This tutorial walks through the end-to-end workflow for building a KRM function
using the Go SDK. By the end, you'll have a working function with embedded
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By the end, you'll have -> By the end, you will have

Comment thread docs/tutorial.md
}
```

Here's a minimal function that sets labels on all resources:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here's a minimal function that sets labels on all resources:

->

Here is a minimal function that sets labels on all the resources:

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 go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants