Plugin life-cycle hooks

I need to interact with external service (by HTTP API) upon plugin Add/Update/Delete events. I may do it within schema.lua, but IMO it is designed for validation, not for such tasks. Also it doesn’t work for Delete case.

Can anyone point me to right direction?

All what I can imagine is to add plugin API and call it after every plugin lifecycle events.


This does feel a bit like an XY problem. Would you mind taking a step back and explaining why do you need to do this? What is the problem you are actually trying to solve?

Maybe this is a correct solution, in which case we can guide you, but at least we would have learned more about your problem and if it it actually the best way to address it, and how we can make this easier in the future if the use-case seems common.

Thanks for the reply!

My plugin use external HTTP API, which has similar lifecycle events - register/update/remove.

Existing code just register itself from within schema/self_check function.

I prefer that plugin will be successfully added only if it in turn successfully registered with the API.
The same for update.
Upon plugin removal it should unregister.

I may add 3 plugins APIs and call it by client.
But using this way the client must do things which IMO should be encapsulated within plugin.

Hope I was clear enough.

Yes, the schema check function is only for validation purposes. You should not be doing http calls to an external service from it.

What should trigger the Add/Update/Delete events to your external API? Should it be traffic being proxied through Kong or should they happen when someone does direct calls to the admin API?

I prefer that plugin will be successfully added only if it in turn successfully registered with the API.
The same for update.

I don’t exactly understand what you mean on that phrase. Plugins can not be “added only in certain cases”. They are added when you make a POST request to /plugins. Most of them can be configured so that they are only triggered for a certain route, service or consumer. But once they are installed they are “added”.

Yes, I expect this. But it work perfectly in new code I work on now.

May be it not as Kong work now.
But may be it is a way for Kong to improve.

So it looks now there is no any plugin add/update/delete hooks where I may perform some complex actions and accept/reject plugin’s add/update.

I may do it by schema/self_check, but it looks like a hack.

For plugin Delete event I don’t even have a hack.

I will select between still using this schema/self_check hack or introduce some internal plugin states and add some API to manage this state.

The bad thing for this custom state is that I would need to deal with database layer.
Using current hack all what I need is saved within plugin’s config.