PageRenderTime 31ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/devel/development.md

https://gitlab.com/github-cloud-corporation/kubernetes
Markdown | 268 lines | 190 code | 78 blank | 0 comment | 0 complexity | e58c5e11e67b4b1ddf6d777fd1b9abd2 MD5 | raw file
  1. <!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
  2. <!-- BEGIN STRIP_FOR_RELEASE -->
  3. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  4. width="25" height="25">
  5. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  6. width="25" height="25">
  7. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  8. width="25" height="25">
  9. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  10. width="25" height="25">
  11. <img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
  12. width="25" height="25">
  13. <h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
  14. If you are using a released version of Kubernetes, you should
  15. refer to the docs that go with that version.
  16. <!-- TAG RELEASE_LINK, added by the munger automatically -->
  17. <strong>
  18. The latest release of this document can be found
  19. [here](http://releases.k8s.io/release-1.3/docs/devel/development.md).
  20. Documentation for other releases can be found at
  21. [releases.k8s.io](http://releases.k8s.io).
  22. </strong>
  23. --
  24. <!-- END STRIP_FOR_RELEASE -->
  25. <!-- END MUNGE: UNVERSIONED_WARNING -->
  26. # Development Guide
  27. This document is intended to be the canonical source of truth for things like
  28. supported toolchain versions for building Kubernetes. If you find a
  29. requirement that this doc does not capture, please
  30. [submit an issue](https://github.com/kubernetes/kubernetes/issues) on github. If
  31. you find other docs with references to requirements that are not simply links to
  32. this doc, please [submit an issue](https://github.com/kubernetes/kubernetes/issues).
  33. This document is intended to be relative to the branch in which it is found.
  34. It is guaranteed that requirements will change over time for the development
  35. branch, but release branches of Kubernetes should not change.
  36. ## Building Kubernetes with Docker
  37. Official releases are built using Docker containers. To build Kubernetes using
  38. Docker please follow [these instructions]
  39. (http://releases.k8s.io/HEAD/build/README.md).
  40. ## Building Kubernetes on a local OS/shell environment
  41. Many of the Kubernetes development helper scripts rely on a fairly up-to-date
  42. GNU tools environment, so most recent Linux distros should work just fine
  43. out-of-the-box. Note that Mac OS X ships with somewhat outdated BSD-based tools,
  44. some of which may be incompatible in subtle ways, so we recommend
  45. [replacing those with modern GNU tools]
  46. (https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/).
  47. ### Go development environment
  48. Kubernetes is written in the [Go](http://golang.org) programming language.
  49. To build Kubernetes without using Docker containers, you'll need a Go
  50. development environment. Builds for Kubernetes 1.0 - 1.2 require Go version
  51. 1.4.2. Builds for Kubernetes 1.3 and higher require Go version 1.6.0. If you
  52. haven't set up a Go development environment, please follow [these
  53. instructions](http://golang.org/doc/code.html) to install the go tools.
  54. Set up your GOPATH and add a path entry for go binaries to your PATH. Typically
  55. added to your ~/.profile:
  56. ```sh
  57. export GOPATH=$HOME/go
  58. export PATH=$PATH:$GOPATH/bin
  59. ```
  60. ### Godep dependency management
  61. Kubernetes build and test scripts use [godep](https://github.com/tools/godep) to
  62. manage dependencies.
  63. #### Install godep
  64. Ensure that [mercurial](http://mercurial.selenic.com/wiki/Download) is
  65. installed on your system. (some of godep's dependencies use the mercurial
  66. source control system). Use `apt-get install mercurial` or `yum install
  67. mercurial` on Linux, or [brew.sh](http://brew.sh) on OS X, or download directly
  68. from mercurial.
  69. Install godep (may require sudo):
  70. ```sh
  71. go get -u github.com/tools/godep
  72. ```
  73. Note:
  74. At this time, godep version >= v63 is known to work in the Kubernetes project.
  75. To check your version of godep:
  76. ```sh
  77. $ godep version
  78. godep v74 (linux/amd64/go1.6.2)
  79. ```
  80. Developers planning to managing dependencies in the `vendor/` tree may want to
  81. explore alternative environment setups. See
  82. [using godep to manage dependencies](godep.md).
  83. ### Local build using make
  84. To build Kubernetes using your local Go development environment (generate linux
  85. binaries):
  86. ```sh
  87. make
  88. ```
  89. You may pass build options and packages to the script as necessary. For example,
  90. to build with optimizations disabled for enabling use of source debug tools:
  91. ```sh
  92. make GOGCFLAGS="-N -l"
  93. ```
  94. To build binaries for all platforms:
  95. ```sh
  96. make cross
  97. ```
  98. ### How to update the Go version used to test & build k8s
  99. The kubernetes project tries to stay on the latest version of Go so it can
  100. benefit from the improvements to the language over time and can easily
  101. bump to a minor release version for security updates.
  102. Since kubernetes is mostly built and tested in containers, there are a few
  103. unique places you need to update the go version.
  104. - The image for cross compiling in [build/build-image/cross/](../../build/build-image/cross/). The `VERSION` file and `Dockerfile`.
  105. - Update [dockerized-e2e-runner.sh](https://github.com/kubernetes/test-infra/blob/master/jenkins/dockerized-e2e-runner.sh) to run a kubekins-e2e with the desired go version, which requires pushing [e2e-image](../../hack/jenkins/e2e-image/) and [test-image](../../hack/jenkins/test-image/) images that are `FROM` the desired go version.
  106. - The docker image being run in [hack/jenkins/gotest-dockerized.sh](../../hack/jenkins/gotest-dockerized.sh).
  107. - The cross tag `KUBE_BUILD_IMAGE_CROSS_TAG` in [build/common.sh](../../build/common.sh)
  108. ## Workflow
  109. Below, we outline one of the more common git workflows that core developers use.
  110. Other git workflows are also valid.
  111. ### Visual overview
  112. ![Git workflow](git_workflow.png)
  113. ### Fork the main repository
  114. 1. Go to https://github.com/kubernetes/kubernetes
  115. 2. Click the "Fork" button (at the top right)
  116. ### Clone your fork
  117. The commands below require that you have $GOPATH set ([$GOPATH
  118. docs](https://golang.org/doc/code.html#GOPATH)). We highly recommend you put
  119. Kubernetes' code into your GOPATH. Note: the commands below will not work if
  120. there is more than one directory in your `$GOPATH`.
  121. ```sh
  122. mkdir -p $GOPATH/src/k8s.io
  123. cd $GOPATH/src/k8s.io
  124. # Replace "$YOUR_GITHUB_USERNAME" below with your github username
  125. git clone https://github.com/$YOUR_GITHUB_USERNAME/kubernetes.git
  126. cd kubernetes
  127. git remote add upstream 'https://github.com/kubernetes/kubernetes.git'
  128. ```
  129. ### Create a branch and make changes
  130. ```sh
  131. git checkout -b my-feature
  132. # Make your code changes
  133. ```
  134. ### Keeping your development fork in sync
  135. ```sh
  136. git fetch upstream
  137. git rebase upstream/master
  138. ```
  139. Note: If you have write access to the main repository at
  140. github.com/kubernetes/kubernetes, you should modify your git configuration so
  141. that you can't accidentally push to upstream:
  142. ```sh
  143. git remote set-url --push upstream no_push
  144. ```
  145. ### Committing changes to your fork
  146. Before committing any changes, please link/copy the pre-commit hook into your
  147. .git directory. This will keep you from accidentally committing non-gofmt'd Go
  148. code. This hook will also do a build and test whether documentation generation
  149. scripts need to be executed.
  150. The hook requires both Godep and etcd on your `PATH`.
  151. ```sh
  152. cd kubernetes/.git/hooks/
  153. ln -s ../../hooks/pre-commit .
  154. ```
  155. Then you can commit your changes and push them to your fork:
  156. ```sh
  157. git commit
  158. git push -f origin my-feature
  159. ```
  160. ### Creating a pull request
  161. 1. Visit https://github.com/$YOUR_GITHUB_USERNAME/kubernetes
  162. 2. Click the "Compare & pull request" button next to your "my-feature" branch.
  163. 3. Check out the pull request [process](pull-requests.md) for more details
  164. ### When to retain commits and when to squash
  165. Upon merge, all git commits should represent meaningful milestones or units of
  166. work. Use commits to add clarity to the development and review process.
  167. Before merging a PR, squash any "fix review feedback", "typo", and "rebased"
  168. sorts of commits. It is not imperative that every commit in a PR compile and
  169. pass tests independently, but it is worth striving for. For mass automated
  170. fixups (e.g. automated doc formatting), use one or more commits for the
  171. changes to tooling and a final commit to apply the fixup en masse. This makes
  172. reviews much easier.
  173. See [Faster Reviews](faster_reviews.md) for more details.
  174. ## Testing
  175. Three basic commands let you run unit, integration and/or e2e tests:
  176. ```sh
  177. cd kubernetes
  178. make test # Run every unit test
  179. make test WHAT=pkg/util/cache GOFLAGS=-v # Run tests of a package verbosely
  180. make test-integration # Run integration tests, requires etcd
  181. make test-e2e # Run e2e tests
  182. ```
  183. See the [testing guide](testing.md) and [end-to-end tests](e2e-tests.md) for additional information and scenarios.
  184. ## Regenerating the CLI documentation
  185. ```sh
  186. hack/update-generated-docs.sh
  187. ```
  188. <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
  189. [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/development.md?pixel)]()
  190. <!-- END MUNGE: GENERATED_ANALYTICS -->