This guide covers the complete development workflow for HyperFleet API, from initial setup to running tests.
Before running hyperfleet-api, ensure these prerequisites are installed. See PREREQUISITES.md for detailed installation instructions.
- Go 1.24 or higher
- Podman
- PostgreSQL 13+
- Make
Verify installations:
go version # Should show 1.24+
podman version
make --versionSet up your local development environment:
# 1. Generate OpenAPI code and mocks
make generate-all
# 2. Install dependencies
go mod download
# 3. Build the binary
make build
# 4. Setup PostgreSQL database
make db/setup
# 5. Run database migrations
./bin/hyperfleet-api migrate
# 6. Verify database schema
make db/login
\dtImportant: Generated code is not tracked in git. You must run make generate-all after cloning to generate both OpenAPI models and mocks.
This project uses pre-commit hooks for code quality and security checks.
# Install pre-commit
brew install pre-commit # macOS
# or
pip install pre-commit
# Install hooks
pre-commit install
pre-commit install --hook-type pre-push
# Test
pre-commit run --all-filesThe .pre-commit-config.yaml includes rh-pre-commit which requires access to Red Hat's internal GitLab. External contributors can skip it:
# Skip internal hook when committing
SKIP=rh-pre-commit git commit -m "your message"Or comment out the internal hook in .pre-commit-config.yaml.
pre-commit autoupdate
pre-commit run --all-filesmake run-no-authThe service starts on localhost:8000:
- REST API:
http://localhost:8000/api/hyperfleet/v1/ - OpenAPI spec:
http://localhost:8000/api/hyperfleet/v1/openapi - Swagger UI:
http://localhost:8000/api/hyperfleet/v1/openapi.html - Liveness probe:
http://localhost:8080/healthz - Readiness probe:
http://localhost:8080/readyz - Metrics:
http://localhost:9090/metrics
# List clusters
curl http://localhost:8000/api/hyperfleet/v1/clusters | jq
# Create a cluster
curl -X POST http://localhost:8000/api/hyperfleet/v1/clusters \
-H "Content-Type: application/json" \
-d '{
"kind": "Cluster",
"name": "prod-cluster-1",
"spec": {...},
"labels": {"env": "production"}
}' | jqmake run
ocm login --token=${OCM_ACCESS_TOKEN} --url=http://localhost:8000
ocm get /api/hyperfleet/v1/clustersSee Deployment and Authentication for complete configuration options.
# Unit tests
make test
# Integration tests (requires running database)
make test-integrationAll API endpoints have integration test coverage.
# Generate OpenAPI client code
make generate
# Generate mocks for testing
make generate-mocks
# Generate both OpenAPI and mocks
make generate-all
# Build binary
make build
# Run database migrations
./bin/hyperfleet-api migrate
# Start server (no auth)
make run-no-auth
# Run tests
make test
make test-integration
# Database management
make db/setup # Create PostgreSQL container
make db/teardown # Remove PostgreSQL container
make db/login # Connect to database shell| Command | Description |
|---|---|
make generate |
Generate Go models from OpenAPI spec |
make generate-mocks |
Generate mock implementations for testing |
make generate-all |
Generate both OpenAPI models and mocks |
make build |
Build hyperfleet-api executable to bin/ |
make test |
Run unit tests |
make test-integration |
Run integration tests |
make run-no-auth |
Start server without authentication |
make run |
Start server with OCM authentication |
make db/setup |
Create PostgreSQL container |
make db/teardown |
Remove PostgreSQL container |
make db/login |
Connect to database shell |
HyperFleet API generates Go models from OpenAPI specifications using openapi-generator-cli.
Workflow:
openapi/openapi.yaml
↓
make generate (podman + openapi-generator-cli)
↓
pkg/api/openapi/model_*.go (Go structs)
pkg/api/openapi/api/openapi.yaml (embedded spec)
Generated artifacts:
- Go model structs with JSON tags (
model_*.go) - Fully resolved OpenAPI specification (embedded in binary)
Important:
- Generated files are NOT tracked in git
- Must run
make generateafter cloning - Must run after OpenAPI spec updates
OpenAPI spec source:
The openapi/openapi.yaml is maintained in the hyperfleet-api-spec repository using TypeSpec. When the spec changes, the compiled YAML is copied here. Developers working on hyperfleet-api only need to run make generate - no TypeSpec knowledge required.
Commands:
# Generate Go models from OpenAPI spec
make generate
# Generate both OpenAPI models and mocks
make generate-allTroubleshooting:
# If "pkg/api/openapi not found"
make generate
go mod download
# If generator container fails
podman info # Check podman is running
make generateMock implementations of service interfaces are used for unit testing. Mocks are generated using mockgen.
When to regenerate mocks:
- After modifying service interface definitions in
pkg/services/ - When adding or removing methods from service interfaces
- After initial clone (mocks are not committed to git)
How it works:
Service files contain //go:generate directives that specify how to generate mocks:
//go:generate mockgen-v0.6.0 -source=cluster.go -package=services -destination=cluster_mock.goCommands:
# Generate mocks only
make generate-mocks
# Generate OpenAPI models and mocks together
make generate-allHyperFleet API uses bingo to manage Go tool dependencies with pinned versions.
Managed tools:
mockgen- Mock generation for testinggolangci-lint- Code lintinggotestsum- Enhanced test output
Common operations:
# Install all tools
bingo get
# Install a specific tool
bingo get <tool>
# Update a tool to latest version
bingo get <tool>@latest
# List all managed tools
bingo listTool versions are tracked in .bingo/*.mod files and loaded automatically via include .bingo/Variables.mk in the Makefile.
-
Create a feature branch:
git checkout -b feature/my-feature
-
Make your changes to the code
-
Update OpenAPI spec if needed:
- Make changes in the hyperfleet-api-spec repository
- Copy updated
openapi.yamlto this repository - Run
make generateto regenerate Go models
-
Regenerate mocks if service interfaces changed:
make generate-mocks
-
Run tests:
make test make test-integration -
Commit your changes:
git add . git commit -m "feat: add new feature" # Pre-commit hooks will run automatically
-
Push and create pull request:
git push origin feature/my-feature
Problem: Missing generated OpenAPI code
Solution:
make generate
go mod downloadProblem: Missing generated mock implementations
Solution:
make generate-mocksProblem: Cannot connect to PostgreSQL
Solution:
# Check if container is running
podman ps | grep postgres
# Restart database
make db/teardown
make db/setupProblem: Integration tests failing
Solution:
# Ensure database is running
make db/setup
# Run migrations
./bin/hyperfleet-api migrate
# Run tests again
make test-integration- Database - Database schema and migrations
- Deployment - Container and Kubernetes deployment
- API Resources - API endpoints and data models