Skip to content

Commit dd45a6c

Browse files
committed
Add CLAUDE.md with project documentation
Add guidance for Claude Code covering build commands, testing, architecture overview, dependency management, and commit conventions. Assisted-by: Claude Code
1 parent d7dc751 commit dd45a6c

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

CLAUDE.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the OpenShift Installer, a tool that deploys OpenShift clusters across multiple cloud platforms (AWS, Azure, GCP, vSphere, bare metal, etc.). The installer generates Ignition configs for bootstrap, control plane, and worker nodes, and can optionally provision the underlying infrastructure.
8+
9+
## Quick Reference Documentation
10+
11+
- **Getting Started**: See [README.md](README.md) for quick start guide
12+
- **Contributing**: See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution workflow, linting, testing, and commit message format
13+
- **Build Dependencies**: See [docs/dev/dependencies.md](docs/dev/dependencies.md) for required system packages and Go version
14+
15+
## Build and Development Commands
16+
17+
### Building the Installer
18+
19+
```sh
20+
# Build the openshift-install binary
21+
hack/build.sh
22+
23+
# Skip Terraform build (faster)
24+
SKIP_TERRAFORM=y hack/build.sh
25+
26+
# Development build (with debugging symbols)
27+
MODE=dev hack/build.sh
28+
```
29+
30+
The binary is output to `bin/openshift-install`.
31+
32+
### Testing
33+
34+
```sh
35+
# Run unit tests
36+
hack/go-test.sh
37+
38+
# Run specific tests with additional arguments
39+
hack/go-test.sh -v -run TestSpecificTest
40+
41+
# Run integration tests
42+
hack/go-integration-test.sh
43+
44+
# Run node joiner integration tests
45+
hack/go-integration-test-nodejoiner.sh
46+
```
47+
48+
### Linting and Formatting
49+
50+
See [CONTRIBUTING.md](CONTRIBUTING.md#contribution-flow) for the complete list of linters to run before submitting a PR. Quick reference:
51+
52+
```sh
53+
# Format Go code and organize imports
54+
hack/go-fmt.sh .
55+
56+
# Run Go linter
57+
hack/go-lint.sh $(go list -f '{{ .ImportPath }}' ./...)
58+
59+
# Run Go vet
60+
hack/go-vet.sh ./...
61+
62+
# Check shell scripts
63+
hack/shellcheck.sh
64+
65+
# Format Terraform files
66+
hack/tf-fmt.sh -list -check
67+
68+
# Lint Terraform
69+
hack/tf-lint.sh
70+
71+
# Lint YAML files
72+
hack/yaml-lint.sh
73+
```
74+
75+
### Generating Code
76+
77+
```sh
78+
# Regenerate mocks for unit tests
79+
hack/go-genmock.sh
80+
81+
# Update install config CRD (after bumping github.com/openshift/api)
82+
go generate ./pkg/types/installconfig.go
83+
```
84+
85+
## Architecture
86+
87+
### Asset-Based Architecture
88+
89+
The installer uses a dependency-graph architecture where everything is an "Asset". See [docs/design/assetgeneration.md](docs/design/assetgeneration.md) for complete details.
90+
91+
Key points:
92+
- **Asset**: Interface with `Dependencies()`, `Generate()`, and `Name()` methods
93+
- **WritableAsset**: Assets that can be written to disk and loaded
94+
- Main assets in `pkg/asset/`: install-config, manifests, ignition-configs, cluster
95+
96+
### Cluster API Integration
97+
98+
The installer uses Cluster API (CAPI) controllers running in a local control plane. See [docs/dev/cluster-api.md](docs/dev/cluster-api.md) for complete details.
99+
100+
Key points:
101+
- Local `kube-apiserver` and `etcd` run via envtest
102+
- Platform-specific infrastructure providers in `cluster-api/providers/`
103+
- Build CAPI binaries with `hack/build-cluster-api.sh` (called automatically by `hack/build.sh`)
104+
105+
### Platform Types
106+
107+
Platform-specific logic lives in `pkg/types/<platform>/`:
108+
- Platform type definitions
109+
- Validation logic in `validation/`
110+
- Default values in `defaults/`
111+
112+
Supported platforms: AWS, Azure, GCP, vSphere, OpenStack, IBM Cloud, Power VS, Nutanix, bare metal.
113+
114+
### Bootstrap Process
115+
116+
The installer creates a temporary bootstrap machine that:
117+
1. Hosts resources for control plane machines to boot
118+
2. Forms initial etcd cluster with control plane nodes
119+
3. Starts temporary Kubernetes control plane
120+
4. Schedules production control plane on control plane machines
121+
5. Injects OpenShift components
122+
6. Shuts down once cluster is self-hosting
123+
124+
## Dependency Management
125+
126+
See [docs/dev/dependencies.md](docs/dev/dependencies.md) for complete dependency management instructions including:
127+
- Adding/updating Go dependencies with `go get`, `go mod tidy`, `go mod vendor`
128+
- Updating CAPI provider dependencies (detailed multi-step process)
129+
- Special case: updating after bumping `github.com/openshift/api`
130+
131+
**Important**: Always commit vendored code in a separate commit from functional changes.
132+
133+
## Commit Message Format
134+
135+
See [CONTRIBUTING.md](CONTRIBUTING.md#commit-message-format) for the complete format specification.
136+
137+
Quick reference:
138+
```
139+
<subsystem>: <what changed>
140+
141+
<why this change was made>
142+
143+
Fixes #<issue-number>
144+
```
145+
146+
Common subsystems: pkg/asset, pkg/types, terraform, cluster-api, docs
147+
148+
## Testing Approach
149+
150+
The installer has different types of tests with varying external requirements:
151+
152+
### Pure Unit Tests
153+
154+
Most tests in `pkg/` are pure unit tests that test Go code logic without external dependencies. These can be run with:
155+
156+
```sh
157+
go test ./pkg/...
158+
```
159+
160+
These tests should pass in any environment with Go installed.
161+
162+
### Integration Tests with External Requirements
163+
164+
Some test files have external dependencies and will fail without specific tools installed:
165+
166+
#### Node Joiner Integration Tests
167+
- **Location**: `cmd/node-joiner/*_integration_test.go`
168+
- **Requirements**:
169+
- Kubernetes test binaries (etcd, kube-apiserver) via `setup-envtest`
170+
- Uses `sigs.k8s.io/controller-runtime/pkg/envtest` to run a local control plane
171+
- The test script automatically downloads the required binaries
172+
- **Run with**: `hack/go-integration-test-nodejoiner.sh` (handles setup automatically)
173+
- **Example test**: `TestNodeJoinerIntegration`
174+
- **Note**: Running `go test` directly without the script will fail with "fork/exec .../etcd: no such file or directory"
175+
176+
#### Agent Integration Tests
177+
- **Location**: `cmd/openshift-install/*_integration_test.go` (tests with "Agent" in name)
178+
- **Requirements**:
179+
- Write access to cache directory (`~/.cache`)
180+
- `nmstatectl` binary (for network state validation)
181+
- Network access to download RHCOS ISO images
182+
- **Run with**: `hack/go-integration-test.sh`
183+
- **Example test**: `TestAgentIntegration`
184+
185+
#### General Integration Tests
186+
- **Location**: `test/`
187+
- **Requirements**: Various depending on the test (cloud credentials, network access, etc.)
188+
- **Run with**: `hack/go-integration-test.sh`
189+
190+
### Running Tests
191+
192+
```sh
193+
# Run all unit tests (via podman container with all dependencies)
194+
hack/go-test.sh
195+
196+
# Run unit tests directly (may skip integration tests if dependencies missing)
197+
go test ./...
198+
199+
# Run specific package tests
200+
go test ./pkg/asset/...
201+
202+
# Run integration tests (requires full environment setup)
203+
hack/go-integration-test.sh
204+
205+
# Run node joiner integration tests
206+
hack/go-integration-test-nodejoiner.sh
207+
```
208+
209+
### Test Environment Notes
210+
211+
- **Preferred method**: Use `hack/go-test.sh` which runs tests in a podman container with all dependencies
212+
- **Direct execution**: Running `go test` directly may skip integration tests if tools are missing
213+
- Integration test failures due to missing tools (nmstatectl, kubebuilder, etc.) are expected in minimal environments
214+
- All code in `./cmd/...`, `./data/...`, `./pkg/...` must have unit tests
215+
- Use `hack/go-genmock.sh` to regenerate mocks when interfaces change
216+
217+
## Important Notes
218+
219+
- The installer consumes state from a directory (default: current directory)
220+
- Pass `--dir` to specify asset directory for cluster creation/destruction
221+
- Install config can be pre-created and reused across multiple clusters

0 commit comments

Comments
 (0)