Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/#kong-community
Apache License 2.0
38.28k stars 4.75k forks source link

Error "error loading plugin schemas: on plugin <my-plugin>: <my-plugin> plugin is enabled but not installed" with Python plugin for kong #13101

Open AlleMartins opened 1 month ago

AlleMartins commented 1 month ago

Is there an existing issue for this?

Kong version ($ kong version)

Kong 3.6

Current Behavior

Using kong version 3.6, I am encountering when running the kong image "error loading plugin schemas: on plugin : plugin is enabled but not installed". The plugin is implemented with Python 3.12.3, I am using the python plugin present in this link as a plugin: https://github.com/Kong/kong-plugin-py-geocode/tree/main/kong-py-plugins. My docker-compose.yml is as follows: version: '3.9' x-kong-config: &kong-env KONG_DATABASE: ${KONG_DATABASE:-postgres} KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong} KONG_PG_HOST: db KONG_PG_USER: ${KONG_PG_USER:-kong} KONG_PG_PASSWORD_FILE: /run/secrets/kong_postgres_password

volumes: kong_data: {} kong_prefix_vol: driver_opts: type: tmpfs device: tmpfs kong_tmp_vol: driver_opts: type: tmpfs device: tmpfs

networks: kong-net: external: false

services: kong-migrations: image: "${KONG_DOCKER_TAG:-kong:latest}" command: kong migrations bootstrap profiles: [ "database" ] depends_on:

secrets: kong_postgres_password: file: ./POSTGRES_PASSWORD

and my dockerfile.kong is as follows:
FROM kong:3.6

USER root

RUN apt-get update && \ apt-get install -y python3 python3-pip python3-dev libffi-dev gcc g++ make && \ PYTHONWARNINGS=ignore pip3 install kong-pdk geopy

COPY ./kong-python-pdk /opt/kong-python-pdk

COPY --chown=kong --chmod=555 ./kong-python-pdk/kong-pluginserver.py /usr/local/bin/kong-python-pluginserver

COPY custom_plugins/python_plugin /usr/local/share/lua/5.1/kong/plugins/python_plugin

COPY custom_plugins/my_plugin /usr/local/share/lua/5.1/kong/plugins/my_plugin

RUN chown -R kong:kong /usr/local/share/lua/5.1/kong/plugins/my_plugin

RUN chown -R kong:kong /usr/local/share/lua/5.1/kong/plugins/python_plugin

USER kong

ENV KONG_PLUGINS="bundled, my_plugin, python_plugin"

EXPOSE 8000 8443 8001 8444

CMD ["kong", "docker-start"]

the name of my embedded server is python_plugin, and to run everything I run the shell command: set KONG_DATABASE=postgres && docker-compose --profile database up --build
but when the command is executed, the previously mentioned error returns. Leaving aside my first plugin written in lua (working), my directory tree is as follows: /usr/local/ ├── bin/ │ └── kong-python-pluginserver # Script per avviare il server del plugin └── share/ └── lua/ └── 5.1/ └── kong/ └── plugins/ ├── python_plugin/ # Directory per il plugin Python │ └── prova_plugin.py # Codice del plugin Python └── my_plugin/ # Directory per altri plugin Lua personalizzati └── handler.lua and schema.lua # Codice del plugin Lua

finally, my kong.yaml is as follows: _format_version: "2.1" _transform: true What do I need to change? From the documentation provided, it appears that kong cannot find my python code, but although everything seems fine, it still doesn't work (https://support.konghq.com/support/s/article/plugin-is-enabled- but-not-installed)

Expected Behavior

No response

Steps To Reproduce

  1. download the images for docker: https://github.com/Kong/kong?tab=readme-ov-file
  2. modify the docker-compose.yml and create in the same directory dockerfile.kong
  3. add in the same directory as docker-compose.yml e dockerfile.kong kong-python-pdk (present in this link: https://github.com/Kong/kong-plugin-py-geocode/tree/main/kong-py-plugins )
  4. modify the tree of directory like me docker-compose-1 docker-compose-2 docker-compose-3 dockerfile-cong

Anything else?

No response

Smuggla commented 1 month ago

The plugin server is just an instance that runs your python. In your config it is python_plugin but also config'd a server named py. Two fixes are

KONG_PLUGINSERVER_NAMES: py
KONG_PLUGINSERVER_PY_START_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump
KONG_PLUGINSERVER_PY_QUERY_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump

or

KONG_PLUGINSERVER_NAMES: python_plugin
KONG_PLUGINSERVER_PYTHON_PLUGIN_START_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump
KONG_PLUGINSERVER_PYTHON_PLUGIN_QUERY_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump

Kong will get the plugin name when the pluginserver starts.

AlleMartins commented 1 month ago

After applying your change, therefore changing the name of the embedded server, with py, I get this error: "[error] init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/ process.lua:145: Not a plugin info table: kong-1 | /usr/local/bin/kong-python-pluginserver --plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin --dump" I will now attach the important codes of the project, and the logs error (the unspecified settings are like the previous ones said, in the previous commit) docker-compose-1 docker-compose-2 DockerFile-conf info_error plugin-python plugin-python2

AlleMartins commented 1 month ago

I also add on-board information which may be relevant: my version of kong is the community version, not the enterprise version, I also looked at this link, because it dealt with a similar problem but with the Go programming language: https://support. konghq.com/support/s/article/Golang-custom-plugin-throwing-not-a-plugin-info-table-and-error-loading-plugin-schemas-no-plugin-found, also I changed the name of the my python plugin from "prova_plugin.py" to "python_plugin.py"

fffonion commented 1 month ago

Use --dump-all-plugins instead of --dump if you are using embedded plugin server (i.e. not dedicated server).

AlleMartins commented 1 month ago

After I apply your change, this "info" appears, the image continues to run, but if I try to access the website (I created a small server with Flask) it doesn't work, so I assume it's an error. The image continues to work, in fact if I do: curl -i GET http://localhost:8001/plugins/enabled it is present, and if I try to activate it it works too error log

StarlightIbuki commented 2 weeks ago

Please ensure you have py-pdk correctly installed. pip3 install kong-pdk in case it's not installed.

github-actions[bot] commented 10 hours ago

This issue is marked as stale because it has been open for 14 days with no activity.