Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Whitebox Controller

Whitebox Controller

Introducing Whitebox Controller.


Moto Ishizawa

April 22, 2019


  1. Whitebox Controller Extensible generic controller for Kubernetes Moto Ishizawa @summerwind

    Kubernetes Meetup Tokyo #18
  2. None
  3. None
  4. 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
  5. • 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
  6. 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
  7. Extensible reconciler

  8. 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)
  9. 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
  10. 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
  11. 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.
  12. 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.
  13. …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
  14. Thank you!