Share
Embed
Transcript
14 slides
-
Whitebox Controller Extensible generic controller for Kubernetes Moto Ishizawa @summerwind
Kubernetes Meetup Tokyo #18 -
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 -
• 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 -
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 -
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) -
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 -
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 -
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. -
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. -
…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