Skip to content

trstringer/k8s-controller-custom-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Custom Controller - Custom Resource Handling

Note: the source code is verbosely commented, so the source is meant to be read and to teach

What is this?

An example of a custom Kubernetes controller that's only purpose is to watch for the creation, updating, or deletion of all custom resource of type MyResource (in the all namespaces). This was created as an exercise to understand how Kubernetes controllers work and interact with the cluster and resources.

Running

$ git clone https://github.com/trstringer/k8s-controller-custom-resource
$ cd k8s-controller-custom-resource
$ go run *.go

Inspecting resources in the handler

You are welcome to dump the resources themselves in handler but logging would be extremely verbose (and not interactive). I recommend you use a debugger...

$ dlv debug
(dlv) b main.ObjectCreated
(dlv) c

You can then trigger an event by creating a deployment of nginx...

$ kubectl apply -f example/example-myresource.yaml

The breakpoint should be hit and you can analyze in the debugger the object...

(dlv) p obj

About

Base sample for a custom controller in Kubernetes working with custom resources

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages