How to create new custom resource definitions
Note
This guide is intended for developers who want to extend Chantico itself. Users who only install or configure Chantico can skip it.
This guide describes how to add a new Kubernetes custom resource definition (CRD) to Chantico using Kubebuilder.
Relevant resources (this documentation may be outdated, so check the links for the latest information):
Prerequisites
-
Install
kubebuilder: -
Make sure your local environment is set up: How to set up the local development environment
Create the API and controller scaffolding
-
Generate the resource scaffolding:
-
Remove the generated integration tests (these are not used in this repo):
Define the schema
-
Update the Go types in
api/v1alpha1/<resource>_types.go:- Add the
Specfields for the desired state. - Add the
Statusfields for observed state. - Add validation markers if needed.
- Add the
-
Regenerate code and manifests:
Implement controller behavior
-
Update the controller in
internal/controller/<resource>_controller.go:- Implement reconcile logic.
- Add required RBAC markers for the CRD.
-
Add or adjust tests in
internal/<resource>/as needed.
Apply to a cluster (optional)
If you want to test against a running dev cluster:
This installs the CRDs into the current kube-context.