Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service field under a plugin should be ignored for nested routes #1353

Open
healthy-pod opened this issue Aug 3, 2024 · 2 comments
Open
Assignees

Comments

@healthy-pod
Copy link

If the value of service.routes[*].plugins[*].service is set to the same service in which the route is nested, applying the configuration returns an entity already exists error.

For example, consider the following configuration:

---
_format_version: "3.0"
services:
- name: koko-private
  host: koko-cp-ws.koko.svc.cluster.local
  port: 3200
  protocol: http
  routes:
  - name: koko-private-cp
    hosts:
    - 'us.kgateway.svc.konghq.${{ env "DECK_DOMAIN_TLD" }}'
    - 'eu.kgateway.svc.konghq.${{ env "DECK_DOMAIN_TLD" }}'
    snis:
    - 'us.kgateway.svc.konghq.${{ env "DECK_DOMAIN_TLD" }}'
    - 'eu.kgateway.svc.konghq.${{ env "DECK_DOMAIN_TLD" }}'
    paths:
    - ~/cp/(.*)/v1/outlet
    strip_path: false
    plugins:
    - name: request-transformer
      service: koko-private
      config:
        add:
          querystring:
          - cluster.prefix:$(uri_captures[1])
        replace:
          uri: "/v1/outlet"

Applying it succeeds first time, but fails second time with an entity already exists error. Deleting the plugin manually from the service then re-applying works, but still fails on the next apply with the same issue.

Options:

  1. Completely ignore service field in plugins under a route which is explicitly defined under a service
  2. Validate that the service field for the plugin matches the service name under which the route is nested, otherwise return a validation error
@mheap
Copy link
Member

mheap commented Aug 3, 2024

My expectation of behaviour would be:

  1. Error if a foreign key is set in a nested config (even if it matches). Fail fast.

Can you help us understand how you landed on this configuration?

@healthy-pod
Copy link
Author

Can you help us understand how you landed on this configuration?

[noob kong user here] while working on the config above I wanted to add a request-transformer plugin to a route nested within a service definition so I went to https://docs.konghq.com/hub/kong-inc/request-transformer/how-to/basic-example/ and copied the declarative example under Enable on a service which starts with:

- name: request-transformer
  service: SERVICE_NAME|ID

Prashansa-K added a commit to Kong/go-database-reconciler that referenced this issue Jan 6, 2025
As of now, while using deck to create a
route-scoped plugin with a `service` field
defined, the sync goes through the first
time but errors out subsequently. Under a
route, we do not want the user to add the
`service` field for a plugin. Thus, we are
checking for this specific scenario and
erroring out, instead of letting the sync
action go through.

For: Kong/deck#1353
Prashansa-K added a commit to Kong/go-database-reconciler that referenced this issue Jan 9, 2025
As of now, while using deck to create a
route-scoped plugin with a `service` field
defined, the sync goes through the first
time but errors out subsequently. Under a
route, we do not want the user to add the
`service` field for a plugin. Thus, we are
checking for this specific scenario and
erroring out, instead of letting the sync
action go through.

For: Kong/deck#1353
Prashansa-K added a commit to Kong/go-database-reconciler that referenced this issue Jan 13, 2025
* fix: returning a validation error in case of wrong configuration.

As of now, while using deck to create a
route-scoped plugin with a `service` field
defined, the sync goes through the first
time but errors out subsequently. Under a
route, we do not want the user to add the
`service` field for a plugin. Thus, we are
checking for this specific scenario and
erroring out, instead of letting the sync
action go through.

For: Kong/deck#1353

* fix: added checks for all conflicting nested configs in plugins.

A foreign key nested under a plugin of a different
scope would error out. This would make sure that a
sync does not go through when wrong configurations
are passed via deck. An example would be adding a
`service` field in a plugin, nested under a route.
This change ensures more such issues do not come up.

* test: added integration test for validations related to scoped plugins

* chore: removed redundant code lines

* chore: removed stray code lines from test

* test: fixed tests and added more for kong <3.0

* chore: addressed PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants