Development Workflow - Build, Development and Test

Building KubeSphere on a local OS/shell environment

For Quick Taste Binary

  1. mkdir ks-tmp
  2. cd ks-tmp
  3. echo 'module kubesphere' > go.mod
  4. echo 'replace (
  5. github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1
  6. github.com/kiali/kiali => github.com/kubesphere/kiali v0.15.1-0.20190407071308-6b5b818211c3
  7. github.com/kubernetes-sigs/application => github.com/kubesphere/application v0.0.0-20190518133311-b9d9eb0b5cf7
  8. )' >> go.mod
  9. GO111MODULE=on go get kubesphere.io/kubesphere@d649e3d0bbc64bfba18816c904819e4850d021e0
  10. GO111MODULE=on go build -o ks-apiserver kubesphere.io/kubesphere/cmd/ks-apiserver # build ks-apiserver
  11. GO111MODULE=on go build -o ks-apigateway kubesphere.io/kubesphere/cmd/ks-apigateway # build ks-apigateway
  12. GO111MODULE=on go build -o ks-controller-manager kubesphere.io/kubesphere/cmd/controller-manager # build ks-controller-manager
  13. GO111MODULE=on go build -o ks-iam kubesphere.io/kubesphere/cmd/ks-iam # build ks-iam

For Building KubeSphere Images

KubeSphere components are often deployed as a container in a kubernetes cluster, you may need to build a Docker image locally.

  1. Clone repo to local
  1. git clone https://github.com/kubesphere/kubesphere.git
  1. Run Docker command to build image
  1. # $REPO is the docker registry to push to
  2. # $Tag is the tag name of the docker image
  3. # The full go build process will be executed in the Dockerfile, so you may need to set GOPROXY in it.
  4. docker build -f build/ks-apigateway/Dockerfile -t $REPO/ks-apigateway:$TAG .
  5. docker build -f build/ks-apiserver/Dockerfile -t $REPO/ks-apiserver:$TAG .
  6. docker build -f build/ks-iam/Dockerfile -t $REPO/ks-account:$TAG .
  7. docker build -f build/ks-controller-manager/Dockerfile -t $REPO/ks-controller-manager:$TAG .
  8. docker build -f ./pkg/db/Dockerfile -t $REPO/ks-devops:flyway-$TAG ./pkg/db/

Test

In the development process, it is recommended to use local Kubernetes clusters, such as minikube, or to install an single-node all-in-one environment (Kubernetes-based) for quick testing.

Tip: It also supports to use Docker for Desktop ships with Kubernetes as the test environment.

Development Workflow

Development Workflow - 图1

1 - Fork in the cloud

  1. Visit KubeSphere GitHub - Backend

  2. Click Fork button to establish a cloud-based fork.

2 - Clone fork to local storage

Per Go’s [workspace instructions][https://golang.org/doc/code.html#workspaces\], place KubeSphere’ code on your GOPATH using the following cloning procedure.

  1. Define a local working directory:
  1. $ export working_dir=$GOPATH/src/kubesphere.io
  2. $ export user={your github profile name}
  1. Create your clone locally:
  1. $ mkdir -p $working_dir
  2. $ cd $working_dir
  3. $ git clone https://github.com/$user/kubesphere.git
  4. $ cd $working_dir/kubesphere
  5. $ git remote add upstream https://github.com/kubesphere/kubesphere.git
  6. # Never push to upstream master
  7. $ git remote set-url --push upstream no_push
  8. # Confirm that your remotes make sense:
  9. $ git remote -v

3 - Keep your branch in sync

  1. git fetch upstream
  2. git checkout master
  3. git rebase upstream/master

4 - Add new features or fix issues

Branch from it:

  1. $ git checkout -b myfeature

Then edit code on the myfeature branch.

Test and build

Currently, make rules only contain simple checks such as vet, unit test, will add e2e tests soon.

Using KubeBuilder

  • For Linux OS, you can download and execute this KubeBuilder script.
  • For MacOS, you can install KubeBuilder by following this guide.

Run and test

  1. $ make all
  2. # Run every unit test
  3. $ make test

Run make help for additional information on these make targets.

5 - Development in new branch

Sync with upstream

After the test is completed, suggest you to keep your local in sync with upstream which can avoid conflicts.

  1. # Rebase your the master branch of your local repo.
  2. $ git checkout master
  3. $ git rebase upstream/master
  4. # Then make your development branch in sync with master branch
  5. git checkout new_feature
  6. git rebase -i master

Commit local changes

  1. $ git add <file>
  2. $ git commit -s -m "add your description"

6 - Push to your folk

When ready to review (or just to establish an offsite backup or your work), push your branch to your fork on github.com:

  1. $ git push -f ${your_remote_name} myfeature

7 - Create a PR

CI/CD

KubeSphere uses Travis CI as a CI/CD tool.

The components of KubeSphere need to be compiled and build include following:

ks-apiserver, ks-controller-manager, ks-account, ks-apigateway, ks-devops

After your PR is merged,Travis CI will compile the entire project and build the image, and push the image kubespheredev/[component-name]:latest to Dockerhub (e.g. kubespheredev/ks-apiserver:latest)

Code conventions

Please reference Code conventions and follow with the rules.

Note:

  • All new packages and most new significant functionality must come with unit tests
  • Comment your code in English, see Go’s commenting conventions