|
| 1 | +# Metal3 Baremetal Operator (BMO) - AI Agent Instructions |
| 2 | + |
| 3 | +Instructions for AI coding agents. For project overview, see [README.md](README.md). |
| 4 | +For contribution guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md). |
| 5 | + |
| 6 | +## Repository Structure |
| 7 | + |
| 8 | +| Directory | Purpose | |
| 9 | +|-----------|---------| |
| 10 | +| `apis/metal3.io/v1alpha1/` | CRD types (BareMetalHost, HostFirmwareSettings, etc.) - separate Go module | |
| 11 | +| `internal/controller/metal3.io/` | Reconciliation logic with state machine | |
| 12 | +| `internal/webhooks/metal3.io/` | Validation/defaulting webhooks | |
| 13 | +| `pkg/provisioner/` | Provisioner interface (ironic, fixture, demo) | |
| 14 | +| `pkg/hardwareutils/` | BMC protocol handling - separate Go module | |
| 15 | +| `config/` | Kustomize manifests (CRDs, RBAC, webhooks) - auto-generated by `make manifests`, rarely edit directly | |
| 16 | +| `hack/` | CI scripts (prefer Make targets locally) | |
| 17 | +| `test/e2e/` | E2E tests with libvirt VMs | |
| 18 | + |
| 19 | +## Testing Standards |
| 20 | + |
| 21 | +CI uses GitHub Actions (`.github/workflows/`) and [Prow](https://github.com/metal3-io/project-infra/blob/main/prow/config/jobs/metal3-io/baremetal-operator.yaml). |
| 22 | +Run these locally before submitting PRs: |
| 23 | + |
| 24 | +**Make targets:** |
| 25 | + |
| 26 | +| Command | Purpose | |
| 27 | +|---------|---------| |
| 28 | +| `make test` | Full verification (generate + lint + unit) | |
| 29 | +| `make generate` | Regenerate Go code (deepcopy functions) | |
| 30 | +| `make manifests` | Regenerate CRDs, RBAC, webhooks | |
| 31 | +| `make unit` | Unit tests (requires envtest - do not use `go test` directly) | |
| 32 | +| `make lint` | Go linting via golangci-lint (all modules) | |
| 33 | +| `make mod` | Verify go.mod is tidy | |
| 34 | + |
| 35 | +**Hack scripts** (auto-containerized, match CI exactly): |
| 36 | + |
| 37 | +| Script | Purpose | |
| 38 | +|--------|---------| |
| 39 | +| `./hack/shellcheck.sh` | Shell script linting (shellcheck) | |
| 40 | +| `./hack/markdownlint.sh` | Markdown linting (config: `.markdownlint-cli2.yaml`) | |
| 41 | +| `./hack/manifestlint.sh` | Kubernetes manifest validation (kubeconform) | |
| 42 | + |
| 43 | +## Code Conventions |
| 44 | + |
| 45 | +- **Go**: Linting rules in `.golangci.yaml`, license headers in `hack/boilerplate.go.txt` |
| 46 | +- **Shell**: Use `set -o errexit -o nounset -o pipefail` |
| 47 | +- **Markdown**: 3-space indent for lists (`.markdownlint-cli2.yaml`) |
| 48 | + |
| 49 | +## Key Workflows |
| 50 | + |
| 51 | +### Modifying APIs |
| 52 | + |
| 53 | +1. Edit `apis/metal3.io/v1alpha1/*_types.go` |
| 54 | +1. Run `make generate manifests` |
| 55 | +1. Update webhooks in `internal/webhooks/` if validation changes |
| 56 | +1. Run `make test` |
| 57 | + |
| 58 | +## E2E Testing |
| 59 | + |
| 60 | +BMO has standalone E2E tests using libvirt VMs and BMC emulators: |
| 61 | + |
| 62 | +| Command | Purpose | |
| 63 | +|---------|---------| |
| 64 | +| `./hack/ci-e2e.sh` | Full E2E suite (requires libvirt, docker) | |
| 65 | +| `GINKGO_FOCUS="inspection" ./hack/ci-e2e.sh` | Run specific test | |
| 66 | +| `BMC_PROTOCOL=ipmi ./hack/ci-e2e.sh` | Test with IPMI protocol | |
| 67 | + |
| 68 | +Key files: `test/e2e/config/ironic.yaml`, `test/e2e/config/fixture.yaml` |
| 69 | + |
| 70 | +## Code Review Guidelines |
| 71 | + |
| 72 | +When reviewing pull requests: |
| 73 | + |
| 74 | +1. **Security** - Hardcoded secrets, unpinned dependencies, missing input validation |
| 75 | +1. **Test coverage** - New functionality should have tests |
| 76 | +1. **Consistency** - Match existing patterns in the codebase |
| 77 | +1. **Breaking changes** - Flag API/behavior changes affecting users |
| 78 | + |
| 79 | +Focus on: `internal/controller/`, `pkg/provisioner/`, `apis/`, `internal/webhooks/`. |
| 80 | + |
| 81 | +## AI Agent Guidelines |
| 82 | + |
| 83 | +### Before Changes |
| 84 | + |
| 85 | +1. Run `make unit` to verify baseline |
| 86 | +1. Check patterns in similar existing files |
| 87 | + |
| 88 | +### When Making Changes |
| 89 | + |
| 90 | +1. Make minimal, surgical edits |
| 91 | +1. Run `make generate manifests` after API changes |
| 92 | +1. Run `make test` before committing |
| 93 | +1. Add tests for new functionality |
| 94 | + |
| 95 | +### Security Requirements |
| 96 | + |
| 97 | +- Pin external dependencies by SHA (containers, GitHub Actions, binaries) |
| 98 | +- No hardcoded credentials |
| 99 | +- Validate all inputs |
| 100 | + |
| 101 | +## Related Documentation |
| 102 | + |
| 103 | +- [API Documentation](docs/api.md) |
| 104 | +- [State Machine](docs/baremetalhost-states.md) |
| 105 | +- [Release Process](docs/releasing.md) |
| 106 | +- [Metal3 Book](https://book.metal3.io/bmo/introduction) |
0 commit comments