k8s-crd-boilerplate

module
v0.0.0-...-4cf9175 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: GPL-3.0

README

k8s-crd-boilerplate

⚠ Kubernetes has evolved a lot since I wrote this boilerplate, these days I recommend you look in the directory of: https://github.com/operator-framework/operator-sdk

As I started writing Kubernetes CDR (Custom Resource Definitions) I found there was a lot of documentation on the details but very little on what was necessary or not to create a project.

This boilerplate contains only what is needed to bootstrap a CRD.

  1. Rename files/packages name from CrdBoilerplate to whatever you are working on
  2. Edit types.go and register.go (in 'pkg/apis/crdboilerplate/v1alpha1/')
  3. Edit ./hack/update-codegen.sh to reflect the change
  4. Generate the code
./hack/update-codegen.sh
  1. Build the controller
go build -o list-things cmd/ls-things/main.go
  1. Edit the CRD manifest (in './artifacts/')
  2. Apply it to the cluster and run your binary
kubectl apply -f artifacts/cdr.yml
  1. Add a new test resource
kubectl apply -f artifacts/example-thing.yml
  1. List all the things
./ls-things -kubeconfig ~/.kube/config
Found a thing with the name 'a-thing' and the content 'something'

I choose not to include the controller daemon code as you can find a very good and up-to-date example on github.com/kubernetes/sample-controller.

Directories

Path Synopsis
cmd
pkg
apis/crdboilerplate
Package crdboilerplate is the internal version of the API.
Package crdboilerplate is the internal version of the API.
apis/crdboilerplate/v1alpha1
Package v1alpha1 is the v1alpha1 version of the API.
Package v1alpha1 is the v1alpha1 version of the API.

Jump to

Keyboard shortcuts

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