Elemental Operator - Wrangler -> Kubebuilder migration #409
alexander-demicev
started this conversation in
Ideas
Replies: 2 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Elemental Operator - Wrangler -> Kubebuilder migration
Established
TBD (do we actually need this section for the time being?)
Status
TBD (probably here it would be enough to keep track of PRs and GH issues, just a list of links, not to duplicate data)
Context
This ADR explains the path of migrating the Elemental Operator from Wrangler to Kubebuiler.
What is Wrangler?
Wrangler is a framework for building custom kubernetes APIs. It provides a similar experience as client-go
where all client interactions with the custom resources are generated. Generated client code is static meaning it has to be generated for every custom resource.
The controller implementation is based on callbacks allowing to react on object changes.
What is kubebuilder?
Kubebuilder is also a framework for building custom kubernetes APIs. It's goal is to reduce the amount of boilerplate and reduce the complexity of building
kubernetes APIs. Kubebuilder comes with a CLI that helps with scaffolding the project and
provides a set of tools for generating controller manifests(CRDs, RBAC resources, webhooks). Client part of Kubebuilder is based on controller-runtime, this
means that client is dynamic and there is no need to generate big chunks of code of every resources.
The controller implementation is based on a process called
reconciliation
where reconcile loops aretriggered on each event related to the custom resource or other watched additional resources. This approach simplifies controller development by not requiring developers to set up callbacks manually.
Motivation
Using Kubebuilder will improve the overall quality of the Elemental Operator.
An example of these tools usage is Cluster API and all it's providers.
setup event handlers manually.
server allowing unit tests to use real kubernetes client and avoid working with the fake one.
Goals
Non-Goals
Design details
1. Set up second container
In order to not break anything in the current implementation we plan to work on migration in a separate branch as it's a big change. The migration of the controllers can be done in steps where we replace the controllers one
by one making sure that nothing breaks at any point of migration.
To be able to do so as a first step we can add a new command to the operator binary and run it as second container near current one in the deployment:
Another reason for having a second container is that options for configuring controller-runtime manager are a bit different from
what we pass to the Wrangler controllers, a separate command with it's own arguments will make the integration cleaner and not require us
touch any existing code.
2. Prepare Makefile
Before we can start writing new controllers we should also ensure the required binaries for code generation and testing are present. Kubebuilder provides binary for generating operator manifests from code like CRDs, RBAC
objects, webhooks, etc. and controller-runtime will require a binary for downloading etcd and Kubernetes API
server for testing. These binaries can be managed with Makefile:
3. Include new manifests to the helm chart.
We are using helm chart and it means that we have to include new changes in the helm chart,
make generate
will generate the CRDs for us, we can place them in the chart directory. Make task will generate CRDs in aseparate directory and it will have the following structure:
It will be easier for us to bundle the assets into one file before moving them to the chart. We can use Kustomize as it not only bundles the resources for us but also can apply some customizations in case we need them. Kustomize is also the default tool for releasing manifests for
projects using Kubebuilder.
The Makefile change can look like this:
4. Start implementing the controllers.
First, we have to add our API definition to the
api/
directory, in this case it's located in the root of the project. Example of the API package from the Kubebuiler tutorial.Next, we have to setup controller in
controllers
package(link to example) and add it to the main(another example).Finally we can run
make generate
and try out the new controller.5. Switch off old controllers.
Once new controllers are in place, we can switch off old controllers by removing or commenting them out.
pkg/operator/operator.go
Risks and Mitigations
The migration might break existing functionality after upgrade. In order to minimize the risks we have to:
v1beta1
version no matter if we are running new or oldcontrollers.
v1beta1
to make sure that all resource controller have both Wrangler and Kubebuiler implementations.Useful links
Beta Was this translation helpful? Give feedback.
All reactions