Document updated on Oct 10, 2022
All different types of plugins let you freely implement your logic without restrictions. However, make sure to write them implementing the correct interface and compile them respecting the requirements. In this document, we will see how to do it right.
Writing plugins isn’t complicated per se, but Go is very strict with the environment where you compile and load them. Therefore, the following principles are essential:
Yes, it sounds rigorous, but fortunately, some tools will tell you about this, so you don’t have to lose time thinking much about this. Let’s see them below.
Once you have decided what type of plugin to write and started developing it, you need to ensure that your plugin uses the library versions compatible with KrakenD. You can use the following tools:
krakend versiongives you information about the Go and Glibc versions used during compilation.
go.sumfile and warns you about any incompatibilities.
When using Docker to deploy your gateway, the official KrakenD container uses Alpine as the base image. Therefore, to use your custom plugins, they must compile within an Alpine container and use the same Go and Glibc versions as KrakenD. The Plugin Builder docker image spares you from this job.
You can get the plugin builder with the following:
$docker pull krakend/builder:v2.1
Then to build your plugin, you only need to execute the following command inside the folder where your plugin is:
$docker run -it -v "$PWD:/app" -w /app krakend/builder:v2.1 go build -buildmode=plugin -o yourplugin.so .
The command will generate a
yourplugin.so file (name it as you please) that you can now load in KrakenD, as described in injecting plugins
As your custom plugins need to match the Go and libraries versions used to build KrakenD, you have to guarantee your plugin is compatible by checking the
go.sum file with the command
check-plugin (read the documentation)
$krakend check-plugin -v 1.17.0 -s ../myplugin/go.sum 1 incompatibility(ies) found... go have: 1.17.0 want: 1.16.4
Once you have written your plugin with the interface you have chosen, compile it in the same architecture type as follows:
$go mod init myplugin go build -buildmode=plugin -o yourplugin.so .
Now load it in KrakenD, as described in injecting plugins
The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.