Skip to content

Commit 47c9048

Browse files
nixpanicceph-csi-bot
authored andcommitted
doc: add AGENTS.md with guidance for AI agents
Add comprehensive documentation for AI agents (including Claude Code) working with the ceph-csi codebase. Includes: - Build commands emphasizing containerized builds - Testing workflows (unit, static checks, e2e) - Code architecture and directory structure - Development requirements and conventions - Commit message format with Assisted-by requirement This file helps AI agents understand the project structure and development practices, with special emphasis on using containerized builds/tests to avoid requiring local Ceph development libraries. Assisted-by: Claude Code (Anthropic) <claude-code@anthropic.com> Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent ca2c911 commit 47c9048

File tree

1 file changed

+293
-0
lines changed

1 file changed

+293
-0
lines changed

AGENTS.md

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI agents (including Claude Code from
4+
claude.ai/code) when working with code in this repository.
5+
6+
## Project Overview
7+
8+
Ceph-CSI implements Container Storage Interface (CSI) drivers for Ceph
9+
storage, enabling dynamic provisioning and management of Ceph volumes in
10+
Kubernetes. The project supports multiple storage types: RBD (block),
11+
CephFS (filesystem), NFS, and NVMeoF, all packaged in a single binary.
12+
13+
## Build Commands
14+
15+
**Recommended:** Use `make containerized-build` for all compilation tasks.
16+
Local builds only work when Ceph libraries and headers (`librados-devel`,
17+
`librbd-devel`, `libcephfs-devel`) are installed on the system.
18+
19+
### Containerized Build (Recommended)
20+
21+
```bash
22+
make containerized-build # Build cephcsi binary in container (output: _output/cephcsi)
23+
make containerized-build TARGET=<target> # Build specific target in container
24+
make containerized-build TARGET=e2e.test # Build e2e test binary in container
25+
```
26+
27+
### Local Build (Only if Ceph libraries are available)
28+
29+
```bash
30+
make # Build cephcsi binary locally
31+
make cephcsi # Same as make
32+
make e2e.test # Build e2e test binary locally
33+
```
34+
35+
### Container Images
36+
37+
```bash
38+
make image-cephcsi # Build container image
39+
```
40+
41+
The built binary will be in `_output/` directory.
42+
43+
### Environment Variables
44+
45+
- `GO_TAGS`: Build tags (default: ceph version + ceph_preview)
46+
- `CONTAINERIZED`: Set to "yes" for containerized builds
47+
- `CSI_IMAGE_NAME`: Container image name (default: quay.io/cephcsi/cephcsi)
48+
- `CSI_IMAGE_VERSION`: From build.env, default "canary"
49+
50+
## Testing
51+
52+
### Unit Tests (Containerized - Recommended)
53+
54+
```bash
55+
make containerized-test # Run all tests in container (go-test + static-check)
56+
make containerized-test TARGET=static-check # Run specific test target in container
57+
make containerized-test TARGET=go-test # Run only Go unit tests in container
58+
```
59+
60+
### Local Unit Tests
61+
62+
```bash
63+
make test # Run all tests locally (go-test + static-check + mod-check)
64+
make go-test # Run Go unit tests only
65+
```
66+
67+
**Note:** Use `make containerized-test` for running unit tests to ensure
68+
consistent environment.
69+
70+
### Static Checks
71+
72+
```bash
73+
make static-check # Run all static checks (go-lint + lint-extras + codespell)
74+
make go-lint # Run golangci-lint
75+
make lint-extras # Run shell/markdown/yaml/helm/python linters
76+
make codespell # Spell checking
77+
```
78+
79+
### End-to-End Tests
80+
81+
```bash
82+
make e2e.test # Build e2e test binary
83+
make run-e2e # Run e2e tests
84+
make run-e2e E2E_ARGS="--test-cephfs=false" # Run with specific args
85+
```
86+
87+
**Important:** E2E tests require BOTH a functional Kubernetes cluster AND a
88+
functional Ceph cluster. Only run these tests when both are available and
89+
properly configured. See `e2e/` directory for test implementations.
90+
91+
### Module Checks
92+
93+
```bash
94+
make mod-check # Verify go.mod, vendor, and go.sum are up to date
95+
```
96+
97+
This runs `go mod tidy && go mod vendor && go mod verify` across all modules.
98+
99+
## Code Architecture
100+
101+
### Multi-Driver Architecture
102+
103+
The project uses a single binary (`cmd/cephcsi.go`) that can run as different
104+
driver types based on the `-type` flag:
105+
106+
- `rbd` - RBD block storage driver (internal/rbd/)
107+
- `cephfs` - CephFS filesystem driver (internal/cephfs/)
108+
- `nfs` - NFS driver (internal/nfs/)
109+
- `nvmeof` - NVMe-oF driver (internal/nvmeof/)
110+
- `liveness` - Liveness probe server (internal/liveness/)
111+
- `controller` - Kubernetes controller (internal/controller/)
112+
113+
Each driver implements the CSI spec with three main components:
114+
115+
- **IdentityServer**: Driver identification and capabilities
116+
- **ControllerServer**: Volume lifecycle (create, delete, attach, detach,
117+
snapshot, clone)
118+
- **NodeServer**: Node-local operations (stage, unstage, publish, unpublish,
119+
mount)
120+
121+
### Directory Structure
122+
123+
#### Core Implementation
124+
125+
- `cmd/` - Main entry point, flag parsing, driver initialization
126+
- `internal/cephfs/` - CephFS CSI driver implementation
127+
- `internal/rbd/` - RBD CSI driver implementation
128+
- `internal/nfs/` - NFS CSI driver implementation
129+
- `internal/nvmeof/` - NVMe-oF CSI driver implementation
130+
- `internal/util/` - Shared utilities (connection, journal, encryption, KMS)
131+
- `internal/csi-common/` - Common CSI server implementations
132+
- `internal/journal/` - Volume journaling for idempotency
133+
- `internal/kms/` - Key Management System integrations (Vault, AWS, Azure, etc.)
134+
135+
#### Testing & Deployment
136+
137+
- `e2e/` - End-to-end tests with Ginkgo framework
138+
- `deploy/` - Kubernetes deployment manifests (YAML templates, Helm charts)
139+
- `scripts/` - Build, test, and deployment scripts
140+
141+
#### Other
142+
143+
- `api/` - Separate Go module for API definitions
144+
- `pkg/` - Exported packages (minimal, most code in internal/)
145+
- `docs/` - Documentation
146+
147+
### Go Modules
148+
149+
The repository has 4 separate Go modules:
150+
151+
- `./` - Main ceph-csi module
152+
- `e2e/` - E2E test module
153+
- `api/` - API definitions module
154+
- `actions/retest` - GitHub Actions module
155+
156+
When making dependency changes, you may need to run `make mod-check` to
157+
update all modules.
158+
159+
## Development Requirements
160+
161+
### Prerequisites
162+
163+
- Go 1.25.0+ (see build.env for exact version)
164+
- CGO must be enabled (`CGO_ENABLED=1`) - required for go-ceph bindings
165+
- Ceph development libraries: `librados-devel`, `librbd-devel`,
166+
`libcephfs-devel`
167+
- For containerized builds: podman or docker
168+
169+
### Code Conventions
170+
171+
#### Import Organization
172+
173+
```go
174+
import (
175+
// Standard library
176+
"os"
177+
"path"
178+
179+
// Third-party packages
180+
"github.com/pborman/uuid"
181+
182+
// ceph-csi packages
183+
"github.com/ceph/ceph-csi/internal/util"
184+
)
185+
```
186+
187+
#### Error Handling
188+
189+
- Use variable name `err` for errors
190+
- Reuse `err` in scope, don't create `errWrite`, `errRead`, etc.
191+
- Don't ignore errors with `_` unless intentional
192+
- Error strings should not start with capital letter
193+
- Error types should end with `Error`
194+
195+
#### Logging
196+
197+
- Utility functions should NOT log - let callers handle errors
198+
- Use DEBUG for diagnostic info for developers/sysadmins
199+
- Use INFO for user/sysadmin information in normal operations
200+
- Use WARN for failures with workarounds/retries
201+
- Use ERROR for operation failures (not service failures)
202+
203+
#### Line Length
204+
205+
- Maximum 120 characters per line
206+
- Break long function calls across multiple lines for readability
207+
208+
#### Variable Naming
209+
210+
- Keep variable names short for local scope
211+
- Don't export functions/variables until needed externally
212+
213+
### Commit Message Format
214+
215+
```
216+
<component>: <subject of the change>
217+
218+
<paragraph(s) with reason/description>
219+
220+
Assisted-by: Claude Code <noreply@anthropic.com>
221+
Signed-off-by: Your Name <your.email@example.org>
222+
```
223+
224+
**Component prefixes**: `cephfs`, `rbd`, `nfs`, `nvmeof`, `doc`, `util`,
225+
`journal`, `helm`, `deploy`, `build`, `ci`, `e2e`, `cleanup`, `revert`
226+
227+
- Subject line: max 70 characters
228+
- Body: wrap at 80 characters
229+
- All commits require DCO sign-off (`git commit -s`)
230+
- **Add `Assisted-by:` line when AI agents (like Claude Code) helped with
231+
the changes**
232+
- Focus on "why" not "what" in the description
233+
234+
### Testing Guidelines
235+
236+
- Provide unit tests for new code
237+
- Functional tests go in `e2e/` directory
238+
- Set `CEPH_CSI_RUN_ALL_TESTS=1` to run tests requiring extended permissions
239+
- CI runs containerized tests automatically on PRs
240+
241+
## Common Development Workflows
242+
243+
### Recommended: Containerized Development
244+
245+
For most development tasks, use containerized builds and tests to ensure a
246+
consistent environment without needing to install Ceph development libraries
247+
locally:
248+
249+
```bash
250+
# Build and test in one go
251+
make containerized-build && make containerized-test
252+
```
253+
254+
### Running a Single Test
255+
256+
```bash
257+
# Unit test for a specific package
258+
go test -v github.com/ceph/ceph-csi/internal/rbd
259+
260+
# With build tags (important for ceph integration)
261+
go test -tags=tentacle,ceph_preview -v ./internal/rbd/
262+
```
263+
264+
### Working with Multiple Drivers
265+
266+
The codebase shares common infrastructure (journal, KMS, utilities) across
267+
drivers. When modifying shared code in `internal/util/`, consider impact on
268+
all driver types (RBD, CephFS, NFS, NVMeoF).
269+
270+
### Deployment Manifests
271+
272+
Deployment YAMLs in `deploy/` are generated from templates. To regenerate:
273+
274+
```bash
275+
make generate-deploy
276+
```
277+
278+
## Key Files
279+
280+
- `build.env` - Version specifications for builds and dependencies
281+
- `Makefile` - Primary build and test automation
282+
- `cmd/cephcsi.go` - Main entry point for all driver types
283+
- `scripts/test-go.sh` - Go test runner with coverage support
284+
- `scripts/golangci.yml` - Linter configuration (generated from golangci.yml.in)
285+
- `.pre-commit-config.yaml` - Pre-commit hooks configuration
286+
287+
## Documentation
288+
289+
- Development guide: `docs/development-guide.md`
290+
- Coding conventions: `docs/coding.md`
291+
- RBD deployment: `docs/rbd/deploy.md`
292+
- CephFS deployment: `docs/cephfs/deploy.md`
293+
- Additional docs in `docs/` directory

0 commit comments

Comments
 (0)