This document is a guide to start developing the Kvrocks operator.
We recommend you use a Linux/macOS platform for development.
-
Go
- Currently, building the Kvrocks operator requires Go 1.19 or later.
-
Docker
-
Kubernetes cluster
- You can use the minikube to provision your local Kubernetes cluster
Before getting started, please run the following commands to perform some checks:
kubectl version --short
The local manifests contain the CRD, run the following command to install it:
make install
Expected output:
$ kubectl get crds
NAME CREATED AT
kvrocks.kvrocks.apache.org 2023-04-22T06:23:33Z
- Install OpenKruise
helm repo add openkruise https://openkruise.github.io/charts/
helm repo update
helm install kruise openkruise/kruise --version 1.4.0
- Run the operator
make run
Now stop the process and we're ready for debugging.
Telepresence is an open-source tool that allows you to access services in a Kubernets cluster as if you were in a local environment.
Note: You can refer the Telepresence github for more detail.
- To install Telepresence, run the following command or refer to the official installation guide
# 1. Download the latest binary (~50 MB):
sudo curl -fL https://app.getambassador.io/download/tel2/linux/amd64/latest/telepresence -o /usr/local/bin/telepresence
# 2. Make the binary executable:
sudo chmod a+x /usr/local/bin/telepresence
- Then run the following command to set up traffic manager:
telepresence helm install
- Now run the following command to connect the cluster:
telepresence connect
- Debug the operator with your favorite IDE. And we provide the VSCode launch configuration for debugging.
Debugging in VSCode requires a launch configuration, you can use the following configuration:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Kvrocks Operator",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"args": [],
"env": {
"NO_PROXY": "kubernetes.docker.internal,127.0.0.1,localhost"
},
}
]
}
Now start debugging by clicking the menu [Run > Start Debugging] or pressing F5. The following is a list of significant functions/methods/files that might be useful as breakpoints:
main() main.go
, the entry point of the Kvrocks operatorKVRocksReconciler.Reconcile() pkg/controller/kvrocks_controller.go
, the core function of the Kvrocks operator
- After debugging, run the following command to clean up the traffic manager:
telepresence quit # disconnect from the cluster
telepresence quit -ur # stop telepresence's daemon processes
To build a binary of the Kvrocks operator, run the following command.
make build
The binary would be generated in the bin
directory
To build a Docker/OCI-compatible image of the Kvrocks operator, run the following command:
# build image with tag "kvrocks.apache.org/rockslabs/kvrocks-operator:latest"
make docker-build
# build image with tag "rockslabs/kvrocks-operator:latest"
REGISTRY=rockslabs make docker-build
# build image with tag "kvrocks.apache.org/rockslabs/kvrocks-operator:nightly"
TAG=nightly make docker-build