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

Whitebox Controller

Whitebox Controller

Introducing Whitebox Controller.

Moto Ishizawa

April 22, 2019
Tweet

More Decks by Moto Ishizawa

Other Decks in Technology

Transcript

  1. 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
  2. • 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
  3. 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
  4. 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)
  5. 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
  6. 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
  7. 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.
  8. 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.
  9. …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