- Load locally managed plugins in the controller
- Accept plugins over the network (in-cluster)
- Give a simple health status for each plugin
- Make it available over CRD
- Allow different implementations for the same plugin type
kubebuilder init --domain danielfbm.github.com --repo github.com/danielfbm/plugin-example/controller
kubebuilder create api --group plugins --version v1alpha1 --kind Plugin
For the sake of simplicity just two simple plugin: Foo
and Bar
type Foo interface {
Foos() (string, error)
}
type Bar interface {
Bars() []string
}
- Create a folder
extension
and add the plugin code for the interfaces in the respective files - Implement the basic interface and RPC client and server
- Create a
manager.go
to manage loading of plugins
- Create
plugins
folder - Implement specific plugins
- Change CRD specs and status
- Regenerate crd, deepcopy etc.
make
make manifests
- Add
plugin-folder
flag to main.go file and initiateextension.Manager
- Create and implement
plugin_loader.go
- Add loader to mgr on main.go file, set default hclog
- Compile plugins, manager, and run
This controller will only do one thing:
- Check if the plugin is accessible and adds a condition
- Check which implementation it serves and add a condition for each
- Check the implementation on plugin_controller.go
- Build controller and local plugins:
make docker-build
. CheckDockerfile
for specific build instructions - Install CRD:
make install
- Push you image and deploy:
make deploy
- verify that everything is working fine with
kubectl
kubectl get pods --all-namespaces
to check if the controller is up and running
kubectl get plugins
to check if the local plugins are loaded and checked
- Build the foobar plugin
CGO_ENABLED=0 GOOS=linux go build -o plugins/foobar/bin/foobar plugins/foobar/main.go
- Build the docker image `docker build -t danielfbm/foobarplugin -f plugins/foobar/Dockerfile plugins/foobar
- Deploy on kubernetes using kubectl
run
andexpose
:
*PS: Depending on your kubectl version expose
behaviour could be different, adapt accordingly
kubectl run foobar --image=danielfbm/foobarplugin:latest --image-pull-policy=Never --env BASIC_PLUGIN=hello --port 7000
kubectl expose deploy/foobar --port=7000 --target-port=7000
- Check plugins and status:
kubectl get plugins