This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Chaos Mesh is a cloud-native Chaos Engineering platform for Kubernetes that provides various types of fault simulation. It consists of three main components:
- Chaos Controller Manager: Core component responsible for scheduling and managing Chaos experiments through various CRD controllers (Workflow, Scheduler, and fault type controllers)
- Chaos Daemon: Runs as a DaemonSet with privileged permissions, interferes with network devices, file systems, and kernels by accessing target Pod namespaces
- Chaos Dashboard: Web UI for managing, designing, and monitoring Chaos experiments
make image-build-env
make image-dev-env
make enter-devenv
make enter-buildenvmake generate
make config
make chaos-build
make proto
make swagger_spec
make generate-deepcopy
make generate-client
make generate-clientset
make generate-lister
make generate-informer
make manifests/crd.yamlmake check
make fmt
make lint
make vet
make tidy
make gosec-scanmake all
make image
make uimake test
make coverage
make e2e
make e2e-build
make failpoint-enable
make failpoint-disableBuild specific components:
make local/chaos-daemon
make local/chaos-controller-manager
make local/chaos-dashboardControllers in Chaos Mesh follow strict design principles documented in controllers/README.md:
- One Controller Per Field: Each field is controlled by at most one controller to avoid conflicts and hidden bugs
- Standalone Operation: Controllers work independently without depending on other controllers
- Simple Behavior: Controller logic should be describable in ~100 words
- Error Handling: Use
ctrl.Result{Requeue: true}, nilfor retriable errors to leverage exponential backoff
Chaos implementations are in controllers/chaosimpl/:
awschaos: AWS fault injectionazurechaos: Azure fault injectionblockchaos: Block device faultsdnschaos: DNS fault injectiongcpchaos: GCP fault injectionhttpchaos: HTTP fault injectioniochaos: I/O fault injectionjvmchaos: JVM fault injectionkernelchaos: Kernel fault injectionnetworkchaos: Network fault injectionphysicalmachinechaos: Physical machine faultspodchaos: Pod lifecycle faultsstresschaos: CPU/Memory stresstimechaos: Time skew simulation
CRD definitions are in api/v1alpha1/ with types, webhooks, and tests for each chaos kind.
cmd/: Main entry points for binaries (controller-manager, daemon, dashboard, builder)controllers/: Controller implementations and reconciliation logicpkg/: Shared packages (chaosdaemon, dashboard, grpc, selector, metrics, etc.)api/: CRD API definitions (v1alpha1)config/: Kubernetes manifests (CRD, RBAC, webhook)helm/chaos-mesh/: Helm chart for deploymente2e-test/: End-to-end test suiteimages/: Dockerfiles for all componentshack/: Build and development scriptsui/: Frontend dashboard (pnpm-based)
- Before Making Changes: Run
make checkto ensure code passes all checks - After Code Changes:
- Run
make generateif modifying CRDs or APIs - Run
make manifests/crd.yamlto update CRD manifests - Run
make checkbefore committing
- Run
- Testing: Run
make testfor unit tests - Building Images: Use
make imageto build all component images - Commits: Use
git commit --signofffor DCO compliance
- Unit Tests:
make testruns tests with failpoint support and generates coverage - E2E Tests:
make e2eruns end-to-end tests in current Kubernetes cluster - Test Utilities: Build with
make test-utils(timer, multithread_tracee, fakeclock) - Coverage:
make coveragegenerates coverage reports
- Use
goimportswith-local github.com/chaos-mesh/chaos-meshfor formatting - Run
revivelinter with configuration inrevive.toml - Keep
go.modtidy across all submodules (root, api, e2e-test) - Use
controller-genfor CRD and RBAC generation
The project uses a containerized build environment with two Docker images:
- build-env: For compiling binaries (minimal build tools)
- dev-env: For development tasks (code generation, linting, testing)
Generated makefiles (binary.generated.mk, container-image.generated.mk) are created by make generate-makefile.
The dashboard UI is in ui/ and uses pnpm:
cd ui
pnpm install --frozen-lockfile
pnpm buildSet UI=1 environment variable to include UI in builds.
- Always run
make checkbefore creating a PR - When modifying CRD structs, regenerate with
make generate && make manifests/crd.yaml - Use failpoint carefully in tests (enable/disable properly)
- Multi-module project: run
go mod tidyin root, api/, and e2e-test/ directories - Controller modifications should follow "one controller per field" principle