This guide provides instructions for developers who want to contribute to the alert-manager project.
Alert Manager is built using Kubebuilder, a framework for building Kubernetes APIs using custom resource definitions (CRDs). Kubebuilder provides scaffolding tools to quickly create new APIs, controllers, and webhook components. Understanding Kubebuilder will greatly help in comprehending the alert-manager codebase structure and development workflow.
- Go 1.19+ (check the current version in go.mod)
- Kubernetes cluster for testing (minikube, kind, or a remote cluster)
- Docker for building images
- kubectl CLI
- kustomize
- controller-gen
git clone https://github.com/keikoproj/alert-manager.git
cd alert-managerThe Makefile can help install required development tools:
# Install controller-gen
make controller-gen
# Install kustomize
make kustomize
# Install mockgen (for tests)
make mockgen# Build the manager binary
make
# Run the manager locally (outside the cluster)
make run# Run unit tests
make testFor integration tests, you need a Kubernetes cluster and Wavefront access:
# Set up environment variables for integration tests
export WAVEFRONT_URL=https://your-wavefront-instance.wavefront.com
export WAVEFRONT_TOKEN=your-api-token
# Run integration tests
make integration-testTo build a custom Docker image:
# Build the controller image
make docker-build IMG=your-registry/alert-manager:your-tag
# Push the image to your registry
make docker-push IMG=your-registry/alert-manager:your-tagDeploy your custom build to a cluster:
# Deploy with your custom image
make deploy IMG=your-registry/alert-manager:your-tagHere's an overview of the project structure:
.
├── api/ # API definitions (CRDs)
│ └── v1alpha1/ # API version
├── cmd/ # Entry points
├── config/ # Kubernetes YAML manifests
├── controllers/ # Reconciliation logic
├── pkg/ # Shared packages
│ ├── wavefront/ # Wavefront client
│ └── splunk/ # Splunk client (future)
└── hack/ # Development scripts
- api/v1alpha1: Contains the CRD definitions, including the WavefrontAlert and AlertsConfig types.
- controllers: Contains the controllers that reconcile the custom resources.
- pkg/wavefront: Implements the Wavefront API client.
- Create a new branch:
git checkout -b feature/your-feature-name - Make your changes
- Add tests for your changes
- Run tests:
make test - Build and verify:
make - Commit changes with DCO signature:
git commit -s -m "Your commit message" - Push changes:
git push origin feature/your-feature-name - Create a pull request
To add support for a new monitoring system:
- Create a new client package in
pkg/ - Define a new CRD in
api/v1alpha1/ - Create a new controller in
controllers/ - Update the controller manager to include your new controller
- Add appropriate tests
- Update documentation
For easier debugging, you can run the controller outside the cluster:
# Run the controller locally
make runYou can use Delve for remote debugging:
# Install Delve if you don't have it
go install github.com/go-delve/delve/cmd/dlv@latest
# Run with Delve
dlv debug ./cmd/main.go -- --kubeconfig=$HOME/.kube/configTo enable debug logs:
# When running locally
make run LOG_LEVEL=debug
# In a deployed controller
kubectl edit deployment alert-manager-controller-manager -n alert-manager-system
# Add environment variable LOG_LEVEL=debugalert-manager uses kubebuilder and controller-gen for code generation.
Alert Manager follows the Kubebuilder project structure and conventions. The project was initially scaffolded using Kubebuilder, which set up:
- API types in
api/v1alpha1/ - Controller logic in
controllers/ - Configuration files in
config/ - Main entry point in
cmd/manager/main.go
When you make changes to the API types, you need to regenerate various files:
# Generate CRDs
make manifests
# Generate code (deepcopy methods, etc.)
make generateTo add a new Custom Resource Definition (e.g., for a new monitoring system):
# Use kubebuilder to scaffold a new API
kubebuilder create api --group alertmanager --version v1alpha1 --kind YourNewAlert
# This will create:
# - api/v1alpha1/yournewealert_types.go
# - controllers/yournewealert_controller.go
# - And update main.go to include the new controllerAfter scaffolding, you'll need to:
- Define your API schema in the
_types.gofile - Implement the reconciliation logic in the controller
- Regenerate the manifests and code as described above
The project uses GitHub Actions for CI. When you submit a PR, the CI will:
- Run unit tests
- Build the controller image
- Verify code generation is up-to-date
- Check code style
Make sure all CI checks pass before requesting a review.
To create a new release:
- Update version tags in all relevant files
- Run tests and ensure they pass
- Create a git tag:
git tag -a v0.x.y -m "Release v0.x.y" - Push the tag:
git push origin v0.x.y - Create a release on GitHub with release notes