todo-crd

module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2019 License: MIT

README

This is an example about how to extend Kubernetes with a Custom Resource Definition.

I have used code-generator to generate types, clients and informers for this CRD. The cmd/main.go starts a shared informer to extend capabilities with your business code.

Run on kubernetes

  1. Start minikube
  2. Deploy CRD, apps
kubectl apply -f artifacts/crd.yaml
kubectl apply -f artifacts/app.yaml
  1. Tail the logs from the pod to see what the application does
  2. Create your first item: kubectl apply -f artifacts/todo.yaml

Dependency Management

The project uses go mod but it is requited by code-generator for the project to be in the GOPATH. You should export GO111MODULE=on to be sure that the project uses go mod even if it is inside the GOPATH.

Generate code

Checkout the project in your GOPATH because code-generator still uses GOPATH. And this is the command I used to generate the code inside pkg/client.

~/go/src/k8s.io/code-generator/generate-groups.sh all \
    github.com/gianarb/todo-crd/pkg/client \
    github.com/gianarb/todo-crd/pkg/apis todoexample:v1

Run locally

You can start minkube, register the crd with kubectl apply -f artifacts/crd.yaml and run go run ./cmd/main.go to start the shared informer app:

go run cmd/main.go
{"level":"info","msg":"The todo operator started."}

This the expected log. As you can see in ./cmd/main.go I have just initialized the Shared Informer without implementing any method. When you create a new todo item from ./artifacts/todo.yaml you should see logs from the application:

$ go run cmd/main.go
{"level":"info","msg":"The todo operator started."}
{"level":"info","msg":"new key received","message_key":"default/buy-book"}
{"level":"info","msg":"new key received","message_key":"default/buy-book"}

Credits

Some of the project and articles I read to make this to work:

Directories

Path Synopsis
pkg
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/todoexample/v1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/todoexample/v1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL