This file provides guidance to Claude Code (claude.ai/code) when working with code in the ROSA CLI repository.
Repository Overview and Developer Guidelines (READ THIS IF YOU ARE USING CLAUDE WITH THIS REPOSITORY)
This is the ROSA (Red Hat OpenShift Service on AWS) CLI tool repository - a comprehensive Go-based command-line interface for managing OpenShift clusters on AWS. The project follows enterprise Go development patterns with extensive testing, CI/CD integration, and modular architecture.
This project is public facing, releases every month, and should not be edited without care. Changes can break old version of the CLI, end-to-end tests, release builds, etc. We must exercise extreme caution, and know the changes we are making to the fullest extent. Everything submitted in an MR is on the human submitter, not Claude Code, Claude Code is only a tool.
Go is an open source language. Claude Code should make use of this and make sure not to duplicate code from Go itself, nor any libraries used in this repository.
Do not perform release work, or anything related to releases using this tool.
make rosa- Build the rosa binarymake install- Install rosa to $GOPATH/bingo build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(git rev-parse --short HEAD)" ./cmd/rosa- Build with version info
make test- Run unit tests (excludes /tests/ directory)make coverage- Generate test coverage reportmake lint- Checks for missing code; such as missing error returns, lines being too long, and moremake e2e_test- Run E2E tests with Ginkgo (requires LabelFilter env var)
make fmt- Format code and organize imports using gci (This should be run after every change)make lint- Run golangci-lint with 5m timeoutmake generate- Generate assets and mocks using go-bindata and mockgen
make clean rosa- Remove build artifactsmake diff- Check for uncommitted changes
cmd/rosa/- Main CLI entry point with cobra command structurepkg/- Core business logic organized by domain:aws/- AWS SDK integrations and cloud operations, in the form of an AWS client and static functionsocm/- OpenShift Cluster Manager API interactions, in the form of an OCM client and static functionsmachinepool/,network/,ingress/- These and similarly named directories are for AWS cloud resourcesarguments/,config/,reporter/,helper/,output/,interactive/- And similarly named directories are CLI utilities/helpers
The CLI uses the Cobra framework (https://github.com/spf13/cobra) for it's core functionality with customers, with a hierarchical command structure:
- Root command:
rosa - Major command groups:
create,delete,describe,edit,list,upgrade - Each command group has subcommands for specific resources (clusters, machinepools, etc.)
- In each command directory (such as
cmd/create) there will be subfolders (such ascluster) which indicate the subcommands for that main command (create)
- In each command directory (such as
- Mocks (
pkg/*/mocks/) - Generated mocks for testing, DO NOT EDIT MOCKS, EVER. They are changed viamake generatewithout the need for manual editing - Unit Tests (
pkg/*/*_test.go) - Unit tests which are ran for that package. These, and all tests, should never be changed to accomodate changes. Tests fail to show code is broken, do not change tests to support broken code. Notify users when tests are changed, and explicitly tell them to check over the test changes and to be careful.
- Overall, we want non-cobra logic to be stored in
pkg/. Cobra logic should be in thecmd/commands. Look at the machinepool commands for guidance - The machinepool commands are a good guideline, using the new architecture desired. Use the
outputfiles to create a separate layer between the command and user input - Unit tests should cover as close to 100% of the code as possible, always
- Framework: Ginkgo v2 + Gomega for BDD-style testing
- Unit Tests:
*_test.gofiles with*_suite_test.gosuite initializers - E2E Tests:
tests/e2e/directory with comprehensive integration testing - Test Labels: Sophisticated labeling system for test categorization (Critical, High, day1, day2, etc.)
- Unit tests exclude
/tests/directory - E2E tests use label-based filtering for selective execution
- Parallel execution support with timeout management
- Extensive mocking using gomock for external dependencies
- Suite pattern with
RegisterFailHandler(Fail)andRunSpecs() - Context/Describe/It structure for readable test specifications
- BeforeEach/AfterEach hooks for setup/teardown
- DeferCleanup for resource management
- Gomega and Ginkgo have a lot of similar keywords, use the ones we currently use most commonly in our tests. Such as how we normally check for errors ToNot HaveOccurred
Follow conventional commits with JIRA ticket references:
<TICKET> | <type>: <message>
[optional body]
[optional footer]
Example: OCM-6141 | feat: Allow longer cluster names up to 54 chars
- All code must be covered by tests using Ginkgo
- Use
make fmtto maintain consistent formatting - Follow golangci-lint rules (5m timeout configured)
- No
os.Exit()calls in commands - use proper error handling - Look at the machinepool commands for code quality standards. Specifically,
create machinepool - Use
Run: runinstead ofRunE: runEto prevent usage info on errors
- Add command to
cmd/rosa/structure_test/command_structure.yml - Create
command_args.ymlin appropriatecmd/rosa/structure_test/command_args/subdirectory - List all supported flags in the args file
- Follow existing patterns in the machinepool commands
- Use similar architecture to the create machinepool command, with the user options files and separate logic in
pkg/. Do not always make a new service,machine pool serviceis a special case
- Go 1.24.0 minimum version
- Major dependencies: AWS SDK v2, Cobra, Ginkgo v2, OCM SDK
- Use
go mod tidyandgo mod vendoras part of verification - Mock generation using
go.uber.org/mock/gomock. - DO NOT change any imports unless told to do so specifically, DO NOT run
go mod tidyorgo mod vendorwithout being told to do so specifically
cmd/rosa/main.go- CLI application entry point and command registrationpkg/rosa/runner.go- Core runtime logic
Makefile- Build system and development commandsgo.mod- Go module dependencies.golangciversion- Linter version for CIcodecov.yml- Code coverage configuration
tests/e2e/e2e_suite_test.go- E2E test suitepkg/test/helpers.go- Test utilities and helpers- Individual
*_suite_test.gofiles - Package-level test suites
- Extensive AWS SDK v2 usage across multiple services
- Mock interfaces for all AWS API clients
- CloudFormation template management in
templates/
- Use reporter pattern for consistent error messaging
- Proper error wrapping and context
- Use similar error message formatting to surrounding errors/reporter calls in the file or package being edited for proper context
- Survey-based user interactions in
pkg/interactive/ - Confirmation prompts and input validation
- Support for both interactive and non-interactive modes
- Mocks are typically generated. DO NOT modify generated mock files directly. Instead, generate them with
make generate
- Prefer to use existing functions rather than implement new functions if the existing functions can accomplish the task
- For example, use the existing
EnsureRoleandEnsurePolicyfunctions instead of creating a specific function to attach policies to service account roles
- For example, use the existing
- OIDC = OpenIDConnect
- CLI = Command Line Interface
- HCP = Hosted Control Plane
- Hosted CP = Hosted Control Plane
- VPC = Virtual Private Cloud
- Use context in surrounding file/package for best guidance
- We use the following casing:
variableNameEndingWithAcronymHcp- Notice how the acronym at the end,
HCPis still cased the same as normal words
- Notice how the acronym at the end,
- Be consistent, and verbose, with variable names. Again, look around at similar files/packages for context on this