Build your kubernetes operator easily
Choose one of the following:
Cloudflare Pages (China-mainland-friendly)
GitHub Pages
https://flyingonion.github.io/koolbuilder/index.html
Controller name is the name of the controller. It also decides go module name if you choose not to customize it.
Select controller.go
and see the controller structure name.
Go module name is the name of the go module. By default, it is the lowercase of controller name, but you can customize it.
Select go.mod
file and try changing the module name.
Go version is the version of the Go compiler.
See the go 1.21.4
line in go.mod
file.
Kubernetes API version is the version of the Kubernetes API.
See dependencies in go.mod
file.
Namespace sets limits on resources.
Set to empty string to use all namespaces.
If set, then for each resource whose scope is namespaced, the controller will only manage resources in the specified namespace.
Retry is the number of times to retry when controller failed to add a main resource to workqueue.
Main resource is the resource that the controller controls. When a new event (add/update/delete) comes, the corresponding resource should be added to workqueue and got synced.
Other resources are the resources that the controller requires when managing the main resource. Controller can get their information by resource listers.
For example, official deployment controller takes Deployment
as main resource. Meanwhile, it requires to monitor ReplicaSet
and Pod
too. In this case, the yaml configuration should be like this:
resources:
- kind: Deployment # main resource
- kind: ReplicaSet
- kind: Pod
To see the code, click Load Example
and choose Custom Deployment Controller
.
To ensure user friendliness, we do not adopt strict validation on the form. Even invalid inputs can generate code.
If you encounter an error, please check following issues:
-
Check if there's any
undefined
orUnknownType
in the code. If so, there may be wrong filling ofGroup
,Version
orKind
field. -
Check if you have same
Kind
in different resources.Kind
should be unique. -
Check if each custom resource has a definition struct and has already implemented this method:
DeepCopyObject() runtime.Object
Each resource must be a
runtime.Object
, or the controller program will panic.
If you have any other issues, please don't hesitate to let us know.
Official resources are like Deployment
, Pod
, Service
, ConfigMap
, Job
, etc. They have a predefined group like ""
(aka core
), apps
, batch
, etc.
Custom resources are defined by third-party user.
"Generate Resource Template" is made to ensure that each resource is a runtime.Object
.
Official resources are already runtime.Object
s. They don't need to generate DeepCopyObject
method.
For custom resources, things are a little bit complex.
If you want to control a predefined resource from a third-party operator, choose None. The DeepCopyObject
method must be already generated using deepcopy-gen.
If you want a newly-defined resource for the controller, choose Both in "Generate Resource Template" field. In this case, koolbuilder will generate definition struct and DeepCopyObject
for you. All you need is to fill Spec
and Status
field.
Yes. Some official resources do have different versions. You can choose supported version for each resource based on your Kubernetes.
The Kubernetes api version does not have great influence. If Group
and Version
both match, the operator will work.
No. All the functions (including download) are implemented by front-end code.
Please use the command line tool.
(Currently it is out-of-date. We are working on it to match the latest frontend.)
go install github.com/FlyingOnion/koolbuilder@latest
cd <your-project>
koolbuilder -f controller.yaml
Files that will be overwritten:
main.go
controller.go
Files that will be updated:
custom.go
Well, it's not a big deal. You can choose to generate structure only and use deepcopy-gen to generate method.
(It's because we don't have much time reading and understanding deepcopy-gen and write a generator like that.)
The project is licensed under the MIT license.
This project is inspired by zhaohuabing's tutorial, which gives a brief and clear introduction to kubernetes operator.
Besides, with a lot of useful frontend libraries, I saved a lot of time writing my pages. They are:
- Add GitHub corner
- Update go command line tool
- Add
config.yaml
to support command line tool - Add
Generate Definition Struct
option - Add
Generate DeepCopyObject
option - Add the rest of the official resources (currently we just add some resources in
core
,apps
, andbatch
group) - Support custom sync period (currently all resources are 30s)
- Add
Dockerfile
,Makefile
, k8s yaml config files - Add
Load Example