Development
This page is for contributors. It covers the layout of the repository and the commands that build, generate and lint it. Testing covers the tests.
Layout
| Path | Contents |
|---|---|
fn.go | RunFunction and the stack type: render, compose, gate, summary. Start here. |
main.go | The command line, the gRPC server and the recipe source. |
input/v1beta1/ | The Input API types. The CRD under package/input/ is generated from them. |
internal/resolve/ | The overlay from the composite resource, the criteria and the provider config. |
internal/compose/ | The Release and Object builders, manifest rendering, value merging, DRA eviction wiring. |
internal/schema/ | OpenAPI v3 validation of composed resources. |
test-fixtures/ | The requests TestRunFunction sends and the goldens it compares against. |
example/clusterstack/ | The XRD, Composition and composite resources of the render walkthrough. |
test/e2e/ | The end-to-end suite, a Go module of its own. |
Makefile, build/ | The end-to-end cluster and the Crossplane make library it uses. |
docs/ | This site. |
fn.go and main.go live in package main, the layout of Crossplane’s
function template.
Build
# Generate the deepcopy code, the Input CRD and the golden fixtures
go generate ./...
# Build
CGO_ENABLED=0 go build ./...
# Lint; the version CI pins is in .github/workflows/ci.yml
golangci-lint run
# Build the runtime image, then a function package from it
docker build . --tag=runtime
crossplane xpkg build -f package --embed-runtime-image=runtime
go.mod is the source of truth for the Go version. CI reads it and passes it
to the image build.
CI’s check-diff job runs go mod tidy and go generate ./... and fails
when either leaves the tree changed, so commit what they produce.
Add an Input field
- Add the field to
input/v1beta1/input.gowith its kubebuilder markers. - Run
go generate ./..., which regenerates the deepcopy code and the CRD. - Use the field in
fn.go. The overlay can set it with no further code. - Add a fixture under
test-fixtures/input/and aTestRunFunctioncase. Give the case a new golden if the field changes the composed resources, regenerate, and reviewtest-fixtures/want/. - Document it in the Input reference.
Bump AICR
The version of aicr.run, AICR’s Go module, is the recipe catalog version. A
bump changes what the function deploys, so it’s a minor release and never a
patch.
go get aicr.run@vX.Y.Z && go mod tidygo test ./....TestRunFunctionfails wherever recipe content changed.TestCatalogInvariantsfails, with the recipe and component named, wherever a recipe’s shape broke an assumption of the function.go generate ./..., then review the diff undertest-fixtures/want/. It’s exactly what the function now deploys.- Render both example composite resources.
- Re-read AICR’s node scheduling pass,
applyNodeSchedulingOverridesandvalidateRequiredNodeSelectorsinpkg/bundler/bundler.go, and its DRA eviction wiring,injectDRAEvictionLabeland its helpers. The function has a hand copy of both.TestNodeSchedulingAcrossTheCatalogandTestDRAEvictionConstantscatch a registry entry or a constant the copy doesn’t cover, but not a change in behaviour. - Label the pull request
e2e. The end-to-end suite then also deploys a stock recipe of the new catalog onto simulated nodes. - Fix behaviour changes by hand. A component the catalog adds joins every
TestRunFunctionfixture that doesn’t skip it.
AGENTS.md in the repository has the same procedure with more detail.
Conventions
- Go: a pointer to a literal is
new(value). Pointer helper functions aren’t used. - Tests are table-driven and compare with
go-cmp. No third-party test packages. - Commits follow the conventional format,
<type>(<scope>): <subject>, one logical change each.