|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides instructions for autonomous agents working in the operator-controller repository. |
| 4 | + |
| 5 | +## Repository Context |
| 6 | + |
| 7 | +This is **operator-controller**, part of OLM v1. Two main Go binaries: `operator-controller` and `catalogd`. Kubernetes controllers using controller-runtime framework. Focus on simplicity, security, predictability. |
| 8 | + |
| 9 | +## Search and Exploration Guidelines |
| 10 | + |
| 11 | +### When searching for code: |
| 12 | + |
| 13 | +**Controllers and reconciliation logic:** |
| 14 | +- ClusterExtension controller: `internal/operator-controller/controllers/clusterextension_controller.go` |
| 15 | +- ClusterCatalog controller: `internal/catalogd/controllers/core/` |
| 16 | +- Look for `Reconcile()` methods and `SetupWithManager()` functions |
| 17 | + |
| 18 | +**API definitions:** |
| 19 | +- All CRDs defined in `api/v1/*_types.go` |
| 20 | +- Generated DeepCopy code: `api/v1/zz_generated.deepcopy.go` |
| 21 | +- CRD manifests (generated): `helm/olmv1/base/*/crd/standard/` |
| 22 | + |
| 23 | +**Resolution and bundle handling:** |
| 24 | +- Bundle resolution: `internal/operator-controller/resolve/` |
| 25 | +- Bundle rendering: `internal/operator-controller/rukpak/render/` |
| 26 | +- Catalog metadata: `internal/operator-controller/catalogmetadata/` |
| 27 | + |
| 28 | +**Testing:** |
| 29 | +- Unit tests: Co-located with source files (`*_test.go`) |
| 30 | +- E2E tests: `test/e2e/`, `test/experimental-e2e/`, `test/extension-developer-e2e/` |
| 31 | +- Test helpers: `test/helpers/` |
| 32 | + |
| 33 | +### Search patterns to use: |
| 34 | + |
| 35 | +**Find controller setup:** |
| 36 | +``` |
| 37 | +Pattern: "SetupWithManager" |
| 38 | +Files: internal/*/controllers/**/*.go |
| 39 | +``` |
| 40 | + |
| 41 | +**Find API validations:** |
| 42 | +``` |
| 43 | +Pattern: "+kubebuilder:validation" |
| 44 | +Files: api/v1/*.go |
| 45 | +``` |
| 46 | + |
| 47 | +**Find feature gates:** |
| 48 | +``` |
| 49 | +Pattern: "features." |
| 50 | +Directories: internal/*/features/ |
| 51 | +``` |
| 52 | + |
| 53 | +**Find HTTP/catalog endpoints:** |
| 54 | +``` |
| 55 | +Pattern: "http.HandleFunc|HandleFunc" |
| 56 | +Files: internal/catalogd/ |
| 57 | +``` |
| 58 | + |
| 59 | +## Code Modification Guidelines |
| 60 | + |
| 61 | +### CRITICAL: Do not modify generated files |
| 62 | + |
| 63 | +These files are AUTO-GENERATED - never edit directly: |
| 64 | +- `api/v1/zz_generated.deepcopy.go` |
| 65 | +- `helm/olmv1/base/*/crd/**/*.yaml` |
| 66 | +- Any file in `manifests/` directory |
| 67 | +- `config/` directory files |
| 68 | + |
| 69 | +To update these, run: `make generate`, `make update-crds`, or `make manifests` |
| 70 | + |
| 71 | +### When modifying API types: |
| 72 | + |
| 73 | +1. Edit `api/v1/*_types.go` only |
| 74 | +2. Add kubebuilder markers for validation/printing |
| 75 | +3. Run `make generate` to regenerate DeepCopy methods |
| 76 | +4. Run `make update-crds` to regenerate CRD manifests |
| 77 | +5. Run `make manifests` to regenerate deployment manifests |
| 78 | +6. Always run `make verify` before considering task complete |
| 79 | + |
| 80 | +### When modifying controllers: |
| 81 | + |
| 82 | +1. Controllers must implement `reconcile.Reconciler` interface |
| 83 | +2. Use controller-runtime patterns (client, scheme, logging) |
| 84 | +3. Update status conditions using metav1.Condition |
| 85 | +4. Handle finalizers properly for cleanup |
| 86 | +5. Add unit tests using ENVTEST framework |
| 87 | +6. Run `make test-unit` to verify |
| 88 | + |
| 89 | +### When adding dependencies: |
| 90 | + |
| 91 | +1. Add to `go.mod` via `go get` |
| 92 | +2. Run `make tidy` |
| 93 | +3. For Kubernetes dependencies, may need `make k8s-pin` to align versions |
| 94 | +4. Check if `.bingo/` managed tools need updating |
| 95 | + |
| 96 | +## Testing Requirements |
| 97 | + |
| 98 | +### Before completing any code change: |
| 99 | + |
| 100 | +1. **Format and lint:** |
| 101 | + ```bash |
| 102 | + make fmt |
| 103 | + make lint |
| 104 | + ``` |
| 105 | + |
| 106 | +2. **Run unit tests:** |
| 107 | + ```bash |
| 108 | + make test-unit |
| 109 | + ``` |
| 110 | + |
| 111 | +3. **Verify generated code is current:** |
| 112 | + ```bash |
| 113 | + make verify |
| 114 | + ``` |
| 115 | + |
| 116 | +### For new features: |
| 117 | + |
| 118 | +1. Add unit tests in `*_test.go` files |
| 119 | +2. Use `envtest` for controller tests |
| 120 | +3. Add e2e tests in appropriate directory |
| 121 | +4. Document new features in `docs/` |
| 122 | + |
| 123 | +### Test execution patterns: |
| 124 | + |
| 125 | +```bash |
| 126 | +# Single test function |
| 127 | +go test -v ./path/to/package -run TestSpecificFunction |
| 128 | + |
| 129 | +# With ENVTEST (for controller tests) |
| 130 | +KUBEBUILDER_ASSETS="$(./bin/setup-envtest use -p path 1.31.x)" \ |
| 131 | + go test -v ./internal/operator-controller/controllers |
| 132 | + |
| 133 | +# E2E on kind cluster |
| 134 | +make test-e2e # Full standard e2e suite |
| 135 | +make test-experimental-e2e # Experimental features |
| 136 | +``` |
| 137 | + |
| 138 | +## File Organization Patterns |
| 139 | + |
| 140 | +### Controller structure: |
| 141 | +``` |
| 142 | +internal/{component}/controllers/ |
| 143 | +├── {resource}_controller.go # Main reconciliation logic |
| 144 | +├── {resource}_controller_test.go # ENVTEST-based tests |
| 145 | +└── suite_test.go # Test suite setup |
| 146 | +``` |
| 147 | + |
| 148 | +### Package structure: |
| 149 | +``` |
| 150 | +internal/{component}/ |
| 151 | +├── controllers/ # Reconcilers |
| 152 | +├── features/ # Feature gates |
| 153 | +├── {package}/ # Business logic packages |
| 154 | +└── scheme/ # Scheme registration |
| 155 | +``` |
| 156 | + |
| 157 | +## Common Pitfalls to Avoid |
| 158 | + |
| 159 | +1. **Don't edit manifests directly** - They're generated from Helm charts |
| 160 | +2. **Don't skip `make verify`** - It catches generated code drift |
| 161 | +3. **Don't use cluster-admin** - Design for least-privilege ServiceAccount |
| 162 | +4. **Don't assume multi-tenancy** - This is explicitly NOT supported |
| 163 | +5. **Don't hardcode namespaces** - Use `olmv1-system` constant or config |
| 164 | +6. **Don't ignore RBAC** - All operations via ServiceAccount |
| 165 | +7. **Don't skip preflight checks** - CRD upgrade safety is critical |
| 166 | + |
| 167 | +## Architecture Context for Agents |
| 168 | + |
| 169 | +### Data Flow: |
| 170 | +1. User creates ClusterCatalog → catalogd unpacks → HTTP server serves content |
| 171 | +2. User creates ClusterExtension → operator-controller queries catalogd |
| 172 | +3. Resolver selects bundle → Renderer processes manifests → Applier deploys |
| 173 | +4. Status conditions updated throughout lifecycle |
| 174 | + |
| 175 | +### Key Interfaces: |
| 176 | +- `reconcile.Reconciler`: All controllers implement this |
| 177 | +- `client.Client`: Kubernetes API interactions |
| 178 | +- `Resolver`: Bundle selection logic |
| 179 | +- `Applier`: Manifest application via boxcutter |
| 180 | + |
| 181 | +### Security Model: |
| 182 | +- ServiceAccount specified in ClusterExtension.spec.serviceAccount |
| 183 | +- All manifest application uses that ServiceAccount's permissions |
| 184 | +- No privilege escalation - user's SA permissions = installation permissions |
| 185 | + |
| 186 | +## Build and Deployment Context |
| 187 | + |
| 188 | +### Make targets for common tasks: |
| 189 | + |
| 190 | +**Development cycle:** |
| 191 | +```bash |
| 192 | +make build # Compile binaries |
| 193 | +make test-unit # Fast feedback |
| 194 | +make verify # Ensure generated code current |
| 195 | +``` |
| 196 | + |
| 197 | +**Full validation:** |
| 198 | +```bash |
| 199 | +make test # All tests (unit, e2e, regression) |
| 200 | +make lint # Code quality |
| 201 | +``` |
| 202 | + |
| 203 | +**Local deployment:** |
| 204 | +```bash |
| 205 | +make run # Build, deploy to kind, includes cleanup |
| 206 | +make run-experimental # Same but with experimental features |
| 207 | +``` |
| 208 | + |
| 209 | +### Environment variables: |
| 210 | + |
| 211 | +- `OPCON_IMAGE_REPO`: operator-controller image repository |
| 212 | +- `CATD_IMAGE_REPO`: catalogd image repository |
| 213 | +- `IMAGE_TAG`: Image tag (default: devel) |
| 214 | +- `KIND_CLUSTER_NAME`: Kind cluster name |
| 215 | +- `INSTALL_DEFAULT_CATALOGS`: Install default catalogs (true/false) |
| 216 | + |
| 217 | +## Reporting Back to User |
| 218 | + |
| 219 | +### When completing search tasks: |
| 220 | + |
| 221 | +Provide: |
| 222 | +1. Exact file paths with line numbers |
| 223 | +2. Relevant code snippets |
| 224 | +3. Context about what the code does |
| 225 | +4. Related files user might need to check |
| 226 | + |
| 227 | +### When completing code modification tasks: |
| 228 | + |
| 229 | +Report: |
| 230 | +1. Files modified with brief description of changes |
| 231 | +2. Any generated files that need regeneration |
| 232 | +3. Make commands that need to be run |
| 233 | +4. Test results if tests were run |
| 234 | +5. Any remaining work or considerations |
| 235 | + |
| 236 | +### When encountering issues: |
| 237 | + |
| 238 | +Report: |
| 239 | +1. Exact error messages |
| 240 | +2. What was attempted |
| 241 | +3. Relevant logs or output |
| 242 | +4. Suggestions for resolution or what to investigate |
| 243 | + |
| 244 | +## Quick Reference |
| 245 | + |
| 246 | +**Find definition of**: `grep -r "type {Name} struct" api/` |
| 247 | +**Find usages of**: `grep -r "{identifier}" internal/` |
| 248 | +**Find tests for**: Look for `*_test.go` in same directory |
| 249 | +**Check generated**: `make verify` (fails if drift detected) |
| 250 | +**Run specific test**: `go test -v ./path -run TestName` |
| 251 | +**Validate changes**: `make fmt && make lint && make test-unit && make verify` |
0 commit comments