Kong / go-pdk

Write Kong plugins in Go! 🦍
https://pkg.go.dev/github.com/Kong/go-pdk
Apache License 2.0
144 stars 48 forks source link

Question: How to reload plugin configuration? #198

Closed sebbonnet closed 2 months ago

sebbonnet commented 2 months ago

Hi,

I’m writing a custom go plugin to validate scopes in JWT. The plugin takes the “allowed scopes” for a given path as plugin configuration. Although the plugin configuration is loaded correctly the first time, subsequent updates to the config are not picked up. Is there a way to rollout config changes or somehow send a signal to the plugin to reload its config?

Besides deleting the KongPlugin configuration CR has no effect either, so it does seem that the plugin configuration is cached for the duration of the plugin server at least. In fact looking at instance.go, there is a comment suggesting here that a new instance should be started in case of plugin config changes and the old one stopped. Are there any examples/guides on how to do that? How can I retrieve the current instance status to stop the old instance and how to generate a new instance status to start a new one?

I posted this question in the discuss.konghq.com too, but realise this might be more sensible to have it here instead.

I'm using kong docker image 3.6.0-ubuntu and go-pdk v0.11.0 Here is what the custom plugin configuration looks like.

apiVersion: [configuration.konghq.com/v1](http://configuration.konghq.com/v1)
config:
jwksUri: https://some-url/certs
protectedPaths:
- allowedScopes:
- tenant-two-scope
path: /ip
kind: KongPlugin
metadata:
name: hello-oauth2
namespace: kong-tenant-two
plugin: mygoplugin

Many thanks

gszr commented 2 months ago

Answered in https://discuss.konghq.com/t/how-to-reload-custom-go-plugin-configuration/12582/5. Closing this to avoid duplication.

gszr commented 2 months ago

For reference, the fix for this issue is https://github.com/Kong/kong/pull/12729