|
| 1 | +# Contributing to the cinder operator |
| 2 | + |
| 3 | +Thank you for taking the time to contribute! |
| 4 | + |
| 5 | +The following is a set of guidelines for contributing to the [cinder-operator |
| 6 | +hosted in GitHub](https://github.com/openstack-k8s-operators/cinder-operator). |
| 7 | +Feel free to propose changes to this document or any other in a pull request. |
| 8 | + |
| 9 | +## What should I know before I get started? |
| 10 | + |
| 11 | +The cinder-operator is not a large open source project, but it's part of the |
| 12 | +[OpenStack podification effort](https://github.com/openstack-k8s-operators) |
| 13 | +which is of some size. |
| 14 | + |
| 15 | +There are some requirements to deploy a working Cinder control plane within |
| 16 | +OpenShift using the cinder-operator. For simplicity's sake all the |
| 17 | +documentation will assume that the |
| 18 | +[openstack-operator](https://github.com/openstack-k8s-operators/openstack-operator) |
| 19 | +will be used to deploy necessary services, though this doesn't mean that there |
| 20 | +are no other ways to do it. |
| 21 | + |
| 22 | +Before working on your first code contribution it would be a good idea to |
| 23 | +complete the [getting started](README.md#getting-started) section first to get |
| 24 | +familiar with the deploying of the services and to get a feeling of the |
| 25 | +behavior of a working OpenStack deployment. |
| 26 | + |
| 27 | +Please refer to the [OpenStack documentation](https://docs.openstack.org) to |
| 28 | +learn about OpenStack itself. |
| 29 | + |
| 30 | +### Design decisions |
| 31 | + |
| 32 | +There is some [global podification |
| 33 | +documentation](https://github.com/openstack-k8s-operators/docs) relevant for |
| 34 | +all the operators, but there are also some global design decisions that have |
| 35 | +not been spelled out yet anywhere else, so they are included in the |
| 36 | +[cinder-operator design decisions document](docs/dev/design-decisions.md). |
| 37 | + |
| 38 | +## How to contribute? |
| 39 | + |
| 40 | +This project is [using pull |
| 41 | +request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) |
| 42 | +to submit changes, but it is not currently using the [issues |
| 43 | +section](https://github.com/openstack-k8s-operators/cinder-operator/issues) or |
| 44 | +any other GitHub feature to track the project's bugs or features and instead it |
| 45 | +is expected that whoever finds an issue will fix it or will find someone else |
| 46 | +to work on it. |
| 47 | + |
| 48 | +### Testing changes |
| 49 | + |
| 50 | +Developers submitting PRs are expected to have run the code and manually |
| 51 | +verified the functionality before submitting the PR, with the exception |
| 52 | +of documentation only and CI only PRs. |
| 53 | + |
| 54 | +There are multiple ways to test code changes, but in general terms they can be |
| 55 | +split into 2 categories: running things locally or in a container in the |
| 56 | +OpenShift cluster. |
| 57 | + |
| 58 | +Running things locally is considerably faster but it doesn't use the real ACLs |
| 59 | +(RBACs) the cinder-operator would use on a normal deployment. On the other hand |
| 60 | +running things in OpenShift is slower (because we have to build a new |
| 61 | +container) but runs as close as a real deployment as we can. |
| 62 | + |
| 63 | +Each of the approaches has its own advantages and disadvantages, so different |
| 64 | +variants of both approaches will be covered for readers to choose the one they |
| 65 | +prefer. |
| 66 | + |
| 67 | +The following list of articles assumes that podified OpenStack has been |
| 68 | +deployed using the openstack-operator as described in the [Getting started |
| 69 | +section](README.md#getting-started): |
| 70 | + |
| 71 | +- [Run operator locally](docs/dev/local.md) |
| 72 | +- [Run operator in OpenShift using a custom image](docs/dev/custom-image.md) |
| 73 | + |
| 74 | +### Pull Requests |
| 75 | + |
| 76 | +While the pull request flow is used for submitting new issues and for |
| 77 | +reviewing, the git repository should **always** be the source of truth, so all |
| 78 | +decisions made through the reviewing and design phases should be properly |
| 79 | +reflected in the final code, code comments, documentation, and git commit |
| 80 | +message that is merged. It should not be necessary to go to a PR in GitHub and |
| 81 | +go through the comments to know what a commit is meant to do or why it is doing |
| 82 | +it. |
| 83 | + |
| 84 | +*One-liner* commit messages should be avoided like the plague. Please refer to |
| 85 | +the [commit messages guide line](#commit-messages) for good practices on commit |
| 86 | +messages. |
| 87 | + |
| 88 | +The cinder-operator project will not squash all pull request commits into a |
| 89 | +single commit but will look to preserve all submitted individual commits |
| 90 | +instead using a merge strategy instead. This means that we can have both |
| 91 | +single commit and as multi-commit PRs, and both have their places. It's all |
| 92 | +about how and when to split changes. |
| 93 | + |
| 94 | +#### Structural split of changes |
| 95 | + |
| 96 | +The general rule for how to split code changes into commits is that we should |
| 97 | +aim to have a single "logical change" per commit. |
| 98 | + |
| 99 | +As the [OpenStack Git Commit Good |
| 100 | +Practice](https://wiki.openstack.org/wiki/GitCommitMessages) explains, there |
| 101 | +are multiple reasons why this rule is important: |
| 102 | + |
| 103 | +- The smaller the amount of code being changed in a commit, the quicker & |
| 104 | + easier it is to review & identify potential flaws in that specific code |
| 105 | + change. |
| 106 | +- If a change is found to be flawed later, it may be necessary to revert the |
| 107 | + broken commit. This is much easier to do if there are not other unrelated |
| 108 | + code changes entangled with the original commit. |
| 109 | +- When troubleshooting problems using Git's bisect capability, small well |
| 110 | + defined changes will aid in isolating exactly where the code problem was |
| 111 | + introduced. |
| 112 | +- When browsing history using Git annotate/blame, small well defined changes |
| 113 | + also aid in isolating exactly where & why a piece of code came from. |
| 114 | + |
| 115 | +In the [OpenStack Git Commit Good Practice |
| 116 | +page](https://wiki.openstack.org/wiki/GitCommitMessages) we can also find two |
| 117 | +great sections explaining [things to avoid when creating |
| 118 | +commits](https://wiki.openstack.org/wiki/GitCommitMessages#Things_to_avoid_when_creating_commits) |
| 119 | +and [examples of bad |
| 120 | +practice](https://wiki.openstack.org/wiki/GitCommitMessages#Examples_of_bad_practice) |
| 121 | +that contributors to this repository should take into consideration. |
| 122 | + |
| 123 | +#### PR Images |
| 124 | + |
| 125 | +Once a PR merges it will trigger an image rebuild and publish, so how can we |
| 126 | +tell when the new image is ready? |
| 127 | + |
| 128 | +For that we'll go to the [project's |
| 129 | +actions](https://github.com/openstack-k8s-operators/cinder-operator/actions) |
| 130 | +and in there [we select the `Cinder Operator image builder` |
| 131 | +job](https://github.com/openstack-k8s-operators/cinder-operator/actions/workflows/build-cinder-operator.yaml) |
| 132 | +where we'll see the job that is building the new operator container image. |
| 133 | + |
| 134 | +In there how the job is building 3 images: Operator, Bundle, and Index, and if |
| 135 | +you go into each one of them and expand the `Push **** To quay.io` step you can |
| 136 | +find the actual image location. |
| 137 | + |
| 138 | +For example: |
| 139 | + |
| 140 | +``` |
| 141 | +Successfully pushed "cinder-operator-index:9f3d1ec26ba8939710f146f3e6a1d81f5077be8a" to "quay.io/***/cinder-operator-index:9f3d1ec26ba8939710f146f3e6a1d81f5077be8a" |
| 142 | +``` |
| 143 | + |
| 144 | +## Style Guides |
| 145 | + |
| 146 | +### Go Style Guide |
| 147 | + |
| 148 | +While the project has not formally defined a Go Style Guide for the project it |
| 149 | +uses [Gofmt](https://pkg.go.dev/cmd/gofmt) for automated code formatting. |
| 150 | + |
| 151 | +This tool is automatically called when building the cinder-operator binary |
| 152 | +using the `Makefile` or when it is manually invoked with: |
| 153 | + |
| 154 | +```sh |
| 155 | +make fmt |
| 156 | +``` |
| 157 | + |
| 158 | +Pull Requests are expected to have passed the formatting tool before committing |
| 159 | +the code and submitting the PR. |
| 160 | + |
| 161 | +### Commit Messages |
| 162 | + |
| 163 | +As mentioned before, commit messages are a very important part of a pull |
| 164 | +request, and their contents must be carefully crafted. |
| 165 | + |
| 166 | +Commit messages should: |
| 167 | + |
| 168 | +- Provide a brief description of the change in the first line. |
| 169 | +- Insert a single blank line after the first line. |
| 170 | +- Provide a detailed description of the change in the following lines, breaking |
| 171 | + paragraphs where needed. |
| 172 | +- Lines should be wrapped at 72 characters. |
| 173 | + |
| 174 | +Once again the OpenStack documentation goes over the [important things to |
| 175 | +consider when writing the commit |
| 176 | +message](https://wiki.openstack.org/wiki/GitCommitMessages#Information_in_commit_messages), |
| 177 | +so please take a good look. The short version is: |
| 178 | + |
| 179 | +- Do not assume the reviewer understands what the original problem was. |
| 180 | +- Do not assume the reviewer has access to external web services/site. |
| 181 | +- Do not assume the code is self-evident/self-documenting. |
| 182 | +- Describe why a change is being made. |
| 183 | +- Read the commit message to see if it hints at improved code structure. |
| 184 | +- The first commit line is the most important. |
| 185 | +- Describe any limitations of the current code. |
| 186 | +- Do not assume the reviewer has knowledge of the tests executed on the change |
| 187 | +- Do not include patch set-specific comments. |
| 188 | + |
| 189 | +## Helpful scripts |
| 190 | + |
| 191 | +Under the `hack` directory we'll find scripts that can help us in the |
| 192 | +development of the cinder-operator as well as some tips and tricks. |
| 193 | + |
| 194 | +Refer to its `README.md` file for additional information. |
0 commit comments