TL;DR: From version v1.12.alpha.3
on, we migrated controller framework to controller-runtime
which is for now actively maintained by the trusted developers. If this is your first time trying out the project, then
no need for you to continue reading. Otherwise if your project is generated by an older version, you will hit some backward-compatibility
issues on upgrading (apologizes we didn't make the feature opt-in b/c integrating controller-runtime literally involves
through-out change in the codebase) and this doc will show you a path to migrating to the new framework w/o hiccups.
- The controller generator now has been removed from
apiserver-boot
, So we will not generate source fileszz_generated.api.register.go
underpkg/controller/...
packages any more. - The new controller template integrated controller-runtime will only be generated for one time on creating the resource.
- The new controller template now contains not only a dummy controller but also local testing environment. When you run
the tests, it'll bootstrap an local kubernetes cluster (please make sure you've installed kubebuilder at this point) and
also install an aggregated apiserver, expecting a 10s-ish time cost for setting up everything. Note that the aggregated
apiserver has to be running on
443
port which may acquire additional priviledges. In this case, consider runningsudo env "GOPATH=$GOPATH" go test ./...
for privilege escalation. (The aggregated apiservers will be able to serve on arbitrary port after kubernetes releasev1.14
)
The point of controller-runtime is to construct a unified controller framework helping developers get rid of troubles from copy/pasting boiler-plates codes when developing a kubernetes controller. The framework implements a Kubernetes API by responding to events (object Create, Update, Delete) and ensuring that the state specified in the Spec of the object matches the state of the system. That is called a reconcile. If they do not match, the Controller will create / update / delete objects as needed to make them match.
Upgrading vendor dependencies for the project will always assures backward-compatibility but the behavior of apiserver-boot
isn't. Vendor updates shall never break anything so that users can track the latest kubernetes w/o conflicts. However, as
for the code re-generation, you'll have to use the v1.12.alpha.2
version of apiserver-boot
so that codes won't mess up.
A complete process of migrating your existing projects to controller-runtime will basically consists of 6 steps:
- Download the latest binaries of
apiserver-builder-alpha
and the version should be at least prior tov1.12.alpha.3
- Run
apiserver-boot init repo --domain=<your domain>
, and the command is supposed to generated a new main source file undercmd/manager
. Note that the package name is changed on purpose so that it won't conflict w/ the existing sources. - Then we will move no to migrate the actual controller packages. e.g. for migrating a resource named
foos
in grouptesting
and versionv1alpha1
, runapiserver-boot create resource --group=testing --version v1alpha1 --resource foos --kind Foo
and it will generate the templated controller using controller-runtime underpkg/controller
incrementally. Note that all the existing controller sources will never be over-written in this step b/c the re-generated file names are different from the legacy ones:- Legacy controller source file names:
controller.go
,controller_test.go
,foo_suite_test.go
. - New controller source file names:
foo_controller.go
,foo_controller_suite_test.go
,foo_controller_test.go
.
- Legacy controller source file names:
- After learning about how controller-runtime works, migrate the existing controller's logic and also it's tests to the new source files.
- Clean-ups. Delete the legacy controller files as mentioned above and don't forget to delete
zz_generated.api/register.go
from the package. - Make sure the tests happy. And file an issue if you encounter any issues.