|
| 1 | +# Metal3 IP Address Manager - 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 | +| `api/v1alpha1/` | CRD types (IPPool, IPClaim, IPAddress) - separate Go module | |
| 11 | +| `controllers/` | Reconciliation logic | |
| 12 | +| `ipam/` | Core IP allocation algorithms | |
| 13 | +| `internal/webhooks/` | Validation/defaulting webhooks | |
| 14 | +| `config/` | Kustomize manifests (CRDs, RBAC, webhooks) - auto-generated by `make generate`, rarely edit directly | |
| 15 | +| `hack/` | CI scripts (prefer Make targets locally) | |
| 16 | + |
| 17 | +## Testing Standards |
| 18 | + |
| 19 | +CI is managed by [Prow](https://github.com/metal3-io/project-infra/blob/main/prow/config/jobs/metal3-io/ip-address-manager.yaml). |
| 20 | +Run these locally before submitting PRs: |
| 21 | + |
| 22 | +**Make targets:** |
| 23 | + |
| 24 | +| Command | Purpose | |
| 25 | +|---------|---------| |
| 26 | +| `make test` | Full verification (generate + lint + unit) | |
| 27 | +| `make generate` | Regenerate code (DeepCopy, CRDs, RBAC, mocks) | |
| 28 | +| `make unit` | Unit tests (requires envtest - do not use `go test` directly) | |
| 29 | +| `make lint` | Go linting via golangci-lint (all modules) | |
| 30 | +| `make verify-boilerplate` | Check license headers | |
| 31 | +| `make modules` | Verify go.mod is tidy | |
| 32 | + |
| 33 | +**Hack scripts** (auto-containerized, match CI exactly): |
| 34 | + |
| 35 | +| Script | Purpose | |
| 36 | +|--------|---------| |
| 37 | +| `./hack/shellcheck.sh` | Shell script linting (shellcheck) | |
| 38 | +| `./hack/markdownlint.sh` | Markdown linting (config: `.markdownlint-cli2.yaml`) | |
| 39 | +| `./hack/manifestlint.sh` | Kubernetes manifest validation (kubeconform) | |
| 40 | + |
| 41 | +**GitHub Actions** (reusable workflows from project-infra): |
| 42 | + |
| 43 | +| Workflow | Purpose | |
| 44 | +|----------|---------| |
| 45 | +| yamllint | YAML linting (config: `.yamllint.yaml`) | |
| 46 | + |
| 47 | +## Code Conventions |
| 48 | + |
| 49 | +- **Go**: Linting rules in `.golangci.yaml`, license headers in `hack/boilerplate/` |
| 50 | +- **Shell**: Use `set -o errexit -o nounset -o pipefail` |
| 51 | +- **Markdown**: 3-space indent for lists (`.markdownlint-cli2.yaml`) |
| 52 | + |
| 53 | +## Key Workflows |
| 54 | + |
| 55 | +### Modifying APIs |
| 56 | + |
| 57 | +1. Edit `api/v1alpha1/*_types.go` |
| 58 | +1. Run `make generate` |
| 59 | +1. Update webhooks in `internal/webhooks/` if validation changes |
| 60 | +1. Run `make test` |
| 61 | + |
| 62 | +## Code Review Guidelines |
| 63 | + |
| 64 | +When reviewing pull requests: |
| 65 | + |
| 66 | +1. **Security** - Hardcoded secrets, unpinned dependencies, missing input validation |
| 67 | +1. **Test coverage** - New functionality should have tests |
| 68 | +1. **Consistency** - Match existing patterns in the codebase |
| 69 | +1. **Breaking changes** - Flag API/behavior changes affecting users |
| 70 | + |
| 71 | +Focus on: `controllers/`, `ipam/`, `api/`, `internal/webhooks/`. |
| 72 | + |
| 73 | +## AI Agent Guidelines |
| 74 | + |
| 75 | +### Before Changes |
| 76 | + |
| 77 | +1. Run `make unit` to verify baseline |
| 78 | +1. Check patterns in similar existing files |
| 79 | + |
| 80 | +### When Making Changes |
| 81 | + |
| 82 | +1. Make minimal, surgical edits |
| 83 | +1. Run `make generate` after API changes |
| 84 | +1. Run `make test` before committing |
| 85 | +1. Add tests for new functionality |
| 86 | + |
| 87 | +### Security Requirements |
| 88 | + |
| 89 | +- Pin external dependencies by SHA (containers, GitHub Actions, binaries) |
| 90 | +- No hardcoded credentials |
| 91 | +- Validate all inputs |
| 92 | + |
| 93 | +## E2E Testing |
| 94 | + |
| 95 | +IPAM has no standalone e2e tests. E2E runs through |
| 96 | +[CAPM3](https://github.com/metal3-io/cluster-api-provider-metal3). |
| 97 | + |
| 98 | +## Related Documentation |
| 99 | + |
| 100 | +- [API Documentation](docs/api.md) |
| 101 | +- [Testing Guide](docs/testing.md) |
| 102 | +- [Release Process](docs/releasing.md) |
| 103 | +- [Metal3 Book](https://book.metal3.io/ipam/introduction) |
0 commit comments