Kubebuilder 1.0 adds a new flag --project-version, it accepts two different values, v0 and v1. When v0 is used, the kubebuilder behavior and workflow are the same as kubebuilder 0.*. When v1 is specified, the generated v1 project layout is architecturally different from v0 project. v1 project use controller-runtime set of libraries for controller implementation and used tools under controller-tools for scaffolding and generation.
- kubebuilder v0 has
init,create controller,create resource,create config,generatecommands and the workflow is:
kubebuilder init --domain example.com
kubebuilder create resource --group <group> --version <version> --kind <Kind>
GOBIN=${PWD}/bin go install ${PWD#$GOPATH/src/}/cmd/controller-manager
bin/controller-manager --kubeconfig ~/.kube/config
kubectl apply -f hack/sample/<resource>.yaml
docker build -f Dockerfile.controller . -t <image:tag>
docker push <image:tag>
kubebuilder create config --controller-image <image:tag> --name <project-name>
kubectl apply -f hack/install.yaml
Every time the resource or controller is updated, users need to run kubebuilder generate to regenerate the project.
- kubebuilder v1 has
init,create apicommands and the workflow is
kubebuilder init --domain example.com --license apache2 --owner "The Kubernetes authors"
kubebuilder create api --group ship --version v1beta1 --kind Frigate
make install
make run
In a v1 project, there is no generate command. When the resource or controller is updated, users don't need to regenerate the project.
- v0 project contains a directory
pkg/clientwhile v1 project doesn't - v0 project contains a directory
injectwhile v1 project doesn't - v0 project layout follows predefined directory layout
pkg/apisandpkg/controllerwhile v1 project accepts user-specified path - In v1 project, there is a
init()function for every api and controller.
-
v0 projects import the controller library from kubebuilder
kubebuilder/pkg/controller. It provides aGenericControllertype with a list of functions. -
v1 projects import the controller libraries from controller-runtime, such as
controller-runtime/pkg/controller,controller-runtime/pkg/reconcile.
-
In v0 projects, the client libraries is generated by
kubebuilder generateunder directorypkg/clientand imported wherever they are used in the project. -
v1 projects import the dynamic client library from controller-runtime
controller-runtime/pkg/client.
Wiring refers to the mechanics of integrating controllers into controller-managers and injecting the dependencies in them.
- v0 projects have an
injectpackage and it provides functions for adding the controller to controller-manager as well as registering CRDs. - v1 projects don't have a
injectpackage, the controller is added to controller-manager by ainitfunction inside add_.go file inside the controller directory. The types are registered by aninitfunction inside _types.go file inside the apis directory.