Reputation: 1581
I have a custom plugin for Kong which worked fine for Kong v0.14.1 but after I upgraded to v.1.0.2 it's throwing an error.
OS used: macOS Mojave
In kong.conf file I have this code:
log_level = debug
plugins=my-custom-plugin
I try to start Kong with this command:
kong start -c kong.conf
and I get this error:
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:50: nginx: [error] init_by_lua
error: /usr/local/share/lua/5.1/kong/init.lua:344: my-custom-plugin plugin is enabled but not installed;
module 'kong.plugins.my-custom-plugin.handler' not found:No LuaRocks module found for kong.plugins.my-custom-plugin.handler
no field package.preload['kong.plugins.my-custom-plugin.handler']
no file './kong/plugins/kong-my-custom-plugin/handler.lua'...
I installed the plugin using this command:
luarocks make
which gave the following output:
my-custom-plugin 1.0-1 is now installed in /usr/local/opt/kong (license: MIT)
Somehow, it appears that Kong is unable to find my installed custom plugin. Any idea why this happens?
Upvotes: 7
Views: 10026
Reputation: 86
@user5377037's answer has most of the relevant details, I just wanted to mention that as of Kong 0.14.x, "custom_plugins" is now just "plugins".
One of the reasons for this change is that you can now use this new variable name to choose to load or not to load plugins that are bundled with Kong -- a useful feature for some. However, if you want to load your custom plugin AND the bundled plugins, you now have to specify the bundled
keyword to indicate that you want to keep the bundled plugins loaded.
The practical effect is that in Kong < 0.14.x:
custom_plugins = plugin1,plugin2
Or
KONG_CUSTOM_PLUGINS=<plugin-name>
In Kong >= 0.14.x, you now write:
plugins = bundled,plugin1,plugin2
Or
KONG_PLUGINS=bundled,<plugin-name>
bundled
If you don't add the bundled
keyword, you'll likely face something like this error:
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:292: key-auth plugin is in use but not enabled
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.1/kong/init.lua:292: in function 'init'
init_by_lua:3: in main chunk
This means that you've set your proxy to use some plugin, but now you aren't loading that plugin on startup so Kong doesn't know what to do and quits. Essentially, you will only be loading your one single custom plugin which probably isn't what you want.
The notes about lua_package_path
and KONG_LUA_PACKAGE_PATH
remain the same as in user5377037's post.
Upvotes: 5
Reputation:
You must now add the custom plugin’s name to the custom_plugins list in your Kong configuration (on each Kong node):
custom_plugins = <plugin-name>
If you are using two or more custom plugins, insert commas in between, like so:
custom_plugins = plugin1,plugin2
Note: You can also set this property via its environment variable equivalent: KONG_CUSTOM_PLUGINS
or define custom plugin in configuration property like:
KONG_CUSTOM_PLUGINS=<plugin-name> kong start
Reminder: don’t forget to update the custom_plugins directive for each node in your Kong cluster.
You should now be able to start Kong without any issue. Consult your custom plugin’s instructions on how to enable/configure your plugin on an API or Consumer object.
To make sure your plugin is being loaded by Kong, you can start Kong with a debug log level:
log_level = debug
OR:
KONG_LOG_LEVEL=debug
Then, you should see the following log for each plugin being loaded:
[debug] Loading plugin <plugin-name>
And here is workaround steps for adding things in custom_plugins and lua_package_path.
custom_plugins = <plugin-name>
Install hello-world plugin by using following steps :
If you have source code of your plugin then move into it and execute the command : luarocks make
it will install your plugin.
Now you have to execute a command : make install-dev
make sure your plugin have makefile like as:
Once you execute this command make install-dev
. It will create lua file at a location something like that :
/your-plugin-path/**lua_modules/share/lua/5.1/kong/plugins/your-plugin-name/**?.lua
Just copy this path and add it into the kong configuration file in lua_package_path
lua_package_path=/your-plugin-path/lua_modules/share/lua/5.1/kong/plugins/your-plugin-name/?.lua
Just start kong : kong start --vv
Upvotes: 3
Reputation: 2243
It looks like it can't find the handler.lua
file, which is required. Can you run $ tree .
at the root of your plugin project?
Here's the result of that same command for a test plugin I did a while back (https://github.com/jerneyio/kong-plugin-header-echo)
$ tree .
.
├── README.md
├── kong
│ └── plugins
│ └── kong-plugin-header-echo
│ ├── handler.lua
│ └── schema.lua
├── kong-plugin-header-echo-0.1.0-1.all.rock
└── kong-plugin-header-echo-0.1.0-1.rockspec
Also, are you sure your handler.lua is exposed in your rockspec? Again, successful example here:
$ cat kong-plugin-header-echo-0.1.0-1.rockspec
package = "kong-plugin-header-echo"
version = "0.1.0-1"
source = {
url = "git//github.com/jerneyio/kong-plugin-header-echo.git"
}
description = {
homepage = "https://github.com/jerneyio/kong-plugin-header-echo",
license = "MIT"
}
dependencies = {
"lua >= 5.3",
"kong >= 0.14"
}
build = {
type = "builtin",
modules = {
["kong.plugins.kong-plugin-header-echo.handler"] = "kong/plugins/kong-plugin-header-echo/handler.lua",
["kong.plugins.kong-plugin-header-echo.schema"] = "kong/plugins/kong-plugin-header-echo/schema.lua"
}
}
Upvotes: 0