Skip to content

Commit c6e166f

Browse files
committed
Add AGENTS.md file
Generated-by: Claude Code
1 parent 8529b7d commit c6e166f

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI code assistants when working with code in this repository.
4+
5+
## Overview
6+
7+
The Cluster Version Operator (CVO) is one of the Cluster Operators that run in every OpenShift cluster. CVO consumes an artifact called a "release payload image," which represents a specific version of OpenShift. The release payload image contains the resource manifests necessary for the cluster to function, including manifests for all Cluster Operators. CVO reconciles the resources within the cluster to match the manifests in the release payload image, implementing cluster upgrades by this reconciliation process.
8+
9+
CVO continuously monitors for available updates from the OpenShift Update Service (OSUS) and orchestrates the systematic rollout of new versions. When provided a release payload image for a newer OpenShift version, CVO reconciles all Cluster Operators to their updated versions, and those Cluster Operators similarly update their operands, completing the cluster upgrade.
10+
11+
## Building and Testing
12+
13+
### Build commands
14+
```bash
15+
# Build the CVO binary
16+
make build # Runs hack/build-go.sh, outputs to _output/
17+
18+
# Build the CVO container image
19+
./hack/build-image.sh # Creates local image with git version tag
20+
21+
# Push development image to a registry
22+
REPO=quay.io/yourname ./hack/push-image.sh
23+
24+
# Format code
25+
make format # Run go fmt on all packages
26+
```
27+
28+
### Testing commands
29+
```bash
30+
# Unit tests
31+
make test # Runs gotestsum with JUnit XML output to _output/junit.xml
32+
33+
# Single package test
34+
gotestsum --packages="./pkg/cvo"
35+
36+
# Integration tests (requires KUBECONFIG with admin credentials for a disposable cluster)
37+
make integration-test # Runs tests with TEST_INTEGRATION=1 against real cluster
38+
39+
# Update test metadata (for tests in test/ directory)
40+
make update
41+
42+
# Verification
43+
make verify # Runs verify-yaml and verify-update
44+
make verify-yaml # Validates YAML manifests
45+
make verify-update # Ensures generated files are up-to-date
46+
```
47+
48+
## Architecture
49+
50+
### Core Components
51+
52+
#### Main Operator Loop (pkg/cvo/cvo.go)
53+
- The `Operator` struct is the central controller
54+
- Watches the `ClusterVersion` resource in cluster
55+
- Implements a reconciliation loop that is the single writer of `ClusterVersion` status
56+
- Uses a work queue pattern with 15 max retries for failed operations
57+
- Periodically checks for updates from configured upstream server
58+
- Maintains conditions: `Progressing`, `Available`, `Failing`, `Upgradeable`, `RetrievedUpdates`
59+
60+
#### SyncWorker (pkg/cvo/sync_worker.go)
61+
- Abstracts payload synchronization via `ConfigSyncWorker` interface
62+
- Manages the actual application of manifests from release payload images
63+
- Handles payload retrieval, verification, and application
64+
- Uses rate limiting and retry logic for resilient updates
65+
- Reports status back to main operator via `SyncWorkerStatus` channel
66+
67+
#### Payload Management (pkg/payload/)
68+
- `State` enum defines update modes: `UpdatingPayload`, `ReconcilingPayload`, `InitializingPayload`, `PrecreatingPayload`
69+
- `UpdatingPayload`: Conservative ordering when transitioning versions, errors block dependent operators
70+
- `ReconcilingPayload`: Maintains current state, recreates resources without strict ordering
71+
- `InitializingPayload`: First-time deployment, fast progress with tolerance for transient errors
72+
- Release payloads stored in two directories:
73+
- `manifests/`: CVO's own manifests
74+
- `release-manifests/`: Manifests for other cluster operators
75+
- Task graph orchestrates ordered application of manifests based on dependencies
76+
77+
#### Resource Libraries (lib/)
78+
- `resourcebuilder/`: Builds Kubernetes resources from manifests
79+
- `resourceapply/`: Applies resources with proper merge semantics for different API types
80+
- `resourcemerge/`: Merges resource specifications
81+
- `resourceread/`: Reads and validates manifests
82+
- `capability/`: Manages cluster capability filtering
83+
84+
**Note**: `lib/resourcebuilder/resourcebuilder.go` and `lib/resourceread/resourceread.go` are auto-generated by `hack/generate-lib-resources.py`.
85+
86+
#### Update Service Integration (pkg/cincinnati/)
87+
- Cincinnati client that communicates with OSUS to fetch available updates
88+
- Cincinnati is an update protocol for representing transitions between releases and facilitating automatic updates
89+
- Fetches and parses update graphs with nodes (release versions) and edges (upgrade paths)
90+
- Supports conditional edges based on cluster-specific conditions
91+
- Returns both unconditional and conditional update recommendations
92+
93+
#### Preconditions (pkg/payload/precondition/)
94+
- Validates cluster readiness before applying updates
95+
- Checks prevent upgrades when cluster is in unhealthy state
96+
- ClusterVersion-specific preconditions in `precondition/clusterversion/`
97+
98+
### Entry Points
99+
100+
#### cmd/cluster-version-operator/main.go
101+
- Uses cobra for CLI structure
102+
- Actual start logic delegated to `pkg/start/` package
103+
104+
##### pkg/start/start.go
105+
- Initializes and launches core CVO control loops
106+
- Sets up client connections, informers, and signal handling
107+
- Creates and starts the main `Operator` instance
108+
109+
#### cmd/cluster-version-operator-tests/main.go
110+
- OpenShift tests extension for CVO integration tests
111+
- Uses openshift-tests-extension framework to contribute CVO tests to OpenShift test suites
112+
113+
### Key Patterns
114+
115+
#### Release Payload Image Structure
116+
- Release payload images are OCI container images containing:
117+
- CVO binary at a specific version
118+
- Manifest files in `manifests/` and `release-manifests/`
119+
- `release-metadata` file with Cincinnati update graph info
120+
- `image-references` file mapping component names to images
121+
122+
#### Update Flow
123+
1. CVO fetches available updates from configured upstream (OSUS)
124+
2. Updates stored in `status.availableUpdates` and `status.conditionalUpdates` of `ClusterVersion` resource
125+
3. User/admin sets `spec.desiredUpdate` to trigger upgrade
126+
4. Validates payload signatures
127+
5. CVO retrieves new release payload image
128+
6. Applies manifests systematically using task graph
129+
7. Monitors cluster operator readiness during rollout
130+
8. Updates `ClusterVersion` status conditions throughout process
131+
132+
#### Manifest Application Order
133+
- Task graph in `pkg/payload/task_graph.go` determines ordering
134+
- Dependencies between operators enforced during updates
135+
- Parallel application during reconciliation for faster recovery
136+
137+
## Debugging CVO in Cluster
138+
139+
```bash
140+
# Check CVO deployment and pods
141+
oc get deployment -n openshift-cluster-version cluster-version-operator
142+
oc get pods -n openshift-cluster-version -l k8s-app=cluster-version-operator
143+
144+
# View logs
145+
oc logs -n openshift-cluster-version -l k8s-app=cluster-version-operator
146+
147+
# Inspect ClusterVersion status
148+
oc get clusterversion version -o yaml
149+
oc adm upgrade
150+
```
151+
152+
## Common File Locations
153+
154+
- **Manifests**: `install/` - YAML files for CVO deployment itself
155+
- **Build scripts**: `hack/` - Shell scripts for building, testing, pushing
156+
- **Integration tests**: `test/` - Separate integration test suite
157+
- **Development documentation**: `docs/dev/` - Development guides and workflows
158+
- `README.md` - Building, testing, and publishing development CVO images
159+
- `feed-cvo-custom-graphs.md` - Testing with custom update graphs
160+
- `run-cvo-locally.md` - Running CVO outside cluster
161+
162+
## Commit Message Format
163+
164+
Follow the conventional format with subsystem prefix:
165+
```text
166+
<subsystem>: <what changed>
167+
168+
<why this change was made>
169+
170+
Fixes #<issue-number>
171+
```
172+
173+
Subsystems include: `pkg/cvo`, `pkg/payload`, `lib/resourceapply`, `hack`, etc.
174+
175+
## Important Notes
176+
177+
### ClusterVersion Resource
178+
- The `ClusterVersion` resource is the primary interface for configuring and monitoring CVO
179+
- Follows Kubernetes conventions: `spec` defines desired state, `status` reflects observed state
180+
- Users interact with CVO by setting `spec.desiredUpdate` to trigger upgrades
181+
- Status fields like `availableUpdates` and `conditionalUpdates` show available upgrade paths
182+
183+
### Deployment and Operation
184+
- CVO runs as a single replica in the `openshift-cluster-version` namespace when deployed using repository manifests
185+
- Uses leader election to ensure only one active instance
186+
- Release payload images must be cryptographically verified before application (signature checking)
187+
- Capabilities system filters which manifests are applied based on the cluster's capability set
188+
189+
### Development and Testing
190+
- Never test against production clusters - always use disposable test environments
191+
- CVO has significant control over cluster state and can disrupt operations during development

0 commit comments

Comments
 (0)