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

  1. 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
  1. 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
  1. 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
  1. 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 
  1. Log out of your VM and log in again so that the go is added to your path. Verify that go is in the path:
> exit

> ssh ubuntu@thevmhostname

> go version
go version go1.22.5 linux/amd64
  1. Install go delve for debugging on the VM:
go install -v github.com/go-delve/delve/cmd/dlv@latest
  1. 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
  1. 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
  1. 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'
  1. Set the KUBECONFIG and FUNCTION_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.

  1. Use the Connect to a remote host instructions on the Remote Development using SSH page to connect to your VM.

  2. Click Open Folder and browse to the Porch code on the vm, /home/ubuntu/git/github/nephio-project/porch in this case:

Browse to Porch code

  1. VSCode now opens the Porch project on the VM.

Porch code is open

  1. 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.

Launch the Override Server VSCode debug configuration

  1. VSCode complains that go debugging is not supported, click the Install go Extension button.

VSCode go debugging not supported message

  1. Go automatically presents the Go debug plugin for installation. Click the Install button.

VSCode Go debugging plugin selected

  1. VSCode installs the plugin.

VSCode Go debugging plugin installed

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.