deck gateway sync triggers "UNIQUE violation..." error on certain changes for Plugins config
- Dominant language
- Go
- Stars
- 503
- Forks
- 137
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 20
Description
Hello! I've run into this issue where specific changes to a Plugins configuration throws the error `decK sync stderr: Error: 1 errors occurred:
while processing event: Create plugin {plugin name} for route {route name} failed: HTTP status 409 (message: "UNIQUE violation detected on '{instance_name=\"sandbox-test-plugin\"}'")`
This seems like a bug but perhaps I'm missing an extra flag when running the sync, or something is wrong with the yaml?
#### Version and Syncing
Using Kong Deck 1.55.0-linux.
Kong Gateway version 3.10.0.3.
To sync I'm running `deck gateway sync {my yaml file} --headers {my auth header}`
#### Expected Result
Since I am changing the configuration for a plugin that's in a yaml with my route and service settings all using the same `select_tags` I expect it to succeed and update the items (specifically the Plugin).
#### Result Error
Changing some settings causes the `deck gateway sync` to fail with the following error:
`decK sync stderr: Error: 1 errors occurred:
while processing event: Create plugin {plugin name} for route {route name} failed: HTTP status 409 (message: "UNIQUE violation detected on '{instance_name=\"sandbox-test-plugin\"}'")`
#### Reproduce This Error
I've provided the full .yaml I'm testing with at the bottom of this issue.
Seems like the error only occurs when changing certain settings. I've seen it happen when changing the `route` and `service` settings for a plugin.
1. Run a Kong `deck gateway sync` for the yaml below to create it all.
2. Then change anything other than the `route` or `service` setting for the plugin. For my example I'll change `uri: /sandbox-example/endpoint/foobar` to `uri: /sandbox-example/endpoint`
3. Run `deck gateway sync` after the above change. This will succeed as expected, and we'll see the updated `uri:` setting for that plugin instance reflected in the sync output log, and on Kong Dashboard itself.
4. Now, change the `route` that the plugin is applied to. `route: devtools-sandbox-route-a` gets changed to `route: devtools-sandbox-route-b`.
5. Run `deck gateway sync` again. In this case I expect it to gracefully update the plugin in place, changing the route it's attached to but it throws the same error mentioned before in this issue.
#### Workarounds
One fix I've found is to just delete the existing Plugin instance on the Kong dashboard manually, then run the `deck gateway sync` which will then succeed.
The second is to rename the Plugins `instance_name` when changing the route or service on it. For example, if you followed the steps above, but then for step 4 **also** change the Plugins instance name to anything else it'll succeed. It deletes the old instance and then creates the new.
#### Yaml Example
```
_format_version: "3.0"
_workspace: kong_workspace_here
_info:
select_tags:
- devtools-sandbox
services:
- name: devtools-sandbox-service
host: devtools-sandbox.kong-dev.svc.cluster.local
enabled: true
path: /
port: 8080
protocol: http
read_timeout: 60000
retries: 5
write_timeout: 60000
tags: &tags
- sandbox
- dev
- dev-sandbox
routes:
- name: devtools-sandbox-route-a
hosts: &hosts
- kong.host.sandbox
https_redirect_status_code: 426
path_handling: v0
paths:
- /site/sandbox/route/a
methods:
- GET
preserve_host: false
protocols:
- https
regex_priority: 100
request_buffering: true
response_buffering: true
strip_path: true
tags: *tags
- name: devtools-sandbox-route-b
hosts: *hosts
https_redirect_status_code: 426
path_handling: v0
paths:
- /site/sandbox/route/b
methods:
- GET
preserve_host: false
protocols:
- https
regex_priority: 100
request_buffering: true
response_buffering: true
strip_path: true
tags: *tags
plugins:
- name: request-transformer-advanced
instance_name: sandbox-test-plugin-02
route: devtools-sandbox-route-a
config:
dots_in_keys: false
replace:
uri: /sandbox-example/endpoint/foobar
tags: *tags
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the `deck gateway sync` command and reproduce the issue using the YAML example, changing a plugin's route or service while keeping its `instance_name`. Trace how decK processes the plugin update through Kong Gateway and verify that the change completes without a UNIQUE violation or manual deletion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100