2017-08-04 13:15:34 -07:00
---
2022-05-12 19:29:40 +02:00
title : Development Flow
2017-08-04 13:15:34 -07:00
---
2018-01-12 18:24:33 +01:00
Thank you for your time and effort to help us improve Rook! Here are a few steps to get started. If you have any questions,
2024-08-20 14:27:17 -04:00
don't hesitate to reach out to us on our [Slack ](https://Rook-io.slack.com ) dev channel. Sign up for the Rook Slack [here ](https://slack.rook.io ).
2018-01-12 16:55:23 -08:00
2017-08-07 12:13:18 -07:00
## Prerequisites
2024-07-03 16:59:00 +05:30
1. [GO 1.22 ](https://golang.org/dl/ ) or greater installed
2017-05-08 14:54:06 -07:00
2. Git client installed
2022-02-19 20:29:02 +09:00
3. GitHub account
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
## Initial Setup
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
### Create a Fork
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
Navigate to [http://github.com/rook/rook ](http://github.com/rook/rook ) and click the "Fork" button.
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
### Clone Your Fork
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
In a console window:
2017-08-07 12:13:18 -07:00
2019-10-25 09:25:07 +02:00
```console
2017-05-08 14:54:06 -07:00
# Create the rook repo path
mkdir -p $GOPATH/src/github.com/rook
2023-05-10 17:24:02 -06:00
# Navigate to the local repo path
2017-05-08 14:54:06 -07:00
cd $GOPATH/src/github.com/rook
2018-12-07 12:42:04 +01:00
# Clone your fork, where <user> is your GitHub account name
2023-02-06 13:17:07 +01:00
git clone https://github.com/<user>/rook.git
2019-02-21 12:25:01 -07:00
```
2018-01-12 18:24:33 +01:00
2023-02-06 13:17:07 +01:00
### Add Upstream Remote
2023-05-10 17:24:02 -06:00
Add the upstream remote to your local git:
2023-02-06 13:17:07 +01:00
```console
# Add 'upstream' to the list of remotes
cd rook
git remote add upstream https://github.com/rook/rook.git
# Verify the remote was added
git remote -v
```
2023-05-10 17:24:02 -06:00
Two remotes should be available: `origin` and `upstream` .
2023-02-06 13:17:07 +01:00
2019-02-21 12:25:01 -07:00
### Build
2023-05-10 17:24:02 -06:00
Before building the project, fetch the remotes to synchronize tags.
2021-08-30 12:54:50 -06:00
2019-10-25 09:25:07 +02:00
```console
2023-05-10 17:24:02 -06:00
# Fetch all remotes
2023-02-06 13:17:07 +01:00
git fetch -a
2022-07-28 10:15:32 +05:30
make build
2019-02-21 12:25:01 -07:00
```
2022-07-28 10:15:32 +05:30
!!! tip
2023-05-10 17:24:02 -06:00
If in a Linux environment and `make build` command throws an error like `unknown revision` for some imports, add `export GOPROXY=https://proxy.golang.org,direct` to `~/.bashrc` . Reload your environment and confirm with `go env` that `GOPROXY` is set.
!!! hint
Make will automatically pick up `podman` if `docker` packages are not available on your machine.
2019-02-21 12:25:01 -07:00
### Development Settings
2023-05-10 17:24:02 -06:00
For consistent whitespace and other formatting in `.go` and other source files, apply
2019-02-21 12:25:01 -07:00
the following settings in your IDE:
2019-10-25 09:25:07 +02:00
* Format with the `goreturns` tool
* Trim trailing whitespace
* Markdown Table of Contents is correctly updated automatically
2019-02-21 12:25:01 -07:00
2022-05-25 14:48:32 +02:00
#### VS Code
2019-02-21 12:25:01 -07:00
2022-05-25 14:48:32 +02:00
!!! tip
2023-05-10 17:24:02 -06:00
VS Code will prompt you automatically with some recommended extensions to install, such as
Markdown, Go, YAML validator, and ShellCheck.
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
VS Code will automatically use the recommended settings in the `.vscode/settings.json` file.
2019-10-25 09:25:07 +02:00
2022-06-27 20:24:13 +05:30
### Self assign Issue
2023-05-10 17:24:02 -06:00
To self-assign an issue that is not yet assigned to anyone else, add a comment in the issue with `/assign` in the body.
2022-06-27 20:24:13 +05:30
2018-08-31 21:44:34 +00:00
## Layout
2023-05-10 17:24:02 -06:00
The overall source code layout is summarized:
2019-10-25 09:25:07 +02:00
```text
2018-08-31 21:44:34 +00:00
rook
├── build # build makefiles and logic to build, publish and release all Rook artifacts
2024-08-23 20:00:43 +05:30
├── deploy
2018-08-31 21:44:34 +00:00
│ ├── charts # Helm charts
│ │ └── rook-ceph
2021-09-10 16:56:55 -06:00
│ │ └── rook-ceph-cluster
2024-04-07 10:57:46 +08:00
│ └── examples # Sample manifests to configure the cluster
2018-08-31 21:44:34 +00:00
│
2023-05-10 17:24:02 -06:00
├── cmd
2018-08-31 21:44:34 +00:00
│ ├── rook # Main command entry points for operators and daemons
│
2023-05-10 17:24:02 -06:00
├── design # Design documents
├── Documentation # Documentation that is published to rook.io
├── images # Rook docker image sources
2018-08-31 21:44:34 +00:00
│
├── pkg
│ ├── apis
2023-05-10 17:24:02 -06:00
│ │ ├── ceph.rook.io # ceph specs used in the CRDs
2019-07-15 16:58:37 -06:00
│ │ │ ├── v1
2018-08-31 21:44:34 +00:00
│ ├── client # auto-generated strongly typed client code to access Rook APIs
│ ├── clusterd
2023-05-10 17:24:02 -06:00
│ ├── daemon # daemons for configuring ceph
2018-08-31 21:44:34 +00:00
│ │ ├── ceph
2024-08-23 20:00:43 +05:30
│ │ ├── discover
│ │ ├── multus
│ │ └── util
2023-05-10 17:24:02 -06:00
│ ├── operator # all reconcile logic and custom controllers
2018-08-31 21:44:34 +00:00
│ │ ├── ceph
│ │ ├── discover
│ │ ├── k8sutil
2024-08-23 20:00:43 +05:30
│ │ └── test
2018-08-31 21:44:34 +00:00
│ ├── util
│ └── version
2023-05-10 17:24:02 -06:00
└── tests
├── framework # integration test framework
│ ├── clients
│ ├── installer
2018-08-31 21:44:34 +00:00
│ └── utils
2023-05-10 17:24:02 -06:00
├── integration # integration test cases that will be invoked during golang testing
2018-08-31 21:44:34 +00:00
└── scripts # scripts for setting up integration and manual testing environments
```
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
## Development
2023-05-10 17:24:02 -06:00
To submit a change, create a branch in your fork and then submit a pull request (PR) from the branch.
2017-05-08 14:54:06 -07:00
2018-03-29 17:27:54 -07:00
### Design Document
For new features of significant scope and complexity, a design document is recommended before work begins on the implementation.
2023-05-10 17:24:02 -06:00
Create a design document if:
2020-06-08 12:35:20 +02:00
* Adding a new CRD
2023-05-10 17:24:02 -06:00
* Adding a significant feature.
2020-06-08 12:35:20 +02:00
2018-03-29 17:27:54 -07:00
For smaller, straightforward features and bug fixes, there is no need for a design document.
2023-05-10 17:24:02 -06:00
Authoring a design document has many advantages:
2018-03-29 17:27:54 -07:00
2023-05-10 17:24:02 -06:00
* Forces the author to think critically about the feature and identify potential issues early in the design
* Obtain agreement amongst the community before code is written to avoid wasted effort in the wrong direction
* Newcomers may more quickly understand the feature
2018-03-29 17:27:54 -07:00
2023-05-10 17:24:02 -06:00
!!! note
2022-10-19 01:07:01 +05:30
Writing code to prototype the feature while working on the design may be very useful to help flesh out the approach.
2018-03-29 17:27:54 -07:00
2022-04-07 18:40:18 +05:30
A design document should be written as a markdown file in the [design folder ](https://github.com/rook/rook/tree/master/design ).
2023-05-10 17:24:02 -06:00
Follow the process outlined in the [design template ](https://github.com/rook/rook/tree/master/design/design_template.md ).
There are many examples of previous design documents in that folder.
Submit a pull request for the design to be discussed and approved by the community, just like any other change to the repository.
2018-03-29 17:27:54 -07:00
2017-08-07 12:13:18 -07:00
### Create a Branch
2023-05-10 17:24:02 -06:00
From a console, create a new branch based on your fork where changes will be developed:
2017-08-07 12:13:18 -07:00
2019-10-25 09:25:07 +02:00
```console
2023-05-10 17:24:02 -06:00
# Update the remotes
2018-02-17 19:36:10 -08:00
git fetch --all
2017-05-08 14:54:06 -07:00
2018-02-17 19:36:10 -08:00
# Create a new branch that is based off upstream master. Give it a simple, but descriptive name.
# Generally it will be two to three words separated by dashes and without numbers.
git checkout -b feature-name upstream/master
2017-05-08 14:54:06 -07:00
```
2017-08-07 12:13:18 -07:00
### Updating Your Fork
2023-05-10 17:24:02 -06:00
During the development lifecycle, keep your branch(es) updated with the latest upstream master. As others on the team push changes, rebase your commits on top of the latest. This avoids unnecessary merge commits and keeps the commit history clean.
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
Whenever an update is needed to the local repository, never perform a merge, **always** rebase. This will avoid merge commits in the git history. If there are any modified files, first stash them with `git stash` .
2017-05-08 14:54:06 -07:00
2019-10-25 09:25:07 +02:00
```console
2018-02-17 19:36:10 -08:00
git fetch --all
2017-05-08 14:54:06 -07:00
git rebase upstream/master
```
2023-05-10 17:24:02 -06:00
Rebasing is a very powerful feature of Git. You need to understand how it works to avoid risking losing your work. Read about it in the [Git documentation ](https://git-scm.com/docs/git-rebase ). Briefly, rebasing does the following:
2019-10-25 09:25:07 +02:00
2023-05-10 17:24:02 -06:00
* "Unwinds" the local commits. The local commits are removed temporarily from the history.
2019-10-25 09:25:07 +02:00
* The latest changes from upstream are added to the history
2023-05-10 17:24:02 -06:00
* The local commits are re-applied one by one
* If there are merge conflicts, there will be a prompt to fix them before continuing. Read the output closely. It will instruct how to complete the rebase.
* When rebasing is completed, all of the commits are restored in the history.
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
## Submitting a Pull Request
2023-05-10 17:24:02 -06:00
After a feature or bug fix is completed in your branch, open a Pull Request (PR)
to the [upstream Rook repository ](https://github.com/rook/rook ).
2021-09-09 12:53:31 -06:00
2023-05-10 17:24:02 -06:00
Before opening the PR:
2017-05-08 14:54:06 -07:00
2023-08-23 18:49:28 +05:30
* If there are code changes, add unit tests and verify that all unit tests are passing. See [Unit Tests ](#unit-tests ) below on running unit tests.
* Rebase on the latest upstream changes
2017-05-08 14:54:06 -07:00
2017-08-07 12:13:18 -07:00
### Regression Testing
2023-05-10 17:24:02 -06:00
All pull requests must pass all continuous integration (CI) tests before they can be merged. These tests
automatically run against every pull request. The results of these tests along with code review feedback determine whether
your request will be merged.
2017-05-08 14:54:06 -07:00
2025-02-24 12:09:20 +01:00
For developers who would like to locally test their changes
as much as possible before pushing
(a behavior that is not required but highly encouraged),
the unit tests and various linters can easily be run locally.
2023-05-10 17:24:02 -06:00
## Unit Tests
2017-08-07 12:13:18 -07:00
2017-05-08 14:54:06 -07:00
From the root of your local Rook repo execute the following to run all of the unit tests:
2017-08-07 12:13:18 -07:00
2019-10-25 09:25:07 +02:00
```console
2018-01-19 16:36:27 -08:00
make test
2017-05-08 14:54:06 -07:00
```
2023-05-10 17:24:02 -06:00
Unit tests for individual packages can be run with the standard `go test` command.
To see code coverage on the packages that you changed, view the `coverage.html` in a browser to inspect your new code.
2017-08-07 12:13:18 -07:00
2019-10-25 09:25:07 +02:00
```console
2017-05-08 14:54:06 -07:00
go test -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
```
2023-05-10 17:24:02 -06:00
### Writing unit tests
2021-09-09 12:53:31 -06:00
Good unit tests start with easily testable code. Small chunks ("units") of code can be easily tested
for every possible input. Higher-level code units that are built from smaller, already-tested units
can more easily verify that the units are combined together correctly.
Common cases that may need tests:
2022-05-12 19:29:40 +02:00
2021-09-09 12:53:31 -06:00
* the feature is enabled
* the feature is disabled
* the feature is only partially enabled, for every possible way it can be partially enabled
* every error that can be encountered during execution of the feature
* the feature can be disabled (including partially) after it was enabled
* the feature can be modified (including partially) after it was enabled
* if there is a slice/array involved, test length = 0, length = 1, length = 3, length == max, length > max
* an input is not specified, for each input
* an input is specified incorrectly, for each input
* a resource the code relies on doesn't exist, for each dependency
2025-02-24 12:09:20 +01:00
## Linting
Run `make lint` to run all linters. This will require the following CLI tools to be installed on the system:
* [yamllint ](https://www.yamllint.com/ )
* [shellcheck ](https://www.shellcheck.net/ )
* [pylint ](https://www.pylint.org/ )
* [markdownlint-cli2 ](https://github.com/DavidAnson/markdownlint-cli2 )
Many of those tools are available via `brew` for MacOS or as Linux distribution packages.
Otherwise refer to the respective project websites for installation instructions.
!!! tip
Run `make help` to see a list of all possible make targets
2023-05-10 17:24:02 -06:00
## Integration Tests
2020-01-03 10:11:07 +01:00
2021-09-09 12:53:31 -06:00
Rook's upstream continuous integration (CI) tests will run integration tests against your changes
automatically.
2023-08-23 18:49:28 +05:30
## Tmate Session
Integration tests will be run in Github actions. If an integration test fails, enable a tmate session to troubleshoot the issue by one of the following steps:
* Restart the CI action and click the "Enable debug logging" checkbox from the github UI, or
* Add the label `debug-ci` to the PR and push your changes again.
See the action details for an ssh connection to the Github runner.
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
## Commit structure
2020-01-03 10:11:07 +01:00
2025-02-27 18:17:13 +01:00
Rook maintainers value clear and detailed commit messages.
2020-01-03 10:11:07 +01:00
2023-05-10 17:24:02 -06:00
Requirements for commits:
2020-01-03 10:11:07 +01:00
2023-05-10 17:24:02 -06:00
* A commit prefix from the [list of known prefixes ](https://github.com/rook/rook/blob/master/.commitlintrc.json )
* At least one paragraph that explains the original issue and the changes in the commit
* The `Signed-off-by` tag is at the end of the commit message, achieved by committing with `git commit -s`
An example acceptable commit message:
2020-01-03 10:11:07 +01:00
```text
component: commit title
2023-05-10 17:24:02 -06:00
This is the commit message. Here I'm explaining what the bug was along with its root cause.
2020-01-03 10:11:07 +01:00
Then I'm explaining how I fixed it.
2023-05-10 17:24:02 -06:00
Signed-off-by: FirstName LastName <email address>
2020-01-03 10:11:07 +01:00
```
2017-08-07 12:13:18 -07:00
### Commit History
2023-05-10 17:24:02 -06:00
To prepare your branch to open a PR, the minimal number of logical commits is preferred to maintain
2017-05-08 14:54:06 -07:00
a clean commit history. Most commonly a PR will include a single commit where all changes are squashed, although
sometimes there will be multiple logical commits.
2017-08-07 12:13:18 -07:00
2019-10-25 09:25:07 +02:00
```console
2017-05-08 14:54:06 -07:00
# Inspect your commit history to determine if you need to squash commits
git log
2023-05-10 17:24:02 -06:00
```
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
To squash multiple commits or make other changes to the commit history, use `git rebase` :
```console
#
2017-05-08 14:54:06 -07:00
# In this example, the last 5 commits will be opened in the git rebase tool.
git rebase -i HEAD~5
```
2023-08-23 18:49:28 +05:30
Once your commit history is clean, ensure the branch is rebased on the [latest upstream ](#updating-your-fork ) before opening the PR.
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
## Submitting
2017-08-07 12:13:18 -07:00
2023-05-10 17:24:02 -06:00
Go to the [Rook github ](https://www.github.com/rook/rook ) to open the PR. If you have pushed recently to a branch, you will see an obvious link to open the PR. If you have not pushed recently, go to the Pull Request tab and select your fork and branch for the PR.
2017-05-08 14:54:06 -07:00
2023-05-10 17:24:02 -06:00
After the PR is open, make changes simply by pushing new commits. The PR will track the changes in your fork and rerun the CI automatically.
2017-12-15 10:13:01 -08:00
2023-05-10 17:24:02 -06:00
Always open a pull request against master. **Never** open a pull request against a released branch (e.g. release-1.2) unless working directly with a maintainer.
2020-01-03 10:11:07 +01:00
2023-05-10 17:24:02 -06:00
## Backporting to a Release Branch
2017-12-15 10:13:01 -08:00
2019-09-24 11:58:19 +02:00
The flow for getting a fix into a release branch is:
2019-07-11 16:42:08 +02:00
2023-05-10 17:24:02 -06:00
1. Open a PR to merge changes to master following the process outlined above
2. Add the backport label to that PR such as backport-release-1.11
3. After the PR is merged to master, the `mergify` bot will automatically open a PR with the commits backported to the release branch
4. After the CI is green and a maintainer has approved the PR, the bot will automatically merge the backport PR
2023-01-20 14:13:35 +01:00
2023-05-10 17:24:02 -06:00
## Debugging issues in Ceph manager modules
2023-01-20 14:13:35 +01:00
The Ceph manager modules are written in Python and can be individually and dynamically loaded from the manager. We can take advantage of this feature in order to test changes and to debug issues in the modules.
2023-05-10 17:24:02 -06:00
This is just a hack to debug any modification in the manager modules.
2023-01-20 14:13:35 +01:00
2023-05-10 17:24:02 -06:00
The `dashboard` and the `rook` orchestrator modules are the two modules most commonly have modifications that need to be tested.
2023-01-20 14:13:35 +01:00
2023-05-10 17:24:02 -06:00
Make modifications directly in the manager module and reload:
2023-01-20 14:13:35 +01:00
1. Update the cluster so only a single mgr pod is running. Set the `mgr.count: 1` in the CephCluster CR if it is not already.
2023-05-10 17:24:02 -06:00
2. Shell into the manager container:
2024-04-22 11:54:27 -06:00
```console
kubectl exec -n rook-ceph --stdin --tty $(kubectl get pod -n rook-ceph -l ceph_daemon_type=mgr,instance=a -o jsonpath='{.items[0].metadata.name}') -c mgr -- /bin/bash
` ``
2023-01-20 14:13:35 +01:00
2023-05-10 17:24:02 -06:00
3. Make the modifications needed in the required manager module. The manager module source code is found in ` /usr/share/ceph/mgr/`.
2023-01-20 14:13:35 +01:00
2024-04-22 11:54:27 -06:00
!!! Note
If the manager pod is restarted, all modifications made in the mgr container will be lost
2023-01-20 14:13:35 +01:00
2024-04-22 11:54:27 -06:00
4. Restart the modified manager module to test the modifications:
2023-01-20 14:13:35 +01:00
2024-04-22 11:54:27 -06:00
Example for restarting the rook manager module with the [kubectl plugin](https://github.com/rook/kubectl-rook-ceph):
2023-08-23 18:49:28 +05:30
2024-04-22 11:54:27 -06:00
` ``console
kubectl rook-ceph ceph mgr module disable rook
kubectl rook-ceph ceph mgr module enable rook
` ``
2023-01-20 14:13:35 +01:00
2024-04-22 11:54:27 -06:00
5. Once the module is restarted the modifications will be running in the active manager.
View the manager pod log or other changed behavior to validate the changes.