kubernetes-crd-demo

module
v0.0.0-...-0eea0ee Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MIT

README

kubernetes-crd-demo

This code accompanies a talk I gave at Go Oslo User Group in December 2019 on extending Kubernetes and code generation.

The Application CRD used in this demo is a simplified version of what we use in the FIAAS go client.

What's in this repository

  • pkg/apis/gooslo.io/v1/types.go: annotated human-made code that defines the data structure of your custom resource.
  • pkg/apis/gooslo.io/v1/[doc.go|register.go]: necessary boilerplate code.
  • pkg/apis/gooslo.io/v1/zz_generated.deepcopy.go: generated deepcopy functions.
  • pkg/client generated clientset, informers, and listers code to handle that custom resource.
  • cmd/…/main.go: a simple client that watches events on our CRD and prints them out.

Usage

Prerequisites
  • This code was written in Go 1.12. Might not work with Go 1.13 due to library incompatibilities. Haven't had time to test/fix this.
  • You need a Kubernetes cluster. You can set one on your machine locally using either kind or minikube.
Usage
  1. Clone this repository and run go get to fetch dependencies.
  2. Start your local Kubernetes cluster.
  3. Run the executable. The easiest way is to run KUBECONFIG=<path to your local cluster's kubeconfig> make local

Troubleshooting

If the event channel doesn't receive any new events (= there's no related activity in the cluster), it will time out and exit quietly. This is ok for the demo, but for production code you probably want another sort of queue. You can use generated informers for that (like in the somewhat confusing sample controller), or you can explore client-go's cache package.

If you get an error that goes like not enough arguments in call to watch.NewStreamWatcher, it means you're using an incompatible client-go version in go.mod. There is a number of solutions to this problem in this apimachinery github issue.

Further reading

Directories

Path Synopsis
cmd
pkg
apis/gooslo.io/v1
Package v1 is the v1 version of the API.
Package v1 is the v1 version of the API.
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/gooslo.io/v1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/gooslo.io/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