Setting up a VM environment
This tutorial gives short instructions on how to set up a development environment for Porch on a Nephio VM. It outlines the steps to get a kind cluster up and running to which a Porch instance running in Visual Studio Code can connect to and interact with. If you are not familiar with how porch works, it is highly recommended that you go through the Starting with Porch tutorial before going through this one.
Setting up the environment
- The first step is to install the Nephio sandbox environment on your VM using the procedure described in Installation on a single VM. In short, log onto your VM and give the command below:
wget -O - https://raw.githubusercontent.com/nephio-project/test-infra/main/e2e/provision/init.sh | \
sudo NEPHIO_DEBUG=false \
NEPHIO_BRANCH=main \
NEPHIO_USER=ubuntu \
bash
- Set up your VM for development (optional but recommended step).
echo '' >> ~/.bashrc
echo 'source <(kubectl completion bash)' >> ~/.bashrc
echo 'source <(kpt completion bash)' >> ~/.bashrc
echo 'source <(porchctl completion bash)' >> ~/.bashrc
echo '' >> ~/.bashrc
echo 'alias h=history' >> ~/.bashrc
echo 'alias k=kubectl' >> ~/.bashrc
echo '' >> ~/.bashrc
echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
sudo usermod -a -G syslog ubuntu
sudo usermod -a -G docker ubuntu
- Log out of your VM and log in again so that the group changes on the
ubuntu
user are picked up.
> exit
> ssh ubuntu@thevmhostname
> groups
ubuntu adm dialout cdrom floppy sudo audio dip video plugdev syslog netdev lxd docker
- Install
go
so that you can build Porch on the VM:
wget -O - https://go.dev/dl/go1.22.5.linux-amd64.tar.gz | sudo tar -C /usr/local -zxvf -
echo '' >> ~/.profile
echo '# set PATH for go' >> ~/.profile
echo 'if [ -d "/usr/local/go" ]' >> ~/.profile
echo 'then' >> ~/.profile
echo ' PATH="/usr/local/go/bin:$PATH"' >> ~/.profile
echo 'fi' >> ~/.profile
- Log out of your VM and log in again so that the
go
is added to your path. Verify thatgo
is in the path:
> exit
> ssh ubuntu@thevmhostname
> go version
go version go1.22.5 linux/amd64
- Install
go delve
for debugging on the VM:
go install -v github.com/go-delve/delve/cmd/dlv@latest
- Clone Porch onto the VM
mkdir -p git/github/nephio-project
cd ~/git/github/nephio-project
# Clone porch
git clone https://github.com/nephio-project/porch.git
cd porch
- Change the Kind cluster name in the Porch Makefile to match the Kind cluster name on the VM:
sed -i "s/^KIND_CONTEXT_NAME ?= porch-test$/KIND_CONTEXT_NAME ?= "$(kind get clusters)"/" Makefile
- Expose the Porch function runner so that the Nephio server running in VSCode can access it
kubectl expose svc -n porch-system function-runner --name=xfunction-runner --type=LoadBalancer --load-balancer-ip='172.18.0.202'
- Set the
KUBECONFIG
andFUNCTION_RUNNER_IP
environment variables in the.profile
file You must do this step before connecting with VSCode because VSCode caches the environment on the server. If you want to change the values of these variables subsequently, you must restart the VM server.
echo '' >> ~/.profile
echo 'export KUBECONFIG="/home/ubuntu/.kube/config"' >> ~/.profile
echo 'export FUNCTION_RUNNER_IP="172.18.0.202"' >> ~/.profile
You have now set up the VM so that it can be used for remove debugging of Porch.
Setting up VSCode
Use the [VSCode Remote SSH] ( https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) plugin to To debug from VSCode running on your local machine towards a VM. Detailed documentation on the plugin and its use is available on the Remote Development using SSH in the VSCode documentation.
-
Use the Connect to a remote host instructions on the Remote Development using SSH page to connect to your VM.
-
Click Open Folder and browse to the Porch code on the vm,
/home/ubuntu/git/github/nephio-project/porch
in this case:
- VSCode now opens the Porch project on the VM.
- We now need to install support for
go
debugging in VSCode. Trigger this by launching a debug configuration in VSCode. Here we use the Launch Override Server configuration.
- VSCode complains that
go
debugging is not supported, click the Install go Extension button.
- Go automatically presents the Go debug plugin for installation. Click the Install button.
- VSCode installs the plugin.
You have now set up VSCode so that it can be used for remove debugging of Porch.
Getting started with actual development
You can find a detailed description of the actual development process here.