k8s-controller-testing
Installation
SKILL.md
Kubernetes Controller Testing
Testing strategies for Kubernetes controllers using controller-runtime. Covers envtest (the recommended approach), CEL validation testing, integration patterns, and common pitfalls.
Test Hierarchy
| Level | Tool | K8s Required | Purpose |
|---|---|---|---|
| Unit | Standard Go _test.go |
No | Test pure functions, business logic, transformations |
| CEL validation | envtest | API server only | Test CRD validation rules |
| Controller integration | envtest | API server + controllers | Test reconciler logic end-to-end |
| Data plane | Real binary (e.g., func-e) | No | Test data plane processing with real binaries |
| E2E | Kind cluster | Full stack | Test complete system with real infrastructure |
envtest: The Recommended Approach
envtest vs. Fake Client
Use envtest for integration tests (controllers, CEL validation, status subresource). The fake client is acceptable for unit tests of pure business logic that doesn't need server-side behavior, but should not be used for controller integration tests.