Slide 1

Slide 1 text

Whitebox Controller Extensible generic controller for Kubernetes Moto Ishizawa @summerwind Kubernetes Meetup Tokyo #18

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Implementing controller is hard… workqueue informers controller-tools controller-runtime reconciliation loop Golang controller-gen admission webhook owner reference vendor metav1 apimachinery CustomResourceDefinition finalizer client-go corev1

Slide 5

Slide 5 text

• Allow to make a controller without specific knowledges • Allow to implement a controller in familiar programming languages • Allow to validate new controller ideas more quickly Motivation

Slide 6

Slide 6 text

Whitebox Controller • https://github.com/summerwind/whitebox-controller • Extensible generic controller for Kubernetes • It is possible to replace “reconciler” with any command or HTTP server • Very similar to Metacontroller, but executes command • Just like "Whitebox Switch" but it is for Kubernetes controller

Slide 7

Slide 7 text

Extensible reconciler

Slide 8

Slide 8 text

Whitebox Controller Managing resource state Exec hander Command { "object": { "apiVersion": "example.dev/v1alpha1", "kind": "Issue", "metadata": { "name": "example", "namespace": "default" }, "spec": { "title": "Hello World!", "body": "This is an example." } } } Request (stdin) { "object": { "apiVersion": "example.dev/v1alpha1", "kind": "Issue", "metadata": { "name": "example", "namespace": "default" }, "spec": { "title": "Hello World!", "body": "This is an example." }, "status": { "url": "https://github.com/...", "creationTime": 12345 } } } Response (stdout)

Slide 9

Slide 9 text

Implementing controller in bash (1) controllers: - name: issue-controller resource: group: example.summerwind.dev version: v1alpha1 kind: Issue reconciler: exec: command: ./reconcile.sh timeout: 60s debug: true Create the configuration file for Whitebox Controller. config.yaml

Slide 10

Slide 10 text

Implementing controller in bash (2) #!/bin/bash # Read current state from stdio. state=$(cat -) # Do something based on the state. url=$(echo "${state}" | jq -r ".object.status.url|select (.!=null)") if [ "${url}" == "" ]; then url=$(create_issue "${state}") fi # Update state. updated_state=$(echo "${state}" | jq -r ".object.status.url = \"${url}\"") # Write updated state to stdout. echo "${updated_state}" Write your reconciler in bash. reconcile.sh

Slide 11

Slide 11 text

Implementing controller in bash (3) $ whitebox-gen manifest -c config.yaml | kubectl apply -f - customresourcedefinition.apiextensions.k8s.io "issue.example.summerwind.dev" created Generate and apply CRDs.

Slide 12

Slide 12 text

Implementing controller in bash (4) $ whitebox-controller -c config.yaml … {"level":"info","ts":1555560138.050401,"logger":"controller- runtime.controller","msg":"Starting workers","controller":"issue-controller","worker count”:1} Run whitebox-controller command.

Slide 13

Slide 13 text

…and more! • Handler for finalizer • Handler for validation webhook • Handler for mutation webhook • Handler for injection webhook (Experimental resource injection endpoint) • Observer mode (“watch” only reconciler) • Periodic state sync

Slide 14

Slide 14 text

Thank you!