Skip to content

Commit 62e3677

Browse files
perdasilvaPer Goncalves da Silva
andauthored
Add AGENTS.md (#3678)
* Add AGENTS.md Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> * Add AGENTS.md Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> --------- Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> Co-authored-by: Per Goncalves da Silva <pegoncal@redhat.com>
1 parent b107642 commit 62e3677

File tree

1 file changed

+352
-0
lines changed

1 file changed

+352
-0
lines changed

AGENTS.md

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
# AGENTS.md
2+
3+
This file provides AI agents with comprehensive context about the Operator Lifecycle Manager (OLM) v0 codebase to enable effective navigation, understanding, and contribution.
4+
5+
## Project Status
6+
7+
**CRITICAL**: This repository is in **maintenance mode**. OLM v0 accepts only critical bug fixes and security updates. For new development, use [operator-controller](https://github.com/operator-framework/operator-controller) (OLM v1).
8+
9+
## Project Overview
10+
11+
Operator Lifecycle Manager (OLM) extends Kubernetes to provide declarative installation, upgrade, and lifecycle management for Kubernetes operators. It's part of the [Operator Framework](https://github.com/operator-framework) ecosystem.
12+
13+
### Core Capabilities
14+
- **Over-the-Air Updates**: Automatic operator updates via catalog channels
15+
- **Dependency Resolution**: Automatic resolution and installation of operator dependencies
16+
- **Multi-tenancy**: Namespace-scoped operator management via OperatorGroups
17+
- **Discovery**: Catalog-based operator discovery and installation
18+
- **Stability**: Prevents conflicting operators from owning the same APIs
19+
20+
## Architecture
21+
22+
OLM consists of two main operators working together:
23+
24+
### 1. OLM Operator (`cmd/olm`)
25+
**Responsibility**: Manages the installation and lifecycle of operators defined by ClusterServiceVersions (CSVs)
26+
27+
**Key Functions**:
28+
- Creates Deployments, ServiceAccounts, Roles, and RoleBindings from CSV specifications
29+
- Manages CSV lifecycle states: None → Pending → InstallReady → Installing → Succeeded/Failed
30+
- Monitors installed operator health and rotates certificates
31+
- Enforces OperatorGroup namespace scoping
32+
33+
**Primary Controllers**:
34+
- CSV Controller (pkg/controller/operators/olm)
35+
- OperatorGroup Controller
36+
37+
### 2. Catalog Operator (`cmd/catalog`)
38+
**Responsibility**: Manages operator catalogs, subscriptions, and dependency resolution
39+
40+
**Key Functions**:
41+
- Monitors CatalogSources and builds operator catalogs
42+
- Processes Subscriptions to track operator updates
43+
- Generates InstallPlans with resolved dependencies
44+
- Creates CRDs and CSVs from catalog content
45+
46+
**Primary Controllers**:
47+
- Subscription Controller
48+
- InstallPlan Controller
49+
- CatalogSource Controller
50+
- Registry Reconciler
51+
52+
## Custom Resource Definitions (CRDs)
53+
54+
| Resource | API Group | Owner | Description |
55+
|----------|-----------|-------|-------------|
56+
| **ClusterServiceVersion (CSV)** | operators.coreos.com/v1alpha1 | OLM | Defines operator metadata, installation strategy, permissions, and owned/required CRDs |
57+
| **Subscription** | operators.coreos.com/v1alpha1 | Catalog | Tracks operator updates from a catalog channel; drives automatic upgrades |
58+
| **InstallPlan** | operators.coreos.com/v1alpha1 | Catalog | Calculated list of resources to install/upgrade; requires approval (manual or automatic) |
59+
| **CatalogSource** | operators.coreos.com/v1alpha1 | Catalog | Repository of operators and metadata; served via grpc from operator-registry |
60+
| **OperatorGroup** | operators.coreos.com/v1 | OLM | Groups namespaces for operator installation scope; enables multi-tenancy |
61+
| **OperatorCondition** | operators.coreos.com/v2 | OLM | Tracks operator health status and conditions |
62+
63+
## Directory Structure
64+
65+
```
66+
operator-lifecycle-manager/
67+
├── cmd/ # Entry point binaries
68+
│ ├── catalog/ # Catalog Operator main
69+
│ ├── olm/ # OLM Operator main
70+
│ ├── package-server/ # Package API server
71+
│ └── copy-content/ # Content copy utility
72+
73+
├── pkg/ # Core implementation
74+
│ ├── api/ # API client and wrappers
75+
│ │ ├── client/ # Generated Kubernetes clients
76+
│ │ └── wrappers/ # Client wrapper utilities
77+
│ │
78+
│ ├── controller/ # Main controllers
79+
│ │ ├── bundle/ # Bundle lifecycle controller
80+
│ │ ├── install/ # Installation controller
81+
│ │ ├── operators/ # Operator/CSV controllers (OLM Operator)
82+
│ │ └── registry/ # Catalog/registry controllers (Catalog Operator)
83+
│ │
84+
│ ├── lib/ # Shared libraries and utilities
85+
│ │ ├── catalogsource/ # CatalogSource utilities
86+
│ │ ├── csv/ # CSV manipulation utilities
87+
│ │ ├── operatorclient/ # Operator client abstractions
88+
│ │ ├── operatorlister/ # Informer-based listers
89+
│ │ ├── operatorstatus/ # Status management
90+
│ │ ├── ownerutil/ # Owner reference utilities
91+
│ │ ├── queueinformer/ # Queue-based informers
92+
│ │ ├── scoped/ # Scoped client for multi-tenancy
93+
│ │ └── [other utilities]
94+
│ │
95+
│ ├── metrics/ # Prometheus metrics
96+
│ └── package-server/ # Package server implementation
97+
98+
├── test/ # Testing infrastructure
99+
│ ├── e2e/ # End-to-end tests
100+
│ └── images/ # Test container images
101+
102+
├── doc/ # Documentation
103+
│ ├── design/ # Architecture and design docs
104+
│ └── contributors/ # Contributor guides
105+
106+
└── vendor/ # Vendored dependencies
107+
```
108+
109+
## Key Packages and Their Responsibilities
110+
111+
### Controllers (`pkg/controller/`)
112+
113+
#### `pkg/controller/operators/`
114+
The heart of the OLM Operator. Contains the CSV controller that manages the complete operator lifecycle.
115+
116+
**Key files**:
117+
- `olm/operator.go` - Main OLM operator reconciler
118+
- `olm/csv.go` - CSV reconciliation logic
119+
- `catalog/operator.go` - Catalog operator reconciler
120+
121+
#### `pkg/controller/registry/`
122+
Registry and catalog management for the Catalog Operator.
123+
124+
**Key files**:
125+
- `reconciler/reconciler.go` - CatalogSource reconciliation
126+
- `grpc/source.go` - gRPC catalog source handling
127+
128+
#### `pkg/controller/install/`
129+
Manages the installation of resources defined in InstallPlans.
130+
131+
### Libraries (`pkg/lib/`)
132+
133+
#### `pkg/lib/operatorclient/`
134+
Abstraction layer over Kubernetes clients providing OLM-specific operations.
135+
136+
#### `pkg/lib/operatorlister/`
137+
Informer-based listers for efficient caching and querying of OLM resources.
138+
139+
#### `pkg/lib/queueinformer/`
140+
Queue-based informer pattern used throughout OLM controllers for event-driven reconciliation.
141+
142+
#### `pkg/lib/ownerutil/`
143+
Owner reference management ensuring proper garbage collection of OLM-managed resources.
144+
145+
#### `pkg/lib/scoped/`
146+
Scoped clients that respect OperatorGroup namespace boundaries for multi-tenancy.
147+
148+
## Development Workflow
149+
150+
### Building
151+
```bash
152+
make build # Build all binaries
153+
make image # Build container image
154+
make local-build # Build with 'local' tag
155+
```
156+
157+
### Testing
158+
```bash
159+
make unit # Unit tests with setup-envtest
160+
make e2e # E2E tests (requires cluster)
161+
make e2e-local # Build + deploy + e2e locally
162+
make coverage # Unit tests with coverage
163+
```
164+
165+
### Code Generation
166+
```bash
167+
make gen-all # Generate all code (clients, mocks, manifests)
168+
make codegen # Generate K8s clients and deep-copy methods
169+
make mockgen # Generate test mocks
170+
make manifests # Copy CRD manifests from operator-framework/api
171+
```
172+
173+
### Local Development
174+
```bash
175+
make run-local # Complete local setup
176+
# OR step-by-step:
177+
make kind-create # Create kind cluster (kind-olmv0)
178+
make cert-manager-install
179+
make deploy # Deploy OLM to cluster
180+
```
181+
182+
## Key Design Patterns
183+
184+
### Control Loop State Machines
185+
186+
**CSV Lifecycle**:
187+
```
188+
None → Pending → InstallReady → Installing → Succeeded
189+
↑ ↓
190+
←----------←------←-------Failed
191+
```
192+
193+
**InstallPlan Lifecycle**:
194+
```
195+
None → Planning → RequiresApproval → Installing → Complete
196+
↓ ↓
197+
←-------←-------Failed
198+
```
199+
200+
**Subscription Lifecycle**:
201+
```
202+
None → UpgradeAvailable → UpgradePending → AtLatestKnown
203+
↑ ↓
204+
←-----------←-----------←-------------←
205+
```
206+
207+
### Dependency Resolution
208+
- CSVs declare owned CRDs (what they provide) and required CRDs (what they need)
209+
- Catalog Operator resolves transitive dependencies via graph traversal
210+
- InstallPlans capture the complete dependency closure
211+
- Resolution is based on (Group, Version, Kind) - no version pinning
212+
213+
### Catalog and Channel Model
214+
```
215+
Package (e.g., "etcd")
216+
├── Channel: "stable" → CSV v0.9.4 → CSV v0.9.3 → CSV v0.9.2
217+
├── Channel: "alpha" → CSV v0.10.0
218+
└── Channel: "beta" → CSV v0.9.4
219+
```
220+
221+
Subscriptions track a channel; OLM follows the replacement chain to upgrade operators.
222+
223+
## Testing Strategy
224+
225+
### Unit Tests
226+
- Use `setup-envtest` for real Kubernetes API behavior
227+
- Race detection enabled by default (`CGO_ENABLED=1`)
228+
- Mock generation via `counterfeiter` and `gomock`
229+
230+
### E2E Tests
231+
- Full cluster testing with Ginkgo/Gomega BDD framework
232+
- Test images in `test/images/` hosted on quay.io/olmtest
233+
- Default timeout: 90 minutes (configurable via `E2E_TIMEOUT`)
234+
- Uses kind cluster named `kind-olmv0`
235+
236+
### Integration Tests
237+
- Bundle and catalog integration testing
238+
- Upgrade path validation
239+
- Multi-tenant scenario testing
240+
241+
## Important Dependencies
242+
243+
| Dependency | Version | Purpose |
244+
|------------|---------|---------|
245+
| kubernetes | v0.34.1 | Core K8s libraries |
246+
| controller-runtime | v0.22.2 | Controller framework |
247+
| operator-framework/api | v0.35.0 | OLM API definitions |
248+
| operator-registry | v1.60.0 | Catalog/bundle tooling |
249+
| ginkgo/gomega | v2.26.0 / v1.38.2 | BDD testing |
250+
251+
## Common Tasks for AI Agents
252+
253+
### Understanding Operator Installation Flow
254+
1. User creates Subscription pointing to catalog/package/channel
255+
2. Catalog Operator queries catalog for latest CSV in channel
256+
3. Catalog Operator creates InstallPlan with resolved dependencies
257+
4. Upon approval, Catalog Operator creates CRDs and CSV
258+
5. OLM Operator detects CSV, validates requirements, creates Deployment/RBAC
259+
6. CSV transitions through: Pending → InstallReady → Installing → Succeeded
260+
261+
### Debugging Installation Issues
262+
- Check CSV status and conditions: `kubectl get csv -o yaml`
263+
- Examine InstallPlan: `kubectl get ip -o yaml`
264+
- Review operator logs: OLM Operator and Catalog Operator pods in `olm` namespace
265+
- Verify OperatorGroup configuration for namespace scoping
266+
267+
### Adding New Functionality
268+
**REMINDER**: This repository is in maintenance mode - only critical fixes accepted!
269+
270+
For understanding existing code:
271+
1. Controllers follow controller-runtime patterns with Reconcile() methods
272+
2. Use informers and listers from `pkg/lib/operatorlister`
273+
3. Queue-based event handling via `pkg/lib/queueinformer`
274+
4. Always respect OperatorGroup namespace scoping
275+
276+
### Code Generation
277+
Most code is generated - don't hand-edit:
278+
- Client code: Generated from CRDs using k8s.io/code-generator
279+
- Deep-copy methods: Auto-generated for all API types
280+
- Mocks: Generated via counterfeiter/gomock
281+
- CRD manifests: Copied from operator-framework/api repository
282+
283+
Always run `make gen-all` after API changes.
284+
285+
## Navigation Tips
286+
287+
### Finding Controllers
288+
- OLM Operator controllers: `pkg/controller/operators/`
289+
- Catalog Operator controllers: `pkg/controller/registry/`, subscription/installplan logic in `pkg/controller/operators/catalog/`
290+
291+
### Finding API Definitions
292+
- CRDs are defined in operator-framework/api (external dependency)
293+
- Clients are in `pkg/api/client/`
294+
- Listers are in `pkg/lib/operatorlister/`
295+
296+
### Finding Business Logic
297+
- CSV installation: `pkg/controller/operators/olm/`
298+
- Dependency resolution: `pkg/controller/registry/resolver/`
299+
- Catalog management: `pkg/controller/registry/reconciler/`
300+
- InstallPlan execution: `pkg/controller/install/`
301+
302+
### Finding Utilities
303+
- Owner references: `pkg/lib/ownerutil/`
304+
- Scoped clients: `pkg/lib/scoped/`
305+
- Operator clients: `pkg/lib/operatorclient/`
306+
- Queue informers: `pkg/lib/queueinformer/`
307+
308+
## Anti-Patterns to Avoid
309+
310+
1. **Don't bypass OperatorGroup scoping** - Always use scoped clients for multi-tenancy
311+
2. **Don't modify generated code** - Edit source (CRDs, annotations) and regenerate
312+
3. **Don't skip approval for InstallPlans** - Respect manual approval settings
313+
4. **Don't create CSVs directly** - Use Subscriptions/Catalogs for proper lifecycle
314+
5. **Don't ignore owner references** - Critical for garbage collection
315+
316+
## Resources and Links
317+
318+
- [OLM Documentation](https://olm.operatorframework.io/)
319+
- [Architecture Doc](doc/design/architecture.md)
320+
- [Philosophy](doc/design/philosophy.md)
321+
- [Design Proposals](doc/contributors/design-proposals/)
322+
- [Operator Framework Community](https://github.com/operator-framework/community)
323+
- [OperatorHub.io](https://operatorhub.io/) - Public operator catalog
324+
325+
## Quick Reference
326+
327+
### Resource Short Names
328+
```bash
329+
kubectl get csv # ClusterServiceVersions
330+
kubectl get sub # Subscriptions
331+
kubectl get ip # InstallPlans
332+
kubectl get catsrc # CatalogSources
333+
kubectl get og # OperatorGroups
334+
```
335+
336+
### Common Build Targets
337+
```bash
338+
make build build-utils # Build all binaries
339+
make test unit e2e # Run tests
340+
make lint verify # Code quality
341+
make gen-all # Generate everything
342+
make run-local # Full local dev environment
343+
```
344+
345+
### Tool Management
346+
Tools are managed via **bingo** (`.bingo/Variables.mk`) for reproducible builds. All tools are version-pinned.
347+
348+
## Contributing
349+
350+
See [CONTRIBUTING.md](CONTRIBUTING.md) and [CLAUDE.md](CLAUDE.md) for detailed guidelines.
351+
352+
**Remember**: OLM v0 is in maintenance mode - only critical security fixes and outage issues are accepted!

0 commit comments

Comments
 (0)