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