Running virt-controller locally

While developing Kubevirt, I often want to step through my code. My most recent tasks have involved the virt-controller process. Here’s how I debug them.

UPDATED: See the full command line at the end.

A little background; during development, we use a vagrant based deployment of Kubernetes running in a two node cluster. We need two nodes to test VM migrations. This has been the biggest reason we have not yet moved to minikube.

The various piece of kubevirt run in the vagrant cluster inside containers. However, the design of Kubernetes (which kubevirt follows) allows a controller to run from pretty much anywhere that it has access to the API server. In this case, I want to run it from within my git repo on my laptop. I actually run it from gogland, as I like the interactive debugger, but that is not a requirement.

The first step is to bring up the cluster;

vagrant up
make vagrant-deploy

Once that is up and running (successfully), delete the virt-controller deployment.

cluster/kubectl.sh delete deployments virt-controller

One hack: I had to change the name of the file from cmd/virt-controller/virt-controller.go to cmd/virt-controller/main.go or I could not debug it. Seems to be a bug in gogland. Once I changed the file name, running it will report an error.

2017/06/23 22:09:25 invalid configuration: default cluster has no server defined

To run any of the kubernetes aware pieces you have to pass in a proper configuration environment. In the case of virt-controller, that is done by setting the parameters on the command line by adding the flag.

UPDATED: added the rest of the parameters:

--kubeconfig=/home/ayoung/go/src/kubevirt.io/kubevirt/cluster/vagrant/.kubeconfig    --launcher-image kubevirt/virt-launcher:devel --migrator-image kubevirt/virt-handler:devel --port 8182

Find the run toolbar.

Edit the configuration for main.go

Add the above line to Program Arguments.

once you run it you should see successful start up in the logs:

 level=info timestamp=2017-06-24T02:10:35.858154Z pos=main.go:89 component=virt-controller service=http action=listening interface=0.0.0.0 port=8182
 level=info timestamp=2017-06-24T02:10:35.858175Z pos=vm.go:73 component=virt-controller service=http msg="Starting controller."
 level=info timestamp=2017-06-24T02:10:35.858272Z pos=migration.go:70 component=virt-controller service=http msg="Starting controller."

To run from the command line, after running make to compile all the files:

$ bin/virt-controller --kubeconfig=/home/ayoung/go/src/kubevirt.io/kubevirt/cluster/vagrant/.kubeconfig    --launcher-image kubevirt/virt-launcher:devel --migrator-image kubevirt/virt-handler:devel --port 8182
 
level=info timestamp=2017-06-24T02:13:03.129090Z pos=virt-controller.go:89 component=virt-controller service=http action=listening interface=0.0.0.0 port=8182
level=info timestamp=2017-06-24T02:13:03.129093Z pos=vm.go:73 component=virt-controller service=http msg="Starting controller."
level=info timestamp=2017-06-24T02:13:03.129170Z pos=migration.go:70 component=virt-controller service=http msg="Starting controller."

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.