Skip to content

Commit 47053e9

Browse files
Merge pull request openshift#580 from rashmigottipati/add-agents-file
OPRUN-4268: Add AGENTS.md to allow agents to make contributions to the codebase
2 parents cbbc65c + a5388a3 commit 47053e9

File tree

1 file changed

+333
-0
lines changed

1 file changed

+333
-0
lines changed

openshift/AGENTS.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
# AGENTS.md - Guide for AI Tools
2+
3+
This document provides critical guidance for AI agents working with the OpenShift operator-controller fork.
4+
5+
---
6+
7+
## Critical: This is a Downstream Fork
8+
9+
This repository (`openshift/operator-framework-operator-controller`) is OpenShift's downstream fork of `operator-framework/operator-controller`.
10+
11+
**Upstream Repository:** https://github.com/operator-framework/operator-controller
12+
13+
**Key Constraints for AI Agents:**
14+
- This fork is **synced daily** against upstream by automated tooling
15+
- Changes must use **strict commit message conventions** enforced by CI
16+
- **Minimize divergence** from upstream - every downstream change creates maintenance burden
17+
- **DO NOT create `UPSTREAM: <PR>:` backport commits** - automated tooling handles upstream sync
18+
19+
**Rebase Tooling:** https://github.com/openshift/operator-framework-tooling
20+
21+
---
22+
23+
## Commit Message Conventions (MANDATORY)
24+
25+
**ALL commits MUST use one of these prefixes. CI checks will FAIL non-compliant PRs.**
26+
27+
### `UPSTREAM: <carry>:`
28+
29+
**Use for:** OpenShift-specific changes to non-generated content that must persist across rebases.
30+
31+
**Important:** 99% of carry changes should be in the `openshift/` directory. Code outside `openshift/` should generally be modified upstream and synced downstream.
32+
33+
**Examples:**
34+
```
35+
UPSTREAM: <carry>: Add OpenShift-specific test for disconnected environments
36+
UPSTREAM: <carry>: Update OCP catalogs to v4.21
37+
UPSTREAM: <carry>: Use busybox/httpd to simulate probes
38+
```
39+
40+
**Note:** Creates ongoing maintenance burden. Only use when change cannot go upstream.
41+
42+
### `UPSTREAM: <drop>:`
43+
44+
**Use for:** Temporary commits that will be dropped on the next upstream sync.
45+
46+
**When to use:**
47+
- Pulling down an upstream fix early before the next scheduled sync
48+
- Resolving merge conflicts that cannot be fixed by local regeneration
49+
- Changes that are easier to recreate than rebase/cherry-pick (e.g., removing upstream configuration)
50+
51+
**Examples:**
52+
```
53+
UPSTREAM: <drop>: make manifests
54+
UPSTREAM: <drop>: go mod tidy
55+
UPSTREAM: <drop>: Remove upstream GitHub configuration
56+
```
57+
58+
**Note:** These commits are dropped during the next sync, so they're temporary by design.
59+
60+
### `UPSTREAM: <PR>:`
61+
62+
**AI AGENTS: DO NOT CREATE THESE COMMITS.**
63+
64+
This prefix is **ALMOST NEVER USED** on the main branch because it creates conflicts on the next upstream sync. The bumper tool automatically synchronizes upstream changes during scheduled rebases.
65+
66+
**For urgent fixes:** Use `UPSTREAM: <drop>:` instead to pull the fix early - it will be dropped on the next sync when the real upstream commit comes down.
67+
68+
**Note:** Cherry-picking with this prefix may be done on release branches, but since most work is on main, this is extremely uncommon.
69+
70+
---
71+
72+
## Decision Tree for Changes
73+
74+
| Change Type | Action | Commit Prefix | AI Agent Action |
75+
|------------|--------|--------------|----------------|
76+
| General bug fix | Fix upstream, then let tooling synchronize | None | **DO NOT create PR** - direct user to upstream |
77+
| OpenShift-specific test | Downstream only | `UPSTREAM: <carry>:` | Create in `openshift/tests-extension/` |
78+
| OpenShift-specific config | Downstream only | `UPSTREAM: <carry>:` | Create in `openshift/` |
79+
| Generated files (to fix failures) | Only when necessary | `UPSTREAM: <drop>:` | **Only if absolutely necessary** |
80+
81+
---
82+
83+
## Repository Structure
84+
85+
### Upstream Code (Minimize Changes)
86+
- `api/`, `cmd/`, `internal/`, `pkg/`, `test/`, `helm/`, `docs/`
87+
- **Before modifying:** Can this be fixed upstream? Can this go in `openshift/`?
88+
89+
### Downstream Code (Safe to Modify)
90+
- `openshift/` - ALL OpenShift-specific code and configuration
91+
- `openshift/Makefile` - Downstream build targets
92+
- `openshift/*.Dockerfile` - OpenShift container builds
93+
- `openshift/tests-extension/` - OpenShift Test Extension (OTE) tests
94+
- `openshift/dev_notes.md` - Downstreaming process documentation
95+
- `openshift/AGENTS.md` - This file
96+
97+
---
98+
99+
## Rules for AI Agents
100+
101+
### DO:
102+
1. **Always use correct `UPSTREAM:` prefix** - CI will fail without it
103+
2. **Prefer `openshift/` directory** for new OpenShift-specific code
104+
3. **Check upstream first** before fixing bugs - should it go upstream?
105+
4. **Separate commits:** Never mix code changes with generated files
106+
5. **Run verification:** `make verify` and `make test-unit` before completion
107+
108+
### DO NOT:
109+
1. **DO NOT create `UPSTREAM: <PR>:` backport commits** - tooling handles this
110+
2. **DO NOT use `UPSTREAM: <drop>:` routinely** - only for critical failures
111+
3. **DO NOT modify upstream code** without confirming it's OpenShift-specific
112+
4. **DO NOT hand-edit generated files** - use `make manifests` instead
113+
5. **DO NOT mix code and generated changes** in same commit
114+
6. **DO NOT skip commit prefixes** - CI will reject the PR
115+
116+
---
117+
118+
## Generated Files (Special Handling)
119+
120+
**These files are generated - DO NOT hand-edit:**
121+
- CRD manifests in `helm/olmv1/base/*/crd/`
122+
- Manifests in `manifests/`
123+
- `api/v1/zz_generated.deepcopy.go`
124+
- CRD docs in `docs/api-reference/`
125+
126+
**Workflow for AI Agents:**
127+
1. Make code changes
128+
2. Run `make manifests` locally
129+
3. Verify with `make verify` and `make test-unit`
130+
4. **Commit ONLY the code changes** with `UPSTREAM: <carry>:`
131+
5. **DO NOT commit generated files** unless absolutely necessary to resolve CI failures or merge conflicts
132+
133+
**Only commit regenerated files with `UPSTREAM: <drop>:` when:**
134+
- CI is failing and requires the generated files
135+
- Merge conflicts cannot be resolved by local regeneration
136+
- Multiple PRs have created unmergeable conflicts in generated content
137+
138+
---
139+
140+
## Build and Test Commands
141+
142+
### Verification
143+
```bash
144+
# Root directory
145+
make build
146+
make test-unit
147+
make verify
148+
149+
# OpenShift directory
150+
cd openshift
151+
make verify
152+
make test-e2e
153+
```
154+
155+
### Regenerating Files Locally
156+
```bash
157+
# Always run these after making changes
158+
make manifests
159+
make generate
160+
161+
# Verify tests still pass
162+
make verify
163+
make test-unit
164+
```
165+
166+
**Important:** Run these locally but do NOT commit the generated files unless absolutely necessary to resolve failures.
167+
168+
### Dependencies
169+
```bash
170+
# Run locally to keep dependencies in sync
171+
go mod tidy
172+
173+
# DO NOT commit unless absolutely necessary to resolve failures
174+
```
175+
176+
---
177+
178+
## Common Tasks
179+
180+
### Adding OpenShift-Specific Tests
181+
182+
Add tests to `openshift/tests-extension/`:
183+
184+
```bash
185+
# Create test file in openshift/tests-extension/
186+
# Commit:
187+
git commit -s -m "UPSTREAM: <carry>: Add OTE test for disconnected installation
188+
189+
This test validates OLMv1 behavior in OpenShift disconnected environments.
190+
191+
Signed-off-by: Your Name <your@example.com>"
192+
193+
# Verify:
194+
cd openshift
195+
make test-e2e
196+
```
197+
198+
### Updating OpenShift Configurations
199+
200+
```bash
201+
# Make changes to openshift/ directory files
202+
git commit -s -m "UPSTREAM: <carry>: Update OCP catalogs to v4.22
203+
204+
Updates catalog references to OpenShift 4.22 release catalogs.
205+
206+
Signed-off-by: Your Name <your@example.com>"
207+
```
208+
209+
---
210+
211+
## Examples: Good vs. Bad
212+
213+
### ❌ BAD: Creating Backport Commit
214+
215+
```bash
216+
git commit -m "UPSTREAM: 567: Fix reconciliation loop"
217+
```
218+
219+
**Problem:** AI agents should NOT create backport commits. Tooling handles this.
220+
221+
### ✅ GOOD: Directing to Upstream
222+
223+
**User:** "Fix the reconciliation bug"
224+
225+
**AI:** "This appears to be a general operator-controller issue. I recommend:
226+
1. Check if fixed in upstream `operator-framework/operator-controller`
227+
2. If not, open upstream PR first
228+
3. Automated tooling will sync it downstream on next rebase
229+
230+
Is this OpenShift-specific? If yes, I can create a carry patch."
231+
232+
---
233+
234+
### ❌ BAD: Mixing Code and Generated Files
235+
236+
```
237+
UPSTREAM: <carry>: Fix auth and update manifests
238+
239+
- Modified internal/auth/openshift.go
240+
- Regenerated CRD manifests
241+
```
242+
243+
**Problem:** Mixes code changes with generated files.
244+
245+
### ✅ GOOD: Code Change Only
246+
247+
```
248+
UPSTREAM: <carry>: Fix OpenShift authentication integration
249+
250+
Modified internal/auth/openshift.go
251+
252+
Signed-off-by: Your Name <your@example.com>
253+
```
254+
255+
**After committing:** Run `make manifests` locally to regenerate files. Do NOT commit generated files unless absolutely necessary to resolve failures.
256+
257+
---
258+
259+
### ❌ BAD: Routine Use of `UPSTREAM: <drop>`
260+
261+
```
262+
UPSTREAM: <drop>: make manifests
263+
```
264+
265+
**Problem:** Only use when absolutely necessary to resolve failures, not routinely after every change.
266+
267+
### ✅ GOOD: Only When Necessary
268+
269+
Use `UPSTREAM: <drop>:` for generated files **only** when required to resolve merge conflicts or critical failures that cannot be fixed by local regeneration.
270+
271+
---
272+
273+
## Enforcement
274+
275+
**CI checks by commitchecker will FAIL PRs that do not follow commit conventions.**
276+
277+
Non-compliant PRs will be rejected by maintainers.
278+
279+
---
280+
281+
## Resources
282+
283+
- **Upstream AGENTS.md:** Root of this repository (general operator-controller info)
284+
- **Downstreaming tooling:** https://github.com/openshift/operator-framework-tooling
285+
- **Downstreaming guide:** `openshift/dev_notes.md`
286+
- **Origin tests guide:** `openshift/HOWTO-origin-tests.md`
287+
288+
---
289+
290+
## Quick Reference
291+
292+
```bash
293+
# Verify changes
294+
cd openshift
295+
make verify
296+
make test-e2e
297+
298+
# Regenerate files
299+
make manifests
300+
make generate
301+
302+
# Check commit history
303+
git log --oneline --grep="UPSTREAM: <carry>"
304+
305+
# Proper commit format
306+
git commit -s -m "UPSTREAM: <carry>: Description
307+
308+
Detailed explanation.
309+
310+
Signed-off-by: Your Name <your@example.com>"
311+
```
312+
313+
---
314+
315+
## Summary
316+
317+
**This is a downstream fork that gets regularly rebased against upstream.**
318+
319+
Before suggesting any change, AI agents MUST understand:
320+
321+
1. **Is this upstream or OpenShift-specific?** If upstream, direct to upstream repo
322+
2. **What commit prefix is required?** Use `UPSTREAM: <carry>:` for OpenShift-specific changes
323+
3. **DO NOT create `UPSTREAM: <PR>:` backports** - tooling handles upstream sync
324+
4. **DO NOT use `UPSTREAM: <drop>:` routinely** - only for critical failures
325+
5. **Minimize divergence** - every carry patch creates maintenance burden
326+
327+
**When in doubt:** Ask if the change is OpenShift-specific or should go upstream first.
328+
329+
---
330+
331+
**Last Updated:** 2025-12-11
332+
**Maintainer:** OpenShift OLM Team
333+
**Upstream:** https://github.com/operator-framework/operator-controller

0 commit comments

Comments
 (0)