.agents/skills/documentation-standards/references/REFERENCE.md
Technical references and detailed examples for Kubebuilder documentation standards.
Documentation location: docs/book/src/ (built with mdBook)
This reference provides templates, examples, and patterns for contributing high-quality documentation to Kubebuilder.
Primary reference for all Kubebuilder documentation.
URL: https://kubernetes.io/docs/contribute/style/style-guide/
Key topics:
Core library for building Kubernetes controllers.
Tools for generating CRDs, webhooks, and RBAC from Go code.
Kubebuilder documentation uses mdBook with custom preprocessors:
./litgo.sh): Processes {{#literatego path/to/file.go}} includes./markerdocs.sh): Generates marker documentationConfiguration: docs/book/book.toml
# Install mdBook (one time)
cd docs/book && ./install-and-build.sh
# Build docs
cd docs/book && mdbook build
# Serve with live reload
cd docs/book && mdbook serve
Testdata projects are generated from two different sources:
Location: hack/docs/internal/
Key files:
generate.sh: Main generation script called by make generate-docsinternal/cronjob-tutorial/: CronJob tutorial generatorinternal/getting-started/: Getting Started generatorinternal/multiversion-tutorial/: Multiversion generatorGenerates: Tutorial-specific customizations and examples
Location: pkg/plugins/
Key templates:
pkg/plugins/golang/v4/scaffolds/internal/templates/agents.go - Generates AGENTS.mdpkg/plugins/golang/v4/scaffolds/internal/templates/ - Other default boilerplatepkg/plugins/optional/*/scaffolds/internal/templates/ - Optional plugin templatespkg/plugins/common/kustomize/*/scaffolds/internal/templates/ - Kustomize config filesGenerates: Default project structure files (Makefile, main.go, AGENTS.md, config/ kustomize files, etc.)
If you find a documentation issue in testdata files:
Identify the source:
hack/docs/internal/AGENTS.md, config/ kustomize files, standard boilerplate) → Edit pkg/plugins/Fix the template source:
Rebuild and regenerate:
make install # Rebuild kubebuilder binary with template changes
make generate-docs # Regenerate all testdata using new binary
Verify the fix:
git diff docs/book/src/*/testdata/project/ # Check generated files updated correctly
Auto-generated (DO NOT EDIT DIRECTLY):
docs/book/src/cronjob-tutorial/testdata/project/docs/book/src/getting-started/testdata/project/docs/book/src/multiversion-tutorial/testdata/project/# Regenerate all samples (after template changes)
make install # Required after changing pkg/plugins/ templates
make generate-docs # Regenerates all testdata
# Fix accessibility and trailing spaces
make fix-docs
# Test tutorial code compiles
make test-book
Good:
See [Creating a controller](../cronjob-tutorial/controller-implementation.md) for details.
See [API markers](./markers.md) in the same directory.
Avoid:
See [guide](/docs/book/src/getting-started.md) for details.
See [guide](https://kubebuilder.io/getting-started.md) for internal content.
Content with links to [Kubernetes API][k8s-api] and [contributing guide][contributing].
[k8s-api]: https://kubernetes.io/docs/reference/
[contributing]: ../CONTRIBUTING.md
Good:
See the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md).
Avoid:
Click [here](https://github.com/...) for API conventions.
Problem: Inline code becomes outdated when the codebase changes.
Solution: Use {{#include}} or {{#literatego}} to reference testdata projects.
Available testdata (all tested by make test-book):
docs/book/src/cronjob-tutorial/testdata/project/docs/book/src/getting-started/testdata/project/docs/book/src/multiversion-tutorial/testdata/project/testdata/project-v4-with-plugins/For Go code (adds syntax highlighting, handles imports):
{{#literatego ./testdata/project/path/to/file.go}}
For YAML, JSON, Makefile, shell (includes raw):
{{#include ./testdata/project/config/manager/manager.yaml}}
For specific sections (using anchors in source files):
{{#include ./testdata/project/config/default/kustomization.yaml:webhook-resources}}
Anchors mark sections in testdata files for selective inclusion:
// +kubebuilder:docs-gen:collapse=Apache License
// ANCHOR: imports
import (
"context"
ctrl "sigs.k8s.io/controller-runtime"
)
// ANCHOR_END: imports
Include the anchored section:
{{#literatego ./testdata/project/main.go:imports}}
Pattern (always follow this):
Good example:
## Implementing the controller
The basic logic of our CronJob controller is this:
1. Load the named CronJob
2. List all active jobs, and update the status
3. Clean up old jobs according to the history limits
{{#literatego ./testdata/project/internal/controller/cronjob_controller.go}}
The reconciler returns successfully when the CronJob is deleted (using `client.IgnoreNotFound`).
For existing CronJobs, it ensures child Jobs match the schedule.
Why this pattern works:
Use inline code when:
For tutorials: Always use testdata includes. Add code to testdata first or create issue to track.
// Good: Comments explain WHY, not WHAT
// Reconcile implements the control loop logic.
// It ensures the actual state matches the desired state.
func (r *MyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// Fetch the instance
obj := &myv1.MyKind{}
if err := r.Get(ctx, req.NamespacedName, obj); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// Your logic here
return ctrl.Result{}, nil
}
Use $ for commands:
$ kubebuilder init --domain example.com
$ make install
No $ for output:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-pod-abc123 1/1 Running 0 5m
Use for important information:
<aside class="note" role="note">
<p class="note-title">Title Here</p>
Content goes here. Can include markdown, code blocks, links, etc.
</aside>
Use for critical information or caveats:
<aside class="warning" role="note">
<p class="note-title">Title Here</p>
Content goes here. Can include markdown, code blocks, links, etc.
</aside>
role="note" attribute<p class="note-title"></aside>Requirements:
Run make fix-docs to automatically fix accessibility issues and remove trailing spaces.
Centralize frequently used URLs:
Kubebuilder ecosystem:
When documenting features from controller-runtime, controller-tools, or other dependencies, verify accuracy by checking the source code.
Problem: Documentation about dependencies can become outdated or incorrect:
Solution: Verify by checking the actual source code.
Use go mod vendor to download and inspect dependency source code:
# Create temp directory for verification
mkdir -p /tmp/verify-deps
cd /tmp/verify-deps
# Initialize a Go module
go mod init example.com/verify
# Add the dependency you want to check
go get sigs.k8s.io/controller-runtime@latest
# or
go get sigs.k8s.io/controller-tools@latest
# Vendor the dependencies
go mod vendor
# Now inspect the source code
cd vendor/sigs.k8s.io/controller-runtime
# or
cd vendor/sigs.k8s.io/controller-tools
For controller-runtime:
vendor/sigs.k8s.io/controller-runtime/pkg/manager/manager.govendor/sigs.k8s.io/controller-runtime/pkg/client/client.govendor/sigs.k8s.io/controller-runtime/pkg/reconcile/reconcile.govendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.goFor controller-tools:
vendor/sigs.k8s.io/controller-tools/pkg/markers/vendor/sigs.k8s.io/controller-tools/pkg/crd/vendor/sigs.k8s.io/controller-tools/pkg/webhook/vendor/sigs.k8s.io/controller-tools/pkg/rbac/Documenting a controller-runtime feature:
# Setup
mkdir -p /tmp/verify-controller-runtime
cd /tmp/verify-controller-runtime
go mod init example.com/verify
go get sigs.k8s.io/controller-runtime@latest
go mod vendor
# Check Manager.Start behavior
cat vendor/sigs.k8s.io/controller-runtime/pkg/manager/manager.go | grep -A 10 "func.*Start"
# Check default reconcile options
grep -r "DefaultRecoverPanic" vendor/sigs.k8s.io/controller-runtime/
# Verify the exact version being documented
go list -m sigs.k8s.io/controller-runtime
Always verify when:
Do NOT document from memory or assumptions - verify the source code.
Before submitting:
Test all command examples manually in a clean environment:
# Create temp directory for testing
mkdir -p /tmp/kb-doc-test
cd /tmp/kb-doc-test
# Run commands exactly as documented
kubebuilder init --domain example.com
# ... follow all documented steps
# Verify output matches documentation
Verify code examples compile and run:
Check all links are valid:
Rule: If you cannot test a command or step yourself, do not include it in documentation.