Cisco Tech Blog CiscoTech Blog Close
Home Contact

During the development of the Pipeline Platform all of its key building blocks such as Pipeline, Hollowtrees and Bank-Vaults have relied on making extensive Kubernetes API calls. Often, we tried a quick K8s API call or ran a small PoC inside a cluster, while also wanting to avoid the usual deployment process. We quickly realized that we needed a shortcut.

There are tools like telepresence that support slightly more complex scenarios. However, for simple hacks they tend toward overkill - require osxfuse, use VPN + ssh to make the network available, etc - whereas, when making a quick and dirty API call, this 21 lines of bash script does the job.

kurun is like go run πŸ”—︎

The go run command is a very convenient CLI subcommand for executing Golang code during the development phase. Many of our applications make calls to the Kubernetes API and for a long time we were in need of a utility that could very quickly execute the Go code inside Kubernetes. That’s why we wrote kurun, a dirty little bash utility, to execute Go code inside Kubernetes with a oneliner:

kurun main.go

It’s that easy.

To see how you can leverage kurun, let’s try, just as an example, using it to list all the nodes in a Kubernetes cluster:

 1package main
 3import (
 4	"fmt"
 5	"os"
 7	metav1 ""
 8	""
 9	""
12func main() {
13	fmt.Println(os.Args)
15	config, err := rest.InClusterConfig()
16	if err != nil {
17		panic(err)
18	}
20	client, err := kubernetes.NewForConfig(config)
21	if err != nil {
22		panic(err)
23	}
25	nodes, err := client.CoreV1().Nodes().List(metav1.ListOptions{})
26	if err != nil {
27		panic(err)
28	}
30	fmt.Println("List of Kubernetes nodes:")
31	for _, node := range nodes.Items {
32		fmt.Printf("- %s - %s\n", node.Name, node.Labels)
33	}

Execute the following commands in the CLI, and make sure your kubectl is pointed to the cluster you would like to use:

 1git clone
 2cd kurun
 3# Download the dependencies, this is just a one-time step to get the k8s libraries
 4go get ./...
 5./kurun test.go
 6Sending build context to Docker daemon  31.05MB
 7Step 1/2 : FROM alpine
 8 ---> 3fd9065eaf02
 9Step 2/2 : ADD main /
10 ---> 0f4ee24ec5ea
11Successfully built 0f4ee24ec5ea
12Successfully tagged kurun:latest
14List of Kubernetes nodes:
15- docker-for-desktop - map[]

Learn by the code πŸ”—︎

This project is open source and, of course, available in our GitHub repository.