2015-07-12 04:04:52 +00:00
|
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
|
2016-06-10 23:46:46 +00:00
|
|
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
|
|
|
|
|
|
|
<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.
|
|
|
|
|
|
|
|
<!-- TAG RELEASE_LINK, added by the munger automatically -->
|
|
|
|
<strong>
|
|
|
|
The latest release of this document can be found
|
2016-06-13 19:24:34 +00:00
|
|
|
[here](http://releases.k8s.io/release-1.3/docs/devel/development.md).
|
2016-06-10 23:46:46 +00:00
|
|
|
|
|
|
|
Documentation for other releases can be found at
|
|
|
|
[releases.k8s.io](http://releases.k8s.io).
|
|
|
|
</strong>
|
|
|
|
--
|
|
|
|
|
|
|
|
<!-- END STRIP_FOR_RELEASE -->
|
2015-07-12 04:04:52 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2016-04-29 20:04:03 +00:00
|
|
|
Docker please follow [these
|
2016-06-10 23:46:46 +00:00
|
|
|
instructions](http://releases.k8s.io/HEAD/build/README.md).
|
2014-10-15 15:30:02 +00:00
|
|
|
|
2016-06-02 18:30:31 +00:00
|
|
|
### Local OS/shell environment
|
|
|
|
|
|
|
|
Many of the Kubernetes development helper scripts rely on a fairly up-to-date GNU tools
|
|
|
|
environment, so most recent Linux distros should work just fine
|
|
|
|
out-of-the-box. Note that Mac OS X ships with somewhat outdated
|
|
|
|
BSD-based tools, some of which may be incompatible in subtle ways, so we recommend
|
|
|
|
[replacing those with modern GNU tools](https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/).
|
|
|
|
|
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
|
2016-04-29 20:04:03 +00:00
|
|
|
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-05-24 15:40:44 +00:00
|
|
|
```sh
|
|
|
|
make
|
|
|
|
```
|
|
|
|
|
2016-04-29 20:04:03 +00:00
|
|
|
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-05-24 15:40:44 +00:00
|
|
|
```sh
|
2016-05-31 00:22:53 +00:00
|
|
|
make cross
|
2016-05-24 15:40:44 +00:00
|
|
|
```
|
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-29 20:04:03 +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
|
2016-04-06 22:03:11 +00:00
|
|
|
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
|
|
|
```
|
|
|
|
|
2016-04-29 20:04:03 +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 20:04:03 +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. This hook will also do a build and test whether documentation generation
|
|
|
|
scripts need to be executed.
|
2016-04-29 01:41:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-04-29 20:04:03 +00:00
|
|
|
Kubernetes uses [godep](https://github.com/tools/godep) to manage dependencies.
|
|
|
|
It is not strictly required for building Kubernetes but it is required when
|
2016-05-12 03:52:10 +00:00
|
|
|
managing dependencies under the vendor/ tree, and is required by a number of the
|
|
|
|
build and test scripts. Please make sure that `godep` is installed and in your
|
|
|
|
`$PATH`, and that `godep version` says it is at least v63.
|
2014-10-15 15:30:02 +00:00
|
|
|
|
|
|
|
### Installing godep
|
2015-07-17 22:35:41 +00:00
|
|
|
|
2016-04-29 20:04:03 +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
|
|
|
|
2016-04-29 20:04:03 +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
|
|
|
|
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 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
|
2016-05-12 03:52:10 +00:00
|
|
|
go get -u github.com/tools/godep
|
2014-10-15 15:30:02 +00:00
|
|
|
```
|
|
|
|
|
2016-05-12 03:52:10 +00:00
|
|
|
3) Add this $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-05-12 03:52:10 +00:00
|
|
|
Note:
|
|
|
|
At this time, godep version >= v63 is known to work in the Kubernetes project
|
|
|
|
|
|
|
|
To check your version of godep:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ godep version
|
|
|
|
godep v66 (linux/amd64/go1.6.2)
|
|
|
|
```
|
|
|
|
|
|
|
|
If it is not a valid version try, make sure you have updated the godep repo
|
|
|
|
with `go get -u github.com/tools/godep`.
|
|
|
|
|
2014-10-15 15:30:02 +00:00
|
|
|
### Using godep
|
2015-07-17 22:35:41 +00:00
|
|
|
|
2016-04-29 20:04:03 +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
|
|
|
|
2016-05-12 03:52:10 +00:00
|
|
|
_Devoting a separate directory is not strictly required, but it is helpful to
|
|
|
|
separate dependency updates from other changes._
|
2015-08-27 00:22:27 +00:00
|
|
|
|
2015-07-19 08:54:49 +00:00
|
|
|
```sh
|
2014-12-16 22:36:39 +00:00
|
|
|
export KPATH=$HOME/code/kubernetes
|
2016-07-02 00:23:21 +00:00
|
|
|
mkdir -p $KPATH/src/k8s.io
|
|
|
|
cd $KPATH/src/k8s.io
|
|
|
|
git clone https://path/to/your/kubernetes/fork # assumes your fork is 'kubernetes'
|
2014-12-16 22:36:39 +00:00
|
|
|
# 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
|
2016-05-12 03:52:10 +00:00
|
|
|
# This will *not* let your local builds see packages that exist elsewhere on your system.
|
2014-12-16 22:36:39 +00:00
|
|
|
export GOPATH=$KPATH
|
|
|
|
```
|
|
|
|
|
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
|
|
|
|
2016-05-16 19:26:55 +00:00
|
|
|
To add a new dependency is simple (if a bit slow):
|
|
|
|
|
2015-07-19 08:54:49 +00:00
|
|
|
```sh
|
2015-08-05 22:16:36 +00:00
|
|
|
cd $KPATH/src/k8s.io/kubernetes
|
2016-05-16 19:26:55 +00:00
|
|
|
DEP=example.com/path/to/dependency
|
|
|
|
godep get $DEP/...
|
2016-05-12 03:52:10 +00:00
|
|
|
# Now change code in Kubernetes to use the dependency.
|
2016-05-16 19:26:55 +00:00
|
|
|
./hack/godep-save.sh
|
|
|
|
```
|
2016-05-12 03:52:10 +00:00
|
|
|
|
2016-05-16 19:26:55 +00:00
|
|
|
To update an existing dependency is a bit more complicated. Godep has an
|
|
|
|
`update` command, but none of us can figure out how to actually make it work.
|
|
|
|
Instead, this procedure seems to work reliably:
|
2015-02-10 09:35:11 +00:00
|
|
|
|
2016-05-16 19:26:55 +00:00
|
|
|
```sh
|
2015-08-05 22:16:36 +00:00
|
|
|
cd $KPATH/src/k8s.io/kubernetes
|
2016-05-16 19:26:55 +00:00
|
|
|
DEP=example.com/path/to/dependency
|
|
|
|
# NB: For the next step, $DEP is assumed be the repo root. If it is actually a
|
|
|
|
# subdir of the repo, use the repo root here. This is required to keep godep
|
|
|
|
# from getting angry because `godep restore` left the tree in a "detached head"
|
|
|
|
# state.
|
|
|
|
rm -rf $KPATH/src/$DEP # repo root
|
|
|
|
godep get $DEP/...
|
|
|
|
# Change code in Kubernetes, if necessary.
|
|
|
|
rm -rf Godeps
|
|
|
|
rm -rf vendor
|
|
|
|
./hack/godep-save.sh
|
|
|
|
git co -- $(git st -s | grep "^ D" | awk '{print $2}' | grep ^Godeps)
|
2014-12-16 22:36:39 +00:00
|
|
|
```
|
|
|
|
|
2016-04-29 20:04:03 +00:00
|
|
|
_If `go get -u path/to/dependency` fails with compilation errors, instead try
|
|
|
|
`go get -d -u path/to/dependency` to fetch the dependencies without compiling
|
2016-05-12 03:52:10 +00:00
|
|
|
them. This is unusual, but has been observed._
|
2015-08-27 00:22:27 +00:00
|
|
|
|
2016-05-16 19:26:55 +00:00
|
|
|
After all of this is done, `git status` should show you what files have been
|
|
|
|
modified and added/removed. Make sure to `git add` and `git rm` them. It is
|
|
|
|
commonly advised to make one `git commit` which includes just the dependency
|
|
|
|
update and Godeps files, and another `git commit` that includes changes to
|
|
|
|
Kubernetes code to use the new/updated dependency. These commits can go into a
|
|
|
|
single pull request.
|
2015-08-27 00:22:27 +00:00
|
|
|
|
2016-04-29 20:04:03 +00:00
|
|
|
5) Before sending your PR, it's a good idea to sanity check that your
|
2016-05-12 03:52:10 +00:00
|
|
|
Godeps.json file and the contents of `vendor/ `are ok by running `hack/verify-godeps.sh`
|
2015-08-27 00:22:27 +00:00
|
|
|
|
2016-05-12 03:52:10 +00:00
|
|
|
_If `hack/verify-godeps.sh` fails after a `godep update`, it is possible that a
|
2016-04-29 20:04:03 +00:00
|
|
|
transitive dependency was added or removed but not updated by godeps. It then
|
2016-05-12 03:52:10 +00:00
|
|
|
may be necessary to perform a `hack/godep-save.sh` to pick up the transitive
|
2016-04-29 20:04:03 +00:00
|
|
|
dependency changes._
|
2015-02-10 09:35:11 +00:00
|
|
|
|
2016-05-12 03:52:10 +00:00
|
|
|
It is sometimes expedient to manually fix the /Godeps/Godeps.json file to
|
|
|
|
minimize the changes. However without great care this can lead to failures
|
|
|
|
with `hack/verify-godeps.sh`. This must pass for every PR.
|
2014-12-16 22:36:39 +00:00
|
|
|
|
2016-04-29 20:04:03 +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-05-24 15:40:44 +00:00
|
|
|
make test # Run unit tests
|
|
|
|
make test-integration # Run integration tests, requires etcd
|
2016-03-07 03:07:34 +00:00
|
|
|
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 -->
|