Question
What's the proper way (if there is one) to update an already existing Kong custom plugin? And what about uninstalling it?
Details
I've been struggling a bit while trying to test and debug my Kong custom plugins.
The documentation provides a section "Deploying custom plugins" that explains how to install the custom plugin, while installing Kong, so that it can be used later on.
Given that I already installed Kong, I tried using helm upgrade
, instead of helm install
, to update the values. This way I was able to use the plugin the first time:
- I sent a request to a route using the plugin:
curl -i localhost/foobar/test/custom/myheader[...]
- The gateway logs showed the following entry:
2023/11/28 09:11:24 [notice] 1262#0: *392 [kong] handler.lua:8 [myheader] "LOG: test", client: X.X.0.1, server: kong, request: "GET /foobar/test/custom/myheader HTTP/1.1", host: "localhost"X.X.0.1 - - [28/Nov/2023:09:11:24 +0000] "GET /foobar/test/custom/myheader HTTP/1.1" 200 17 "-" "curl/8.2.1"
However, it seems like I cannot change them a second time:
- I deleted the ConfigMap
kong-plugin-myheader
; - I deleted the KongPlugin
my-custom-plugin
; - I upgraded helm with an empty
values.yaml
; - I created a new ConfigMap
kong-plugin-myheader
with the new code (see below "after"); - I created a new KongPlugin
my-custom-plugin
; - I sent another request, but still see the same log message (therefore I'm guessing the custom plugin was not updated).
To effectively see the changes, I have to uninstall and reinstall Kong entirely. Isn't there a better/quicker approach?
Resources
Custom Plugin "myheader"
File Structure
myheader/myheader/handler.luamyheader/schema.lua
File handler.lua
before
local MyHeader = {}MyHeader.PRIORITY = 1000MyHeader.VERSION = "1.0.0"function MyHeader:header_filter(conf) -- test kong.log('"LOG: test"')endreturn MyHeader
File handler.lua
after
local MyHeader = {}MyHeader.PRIORITY = 1000MyHeader.VERSION = "1.0.0"function MyHeader:header_filter(conf) -- test kong.log('"LOG: test NEW"')endreturn MyHeader
File schema.lua
return { name = "myheader", fields = { { config = { type = "record", fields = { { header_value = { type = "string", default = "roar", }, }, }, }, }, }}
File values.yaml
gateway: plugins: configMaps: - name: kong-plugin-myheader pluginName: myheader
KongPlugin my-custom-plugin
apiVersion: configuration.konghq.com/v1kind: KongPluginmetadata: name: my-custom-pluginconfig: header_value: "my first plugin"plugin: myheader
Service foobar
# DeploymentapiVersion: apps/v1kind: Deploymentmetadata: labels: app: foobar name: foobar[...]---# ServiceapiVersion: v1kind: Servicemetadata: labels: app: foobar-service name: foobar-servicespec: [...] selector: app: foobar # referencing metadata.labels.app (set of key-value)---# Route /foobar/test/custom/myheaderapiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: foobar-route-test-custom-myheader annotations: konghq.com/strip-path: 'true' konghq.com/plugins: 'my-custom-plugin'spec: parentRefs: - name: kong rules: - matches: - path: type: PathPrefix value: /foobar/test/custom/myheader backendRefs: - name: foobar-service kind: Service port: 3000