| 1 | # How to Contribute |
| 2 | |
| 3 | CNI is [Apache 2.0 licensed](LICENSE) and accepts contributions via GitHub |
| 4 | pull requests. This document outlines some of the conventions on development |
| 5 | workflow, commit message formatting, contact points and other resources to make |
| 6 | it easier to get your contribution accepted. |
| 7 | |
| 8 | We gratefully welcome improvements to documentation as well as to code. |
| 9 | |
| 10 | # Certificate of Origin |
| 11 | |
| 12 | By contributing to this project you agree to the Developer Certificate of |
| 13 | Origin (DCO). This document was created by the Linux Kernel community and is a |
| 14 | simple statement that you, as a contributor, have the legal right to make the |
| 15 | contribution. See the [DCO](DCO) file for details. |
| 16 | |
| 17 | # Email and Chat |
| 18 | |
| 19 | The project uses the the cni-dev email list and IRC chat: |
| 20 | - Email: [cni-dev](https://groups.google.com/forum/#!forum/cni-dev) |
| 21 | - IRC: #[containernetworking](irc://irc.freenode.org:6667/#containernetworking) channel on freenode.org |
| 22 | |
| 23 | Please avoid emailing maintainers found in the MAINTAINERS file directly. They |
| 24 | are very busy and read the mailing lists. |
| 25 | |
| 26 | ## Getting Started |
| 27 | |
| 28 | - Fork the repository on GitHub |
| 29 | - Play with the project, submit bugs, submit pull requests! |
| 30 | |
| 31 | |
| 32 | ## Building |
| 33 | |
| 34 | Each plugin is compiled simply with `go build`. Two scripts, `build_linux.sh` and `build_windows.sh`, |
| 35 | are supplied which will build all the plugins for their respective OS. |
| 36 | |
| 37 | ## Contribution workflow |
| 38 | |
| 39 | This is a rough outline of how to prepare a contribution: |
| 40 | |
| 41 | - Create a topic branch from where you want to base your work (usually branched from master). |
| 42 | - Make commits of logical units. |
| 43 | - Make sure your commit messages are in the proper format (see below). |
| 44 | - Push your changes to a topic branch in your fork of the repository. |
| 45 | - If you changed code: |
| 46 | - add automated tests to cover your changes, using the [Ginkgo](http://onsi.github.io/ginkgo/) & [Gomega](http://onsi.github.io/gomega/) style |
| 47 | - if the package did not previously have any test coverage, add it to the list |
| 48 | of `TESTABLE` packages in the `test.sh` script. |
| 49 | - run the full test script and ensure it passes |
| 50 | - Make sure any new code files have a license header (this is now enforced by automated tests) |
| 51 | - Submit a pull request to the original repository. |
| 52 | |
| 53 | ## How to run the test suite |
| 54 | We generally require test coverage of any new features or bug fixes. |
| 55 | |
| 56 | Here's how you can run the test suite on any system (even Mac or Windows) using |
| 57 | [Vagrant](https://www.vagrantup.com/) and a hypervisor of your choice: |
| 58 | |
| 59 | First, ensure that you have the [CNI repo](https://github.com/containernetworking/cni) and this repo (plugins) cloned side-by-side: |
| 60 | ```bash |
| 61 | cd ~/workspace |
| 62 | git clone https://github.com/containernetworking/cni |
| 63 | git clone https://github.com/containernetworking/plugins |
| 64 | ``` |
| 65 | |
| 66 | Next, boot the virtual machine and SSH in to run the tests: |
| 67 | |
| 68 | ```bash |
| 69 | cd ~/workspace/plugins |
| 70 | vagrant up |
| 71 | vagrant ssh |
| 72 | # you're now in a shell in a virtual machine |
| 73 | sudo su |
| 74 | go get github.com/onsi/ginkgo/ginkgo |
| 75 | go install github.com/containernetworking/cni/cnitool |
| 76 | cd /go/src/github.com/containernetworking/plugins |
| 77 | |
| 78 | # to run the full test suite |
| 79 | ./test_linux.sh |
| 80 | |
| 81 | # to focus on a particular test suite |
| 82 | cd plugins/main/loopback |
| 83 | go test |
| 84 | ``` |
| 85 | |
| 86 | # Acceptance policy |
| 87 | |
| 88 | These things will make a PR more likely to be accepted: |
| 89 | |
| 90 | * a well-described requirement |
| 91 | * tests for new code |
| 92 | * tests for old code! |
| 93 | * new code and tests follow the conventions in old code and tests |
| 94 | * a good commit message (see below) |
| 95 | |
| 96 | In general, we will merge a PR once two maintainers have endorsed it. |
| 97 | Trivial changes (e.g., corrections to spelling) may get waved through. |
| 98 | For substantial changes, more people may become involved, and you might get asked to resubmit the PR or divide the changes into more than one PR. |
| 99 | |
| 100 | ### Format of the Commit Message |
| 101 | |
| 102 | We follow a rough convention for commit messages that is designed to answer two |
| 103 | questions: what changed and why. The subject line should feature the what and |
| 104 | the body of the commit should describe the why. |
| 105 | |
| 106 | ``` |
| 107 | scripts: add the test-cluster command |
| 108 | |
| 109 | this uses tmux to setup a test cluster that you can easily kill and |
| 110 | start for debugging. |
| 111 | |
| 112 | Fixes #38 |
| 113 | ``` |
| 114 | |
| 115 | The format can be described more formally as follows: |
| 116 | |
| 117 | ``` |
| 118 | <subsystem>: <what changed> |
| 119 | <BLANK LINE> |
| 120 | <why this change was made> |
| 121 | <BLANK LINE> |
| 122 | <footer> |
| 123 | ``` |
| 124 | |
| 125 | The first line is the subject and should be no longer than 70 characters, the |
| 126 | second line is always blank, and other lines should be wrapped at 80 characters. |
| 127 | This allows the message to be easier to read on GitHub as well as in various |
| 128 | git tools. |
| 129 | |
| 130 | ## 3rd party plugins |
| 131 | So you've built a CNI plugin. Where should it live? |
| 132 | |
| 133 | Short answer: We'd be happy to link to it from our [list of 3rd party plugins](README.md#3rd-party-plugins). |
| 134 | But we'd rather you kept the code in your own repo. |
| 135 | |
| 136 | Long answer: An advantage of the CNI model is that independent plugins can be |
| 137 | built, distributed and used without any code changes to this repository. While |
| 138 | some widely used plugins (and a few less-popular legacy ones) live in this repo, |
| 139 | we're reluctant to add more. |
| 140 | |
| 141 | If you have a good reason why the CNI maintainers should take custody of your |
| 142 | plugin, please open an issue or PR. |