Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom plugin for Kong v1.0.2 is enabled but not installed

Tags:

lua

kong

luarocks

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?

like image 679
Moldovan Daniel Avatar asked Jan 22 '19 12:01

Moldovan Daniel


1 Answers

@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.

Pre 0.14.x

The practical effect is that in Kong < 0.14.x:

custom_plugins = plugin1,plugin2

Or

KONG_CUSTOM_PLUGINS=<plugin-name>

Post 0.14.x

In Kong >= 0.14.x, you now write:

plugins = bundled,plugin1,plugin2

Or

KONG_PLUGINS=bundled,<plugin-name>

If You Don't Use 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.

lua_package_path

The notes about lua_package_path and KONG_LUA_PACKAGE_PATH remain the same as in user5377037's post.

References

  • Upgrade Documentation
  • Configuration Reference
like image 52
stackedsax Avatar answered Sep 30 '22 14:09

stackedsax