Hello, and welcome! If you're thinking about contributing to Kuma's code base, you came to the right place. This document serves as guide/reference for technical contributors.
The following dependencies are all necessary. Please follow the installation instructions for any tools/libraries that you may be missing.
curl
git
unzip
make
go
jq
yq
clang-format
# normally included in system's clang package with some exceptions, please check with the following command:clang-format --version
Throughout this guide, we will use make
to run pre-defined tasks in the Makefile.
Use the following command to list out all the possible commands:
make help
We packaged the remaining dependencies into one target:
make dev/tools
You can install each commands individually if you prefer.
ATTENTION: By default, development tools will be installed at $HOME/.kuma-dev/bin
. Remember to include this directory
into your PATH
, e.g. by adding export PATH=$HOME/.kuma-dev/bin:$PATH
line to the $HOME/.bashrc
file or $HOME/.zshrc
if using zsh.
This can be overridden by setting the env var CI_TOOLS_DIR
, but it isn't recommended.
To run all code formatting, linting and vetting tools use the target:
make check
We use Ginkgo as our testing framework. To run the existing test suite, you have several options:
For all tests, run:
make test
And you can run tests that are specific to a part of Kuma by appending the app name as shown below:
make test/kumactl
For even more specific tests you can specify the package you want to run tests from:
make test TEST_PKG_LIST=<pkgPath>
pkgPath
is a package list selector for example: ./pkg/xds/...
will run all tests in the pkg/xds
subtree.
There's a large set of integration tests that can be run with:
make test/e2e
These tests are big and slow, it is recommended to read e2e-test-tips before running them.
To build all the binaries run:
make build
Like make test
, you can append the app name to the target to build a specific binary. For example, here is how you would build the binary for only kumactl
:
make build/kumactl
This could help expedite your development process if you only made changes to the kumactl
files.
Like any other go program Kuma can be debugged using dlv. In this section we'll go into how to trigger a breakpoint both in K8S and Universal.
- Disable k8s leader election (optional)
- Remove "-w -s" from LDFLAGS here so that debugging symbols are not stripped
- Always add
EXTRA_GOFLAGS='-gcflags "all=-N -l"'
to build / deploy parameters to make sure debug info is in the binaries - Run
make k3d/start
- Run
make EXTRA_GOFLAGS='-gcflags "all=-N -l"' -j k3d/deploy/kuma
- Change the Kuma deployment:
- Remove readiness and Liveness probes (otherwise Kubernetes will kill the container if you stay in a breakpoint long enough)
- set runAsNonRoot: false
- Double the memory (debugger can make the container OOM)
- Check go version in
go.mod
, runkubectl debug --profile=general -n kuma-system -it kuma-control-plane-POD_HASH --image=golang:1.GO_VERSION_FROM_GO_MOD-bookworm --target=control-plane -- bash
- Install
dlv
version that is closes to thego.mod
version in the container, run:go install github.com/go-delve/delve/cmd/dlv@vCLOSEST_DLV_VERSION
- Run
dlv --listen=:4000 --headless=true --api-version=2 --accept-multiclient attach 1
- Setup port forward for
4000
- Run goland/vscode debugger with remote target on port
4000
- Put a breakpoint where you want
- Enjoy!
- Add
4000
port in UniversalApp so that it's exposed, and the debugger can connect. - Remove "-w -s" from LDFLAGS here so that debugging symbols are not stripped
- Add a
time.Sleep
in a place where you want to debug the test - Run the tests
make -j test/e2e/debug EXTRA_GOFLAGS='-gcflags "all=-N -l"' E2E_PKG_LIST=./test/e2e_env/universal/...
- Wait to hit the
time.Sleep
- Figure out the
kuma-cp
container id by running:docker ps | grep kuma-cp
- Exec into the container:
docker exec -it kuma-3_kuma-cp_3dkYrT bash
- Download the same go as in
go.mod
- e.g.curl -o golang https://dl.google.com/go/go1.23.2.linux-arm64.tar.gz
- Extract using
tar xzf golang
- Install
dlv
version that is closes to thego.mod
version in the container, run:go install github.com/go-delve/delve/cmd/dlv@vCLOSEST_DLV_VERSION
- Run
dlv --listen=:4000 --headless=true --api-version=2 --accept-multiclient attach 1
- Figure out the port on the host machine
docker ps | grep kuma-3_kuma-cp_3dkYrT
, look for the port forward for4000
- Run goland/vscode debugger with remote target on port from point 12
- Enjoy!
Execute
make -j k3d/restart
To stop any existing Kuma K3D cluster, start a new K3D cluster, load images, deploy Kuma and Kuma counter demo.
You can test development versions by first pushing to gcr.io
:
gcloud auth configure-docker
make images/push DOCKER_REGISTRY=gcr.io/proj-123456
then setting up kubectl
to connect to your cluster and installing Kuma:
gcloud container clusters get-credentials cluster-name
kumactl install control-plane --registry=gcr.io/proj-123456 | kubectl apply -f -