Skip to content

Commit f0cb4ab

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 f0cb4ab

File tree

1 file changed

+257
-0
lines changed

1 file changed

+257
-0
lines changed

CLAUDE.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
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:
147+
- `baremetal`, `vsphere`, `aws`, `azure`, `gcp`, etc. - for platform-specific changes
148+
- `agent`, `ibi` (image-based installer) - for installation method changes
149+
- `terraform`, `cluster-api` - for infrastructure provider changes
150+
- `docs` - for documentation changes
151+
- `unit tests`, `integration tests` - for test-only changes (makes it clear the change doesn't affect the actual installer)
152+
153+
## Testing Approach
154+
155+
The installer has different types of tests with varying external requirements:
156+
157+
### Pure Unit Tests
158+
159+
Most tests in `pkg/` are pure unit tests that test Go code logic without external dependencies. These can be run with:
160+
161+
```sh
162+
go test ./pkg/...
163+
```
164+
165+
These tests should pass in any environment with Go installed.
166+
167+
### Integration Tests with External Requirements
168+
169+
Some test files have external dependencies and will fail without specific tools installed:
170+
171+
#### Node Joiner Integration Tests
172+
- **Location**: `cmd/node-joiner/*_integration_test.go`
173+
- **Requirements**:
174+
- Kubernetes test binaries (etcd, kube-apiserver) via `setup-envtest`
175+
- Uses `sigs.k8s.io/controller-runtime/pkg/envtest` to run a local control plane
176+
- The test script automatically downloads the required binaries
177+
- **Run with**: `hack/go-integration-test-nodejoiner.sh` (handles setup automatically)
178+
- **Example test**: `TestNodeJoinerIntegration`
179+
- **Note**: Running `go test` directly without the script will fail with "fork/exec .../etcd: no such file or directory"
180+
181+
#### Agent Integration Tests
182+
- **Location**: `cmd/openshift-install/*_integration_test.go` (tests with "Agent" in name)
183+
- **Requirements**:
184+
- `oc` binary (OpenShift CLI) in `$PATH`
185+
- `nmstatectl` binary (for network state validation)
186+
- Registry credentials for `registry.ci.openshift.org` (for full test pass)
187+
- **Run with**: `hack/go-integration-test.sh`
188+
- **Example test**: `TestAgentIntegration`
189+
190+
**Installing oc**: Download and extract the OpenShift client tools from the official mirror:
191+
192+
```sh
193+
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz -o /tmp/oc.tar.gz
194+
mkdir -p ~/.local/bin
195+
tar -xzf /tmp/oc.tar.gz -C ~/.local/bin oc kubectl
196+
rm /tmp/oc.tar.gz
197+
```
198+
199+
Make sure `~/.local/bin` is in your `$PATH`.
200+
201+
**Installing nmstatectl**: Some tests validate network configuration using nmstate. This requires running dnf outside the sandbox:
202+
203+
```sh
204+
sudo dnf install -y nmstate
205+
```
206+
207+
Without `nmstatectl`, network configuration tests will fail with:
208+
209+
```
210+
failed to validate network yaml for host 0, install nmstate package, exec: "nmstatectl": executable file not found in $PATH
211+
```
212+
213+
**Note on registry credentials**: Many agent integration tests query the CI registry (`registry.ci.openshift.org`) to extract release image information. Without credentials, tests will fail with:
214+
215+
```
216+
error: image "registry.ci.openshift.org/origin/release:4.21" not found: manifest unknown: manifest unknown
217+
```
218+
219+
In CI environments, credentials are provided via the `AUTH_FILE` environment variable.
220+
221+
#### General Integration Tests
222+
- **Location**: `test/`
223+
- **Requirements**: Various depending on the test (cloud credentials, network access, etc.)
224+
- **Run with**: `hack/go-integration-test.sh`
225+
226+
### Running Tests
227+
228+
```sh
229+
# Run all unit tests (via podman container with all dependencies)
230+
hack/go-test.sh
231+
232+
# Run unit tests directly (may skip integration tests if dependencies missing)
233+
go test ./...
234+
235+
# Run specific package tests
236+
go test ./pkg/asset/...
237+
238+
# Run integration tests (requires full environment setup)
239+
hack/go-integration-test.sh
240+
241+
# Run node joiner integration tests
242+
hack/go-integration-test-nodejoiner.sh
243+
```
244+
245+
### Test Environment Notes
246+
247+
- **Preferred method**: Use `hack/go-test.sh` which runs tests in a podman container with all dependencies
248+
- **Direct execution**: Running `go test` directly may skip integration tests if tools are missing
249+
- Integration test failures due to missing tools (nmstatectl, kubebuilder, etc.) are expected in minimal environments
250+
- All code in `./cmd/...`, `./data/...`, `./pkg/...` must have unit tests
251+
- Use `hack/go-genmock.sh` to regenerate mocks when interfaces change
252+
253+
## Important Notes
254+
255+
- The installer consumes state from a directory (default: current directory)
256+
- Pass `--dir` to specify asset directory for cluster creation/destruction
257+
- Install config can be pre-created and reused across multiple clusters

0 commit comments

Comments
 (0)