# Development Guide ## New to Go Ceph-csi is written in Go and if you are new to the language, it is **highly** encouraged to: * Take the [A Tour of Go](http://tour.golang.org/welcome/1) course. * [Set up](https://golang.org/doc/code.html) Go development environment on your machine. * Read [Effective Go](https://golang.org/doc/effective_go.html) for best practices. ## Development Workflow ### Workspace and repository setup * [Download](https://golang.org/dl/) Go (>=1.13.x) and [install](https://golang.org/doc/install) it on your system. * Setup the [GOPATH](http://www.g33knotes.org/2014/07/60-second-count-down-to-go.html) environment. * `CGO_ENABLED` is enabled by default, if `CGO_ENABLED` is set to `0` we need to set it to `1` as we need to build with go-ceph bindings. * `GO111MODULE` is enabled by default, if `GO111MODULE` is set to `off` we need to set it to `on` as cephcsi uses go modules for dependency. * Ceph-CSI uses the native Ceph libaries through the [go-ceph package](https://github.com/ceph/go-ceph). It is required to install the Ceph C headers in order to compile Ceph-CSI. The packages are called `libcephfs-devel`, `librados-devel` and `librbd-devel` on many Linux distributions. See the [go-ceph installaton instructions](https://github.com/ceph/go-ceph#installation) for more details. * Run `$ go get -d github.com/ceph/ceph-csi` This will just download the source and not build it. The downloaded source will be at `$GOPATH/src/github.com/ceph/ceph-csi` * Fork the [ceph-csi repo](https://github.com/ceph/ceph-csi) on Github. * Add your fork as a git remote: `$ git remote add fork https://github.com//ceph-csi` > Editors: Our favorite editor is vim with the [vim-go](https://github.com/fatih/vim-go) > plugin, but there are many others like [vscode](https://github.com/Microsoft/vscode-go) ### Building Ceph-CSI To build ceph-csi locally run: `$ make` To build ceph-csi in a container: `$ make containerized-build` The built binary will be present under `_output/` directory. ### Running Ceph-CSI tests in a container Once the changes to the sources compile, it is good practise to run the tests that validate the style and other basics of the source code. Execute the unit tests (in the `*_test.go` files) and check the formatting of YAML files, MarkDown documents and shell scripts: `$ make containerized-test` It is also possible to run only selected tests, these are the targets in the `Makefile` in the root of the project. For example, run the different static checks with: `$ make containerized-test TARGET=static-check` In addition to running tests locally, each Pull Request that is created will trigger Continous Integration tests that include the `containerized-test`, but also additional functionality tests that are defined under the `e2e/` directory. ### Code contribution workflow ceph-csi repository currently follows GitHub's [Fork & Pull] () workflow for code contributions. Please read the [coding guidelines](coding.md) document before submitting a PR. #### Certificate of Origin By contributing to this project you agree to the Developer Certificate of Origin (DCO). This document was created by the Linux Kernel community and is a simple statement that you, as a contributor, have the legal right to make the contribution. See the [DCO](DCO) file for details. Contributors sign-off that they adhere to these requirements by adding a Signed-off-by line to commit messages. For example: ```text subsystem: This is my commit message More details on what this commit does Signed-off-by: Random J Developer ``` If you have already made a commit and forgot to include the sign-off, you can amend your last commit to add the sign-off with the following command, which can then be force pushed. ```console git commit --amend -s ``` We use a [DCO bot](https://github.com/apps/dco) to enforce the DCO on each pull request and branch commits. #### Commit Messages We follow a rough convention for commit messages that is designed to answer two questions: what changed and why? The subject line should feature the what and the body of the commit should describe the why. ```text cephfs: update cephfs resize use cephfs resize to resize subvolume Signed-off-by: Random J Developer ``` The format can be described more formally as follows: ```text :