2015-07-12 04:04:52 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 17:02:26 +00:00
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 >
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
2015-12-14 18:37:38 +00:00
<!-- TAG RELEASE_LINK, added by the munger automatically -->
2015-07-16 17:02:26 +00:00
< strong >
2015-11-03 18:17:57 +00:00
The latest release of this document can be found
2016-03-09 02:06:40 +00:00
[here ](http://releases.k8s.io/release-1.2/docs/devel/development.md ).
2015-07-16 17:02:26 +00:00
Documentation for other releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).
< / strong >
--
2015-07-13 22:15:35 +00:00
2015-07-12 04:04:52 +00:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-17 22:35:41 +00:00
2014-10-15 15:30:02 +00:00
# Development Guide
2015-12-02 17:54:21 +00:00
This document is intended to be the canonical source of truth for things like
2016-04-06 22:03:11 +00:00
supported toolchain versions for building Kubernetes. If you find a
requirement that this doc does not capture, please file a bug. If you find
2015-12-02 17:54:21 +00:00
other docs with references to requirements that are not simply links to this
doc, please file a bug.
This document is intended to be relative to the branch in which it is found.
It is guaranteed that requirements will change over time for the development
branch, but release branches of Kubernetes should not change.
2016-04-06 22:03:11 +00:00
## Building Kubernetes
2014-10-15 15:30:02 +00:00
2016-04-06 22:03:11 +00:00
Official releases are built using Docker containers. To build Kubernetes using
Docker please follow [these instructions ](http://releases.k8s.io/HEAD/build/README.md ).
2014-10-15 15:30:02 +00:00
2016-04-06 22:03:11 +00:00
### Go development environment
2014-10-15 15:30:02 +00:00
2016-04-06 22:03:11 +00:00
Kubernetes is written in the [Go ](http://golang.org ) programming language.
To build Kubernetes without using Docker containers, you'll need a Go
development environment. Builds for Kubernetes 1.0 - 1.2 require Go version
1.4.2. Builds for Kubernetes 1.3 and higher require Go version 1.6.0. If you
haven't set up a Go development environment, please follow [these instructions ](http://golang.org/doc/code.html )
to install the go tools and set up a GOPATH.
2015-12-02 17:54:21 +00:00
2016-04-06 22:03:11 +00:00
To build Kubernetes using your local Go development environment (generate linux
binaries):
2015-12-02 17:54:21 +00:00
2016-04-06 22:03:11 +00:00
hack/build-go.sh
You may pass build options and packages to the script as necessary. To build binaries for all platforms:
2016-04-06 17:08:45 +00:00
2016-04-06 22:03:11 +00:00
hack/build-cross.sh
2014-10-15 15:30:02 +00:00
2016-04-06 22:03:11 +00:00
## Workflow
2014-10-15 15:30:02 +00:00
2016-04-06 22:03:11 +00:00
Below, we outline one of the more common git workflows that core developers use.
Other git workflows are also valid.
2015-06-08 20:32:28 +00:00
### Visual overview
2015-07-17 22:35:41 +00:00
2015-06-08 20:32:28 +00:00
![Git workflow ](git_workflow.png )
### Fork the main repository
2015-08-12 20:12:32 +00:00
1. Go to https://github.com/kubernetes/kubernetes
2015-06-08 20:32:28 +00:00
2. Click the "Fork" button (at the top right)
### Clone your fork
2016-04-06 22:03:11 +00:00
The commands below require that you have $GOPATH set ([$GOPATH docs](https://golang.org/doc/code.html#GOPATH)). We highly recommend you put Kubernetes' code into your GOPATH. Note: the commands below will not work if
there is more than one directory in your `$GOPATH` .
2014-10-15 15:30:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2015-08-05 22:16:36 +00:00
mkdir -p $GOPATH/src/k8s.io
cd $GOPATH/src/k8s.io
2015-06-08 20:32:28 +00:00
# Replace "$YOUR_GITHUB_USERNAME" below with your github username
2015-07-19 08:54:49 +00:00
git clone https://github.com/$YOUR_GITHUB_USERNAME/kubernetes.git
cd kubernetes
2015-08-12 20:12:32 +00:00
git remote add upstream 'https://github.com/kubernetes/kubernetes.git'
2015-06-08 20:32:28 +00:00
```
### Create a branch and make changes
2015-07-19 08:54:49 +00:00
```sh
git checkout -b myfeature
2015-06-08 20:32:28 +00:00
# Make your code changes
```
### Keeping your development fork in sync
2015-07-19 08:54:49 +00:00
```sh
git fetch upstream
git rebase upstream/master
2015-06-08 20:32:28 +00:00
```
2015-08-12 20:12:32 +00:00
Note: If you have write access to the main repository at github.com/kubernetes/kubernetes, you should modify your git configuration so that you can't accidentally push to upstream:
2015-06-08 20:32:28 +00:00
2015-07-19 08:54:49 +00:00
```sh
2015-06-08 20:32:28 +00:00
git remote set-url --push upstream no_push
2014-10-15 15:30:02 +00:00
```
2015-08-09 18:18:06 +00:00
### Committing changes to your fork
2015-06-08 20:32:28 +00:00
2016-04-29 01:41:45 +00:00
Before committing any changes, please link/copy the pre-commit hook
into your .git directory. This will keep you from accidentally
committing non-gofmt'd Go code. In addition this hook will do a build.
The hook requires both Godep and etcd on your `PATH` .
2015-10-02 19:26:59 +00:00
```sh
cd kubernetes/.git/hooks/
ln -s ../../hooks/pre-commit .
```
Then you can commit your changes and push them to your fork:
2015-07-19 08:54:49 +00:00
```sh
git commit
git push -f origin myfeature
2015-06-08 20:32:28 +00:00
```
### Creating a pull request
2015-07-17 22:35:41 +00:00
2015-09-09 16:22:43 +00:00
1. Visit https://github.com/$YOUR_GITHUB_USERNAME/kubernetes
2015-06-08 20:32:28 +00:00
2. Click the "Compare and pull request" button next to your "myfeature" branch.
2015-08-05 21:34:52 +00:00
3. Check out the pull request [process ](pull-requests.md ) for more details
2014-10-15 15:30:02 +00:00
2015-07-30 22:11:38 +00:00
### When to retain commits and when to squash
Upon merge, all git commits should represent meaningful milestones or units of
work. Use commits to add clarity to the development and review process.
Before merging a PR, squash any "fix review feedback", "typo", and "rebased"
2016-04-06 22:03:11 +00:00
sorts of commits. It is not imperative that every commit in a PR compile and
pass tests independently, but it is worth striving for. For mass automated
2015-07-30 22:11:38 +00:00
fixups (e.g. automated doc formatting), use one or more commits for the
2016-04-06 22:03:11 +00:00
changes to tooling and a final commit to apply the fixup en masse. This makes
2015-07-30 22:11:38 +00:00
reviews much easier.
2014-10-15 15:30:02 +00:00
2015-08-27 21:12:06 +00:00
See [Faster Reviews ](faster_reviews.md ) for more details.
2014-10-15 15:30:02 +00:00
## godep and dependency management
Kubernetes uses [godep ](https://github.com/tools/godep ) to manage dependencies. It is not strictly required for building Kubernetes but it is required when managing dependencies under the Godeps/ tree, and is required by a number of the build and test scripts. Please make sure that ``godep`` is installed and in your ``$PATH``.
### Installing godep
2015-07-17 22:35:41 +00:00
2016-04-06 22:03:11 +00:00
There are many ways to build and host Go binaries. Here is an easy way to get utilities like `godep` installed:
2014-10-15 15:30:02 +00:00
2015-02-10 09:35:11 +00:00
1) Ensure that [mercurial ](http://mercurial.selenic.com/wiki/Download ) is installed on your system. (some of godep's dependencies use the mercurial
2016-04-06 22:03:11 +00:00
source control system). Use `apt-get install mercurial` or `yum install mercurial` on Linux, or [brew.sh ](http://brew.sh ) on OS X, or download
2014-10-15 15:30:02 +00:00
directly from mercurial.
2015-02-10 09:35:11 +00:00
2) Create a new GOPATH for your tools and install godep:
2015-07-17 02:01:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2014-10-15 15:30:02 +00:00
export GOPATH=$HOME/go-tools
mkdir -p $GOPATH
go get github.com/tools/godep
```
2015-02-10 09:35:11 +00:00
3) Add $GOPATH/bin to your path. Typically you'd add this to your ~/.profile:
2015-07-17 02:01:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2014-10-15 15:30:02 +00:00
export GOPATH=$HOME/go-tools
export PATH=$PATH:$GOPATH/bin
```
2016-03-10 18:12:53 +00:00
Note:
At this time, godep update in the Kubernetes project only works properly if your version of godep is < 54.
To check your version of godep:
```sh
$ godep version
godep v53 (linux/amd64/go1.5.3)
```
2014-10-15 15:30:02 +00:00
### Using godep
2015-07-17 22:35:41 +00:00
2016-04-14 06:30:15 +00:00
Here's a quick walkthrough of one way to use godeps to add or update a Kubernetes dependency into `vendor/` . For more details, please see the instructions in [godep's documentation ](https://github.com/tools/godep ).
2014-10-15 15:30:02 +00:00
2015-02-10 09:35:11 +00:00
1) Devote a directory to this endeavor:
2015-07-17 02:01:02 +00:00
2015-08-27 00:22:27 +00:00
_Devoting a separate directory is not required, but it is helpful to separate dependency updates from other changes._
2015-07-19 08:54:49 +00:00
```sh
2014-12-16 22:36:39 +00:00
export KPATH=$HOME/code/kubernetes
2015-08-05 22:16:36 +00:00
mkdir -p $KPATH/src/k8s.io/kubernetes
cd $KPATH/src/k8s.io/kubernetes
2014-12-16 22:36:39 +00:00
git clone https://path/to/your/fork .
# Or copy your existing local repo here. IMPORTANT: making a symlink doesn't work.
```
2015-02-10 09:35:11 +00:00
2) Set up your GOPATH.
2015-07-17 02:01:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2014-12-16 22:36:39 +00:00
# Option A: this will let your builds see packages that exist elsewhere on your system.
export GOPATH=$KPATH:$GOPATH
# Option B: This will *not* let your local builds see packages that exist elsewhere on your system.
export GOPATH=$KPATH
# Option B is recommended if you're going to mess with the dependencies.
```
2015-02-18 22:04:56 +00:00
3) Populate your new GOPATH.
2015-07-17 02:01:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2015-08-31 04:15:05 +00:00
cd $KPATH/src/k8s.io/kubernetes
2014-12-16 22:36:39 +00:00
godep restore
```
2015-02-10 09:35:11 +00:00
4) Next, you can either add a new dependency or update an existing one.
2015-07-17 02:01:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2015-02-18 22:04:56 +00:00
# To add a new dependency, do:
2015-08-05 22:16:36 +00:00
cd $KPATH/src/k8s.io/kubernetes
2015-02-10 09:35:11 +00:00
go get path/to/dependency
2015-02-18 22:04:56 +00:00
# Change code in Kubernetes to use the dependency.
2014-12-16 22:36:39 +00:00
godep save ./...
2015-02-10 09:35:11 +00:00
2015-02-18 22:04:56 +00:00
# To update an existing dependency, do:
2015-08-05 22:16:36 +00:00
cd $KPATH/src/k8s.io/kubernetes
2015-02-10 09:35:11 +00:00
go get -u path/to/dependency
2015-02-18 22:04:56 +00:00
# Change code in Kubernetes accordingly if necessary.
2015-08-27 00:22:27 +00:00
godep update path/to/dependency/...
2014-12-16 22:36:39 +00:00
```
2015-08-27 00:22:27 +00:00
_If `go get -u path/to/dependency` fails with compilation errors, instead try `go get -d -u path/to/dependency`
2016-04-06 22:03:11 +00:00
to fetch the dependencies without compiling them. This can happen when updating the cadvisor dependency._
2015-08-27 00:22:27 +00:00
2015-12-08 21:23:59 +00:00
5) Before sending your PR, it's a good idea to sanity check that your Godeps.json file is ok by running `hack/verify-godeps.sh`
2015-08-27 00:22:27 +00:00
_If hack/verify-godeps.sh fails after a `godep update` , it is possible that a transitive dependency was added or removed but not
2016-04-06 22:03:11 +00:00
updated by godeps. It then may be necessary to perform a `godep save ./...` to pick up the transitive dependency changes._
2015-02-10 09:35:11 +00:00
2015-02-18 22:04:56 +00:00
It is sometimes expedient to manually fix the /Godeps/godeps.json file to minimize the changes.
2014-12-16 22:36:39 +00:00
Please send dependency updates in separate commits within your PR, for easier reviewing.
2014-10-15 15:30:02 +00:00
2016-02-27 02:33:24 +00:00
6) If you updated the Godeps, please also update `Godeps/LICENSES` by running `hack/update-godep-licenses.sh` .
2015-12-08 21:23:59 +00:00
2016-03-07 03:07:34 +00:00
## Testing
2015-12-08 21:23:59 +00:00
2016-03-11 10:06:05 +00:00
Three basic commands let you run unit, integration and/or e2e tests:
2014-10-15 15:30:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2014-10-15 15:30:02 +00:00
cd kubernetes
2016-03-07 03:07:34 +00:00
hack/test-go.sh # Run unit tests
hack/test-integration.sh # Run integration tests, requires etcd
go run hack/e2e.go -v --build --up --test --down # Run e2e tests
2014-10-15 15:30:02 +00:00
```
2016-03-07 03:07:34 +00:00
See the [testing guide ](testing.md ) for additional information and scenarios.
2016-01-13 02:10:38 +00:00
2015-01-15 05:27:13 +00:00
## Regenerating the CLI documentation
2014-10-15 15:30:02 +00:00
2015-07-19 08:54:49 +00:00
```sh
2015-07-20 13:24:20 +00:00
hack/update-generated-docs.sh
2014-10-15 15:30:02 +00:00
```
2015-05-14 22:12:45 +00:00
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-14 22:12:45 +00:00
[![Analytics ](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/development.md?pixel )]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->