This guide explains how to set up your development environment and contribute to CAPT (Cluster API Provider for Tofu/Terraform).
- Go 1.22 or later
- Docker
- kubectl
- A Kubernetes cluster (for testing)
- AWS credentials (for testing with AWS)
-
Fork and clone the repository:
git clone https://github.com/YOUR_USERNAME/capt.git cd capt
-
Install dependencies:
go mod download
-
Install required tools:
# These will be installed in ./bin/ make kustomize # Install kustomize make controller-gen # Install controller-gen make envtest # Install setup-envtest make golangci-lint # Install golangci-lint
-
Build the manager binary:
make build
-
Build the Docker image:
make docker-build
-
Build multi-architecture Docker image:
make docker-buildx
-
Run unit tests:
make test
-
Run end-to-end tests:
make test-e2e
-
Run linter:
make lint
-
Generate CRDs and RBAC manifests:
make manifests
-
Generate code (DeepCopy methods, etc.):
make generate
-
Install CRDs in your cluster:
make install
-
Run the controller locally:
make run
-
Deploy the controller to a cluster:
make deploy
.
├── api/ # API definitions
│ └── v1beta1/ # API version
├── cmd/
│ └── main.go # Main entry point
├── config/ # Kubernetes manifests
│ ├── crd/ # Custom Resource Definitions
│ ├── default/ # Default configurations
│ ├── manager/ # Controller manager configurations
│ ├── rbac/ # RBAC configurations
│ └── samples/ # Example CR manifests
├── docs/ # Documentation
├── hack/ # Development scripts
├── internal/
│ └── controller/ # Controller implementations
└── test/ # Test files
└── e2e/ # End-to-end tests
- Add the field to the appropriate type in
api/v1beta1/
- Run:
make generate # Generate DeepCopy methods make manifests # Update CRDs
- Create a new controller in
internal/controller/
- Add tests in
internal/controller/
- Register the controller in
cmd/main.go
- Update RBAC if needed:
make manifests
make build
This creates a binary in bin/manager
make docker-build
Builds a Docker image with the controller
make docker-buildx
Builds and pushes multi-architecture images (linux/amd64, linux/arm64)
The test suite requires:
- Go 1.22+
- Access to a Kubernetes cluster (for e2e tests)
- AWS credentials (for AWS-related tests)
-
Unit tests:
make test
-
E2E tests:
make test-e2e
Generate a coverage report:
make test
Coverage report will be in cover.out
-
Run the controller locally:
make run
-
Watch the logs:
kubectl logs -n capt-system capt-controller-manager-xxx
For remote debugging, you can use delve:
-
Build with debug info:
go build -gcflags="all=-N -l" -o bin/manager cmd/main.go
-
Run with delve:
dlv --listen=:2345 --headless=true --api-version=2 exec ./bin/manager
-
Update version:
make update-version VERSION=x.y.z
-
Update CHANGELOG.md:
make update-changelog
-
Build and push release:
make release VERSION=x.y.z
This will:
- Update version numbers
- Update CHANGELOG.md
- Build and push multi-arch Docker images
- Generate installer YAML
- Create GitHub release