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

[Question] Are we able to override part of values in _plugin_configs? #772

Closed
yongzhang opened this issue Oct 14, 2022 · 6 comments
Closed

Comments

@yongzhang
Copy link

yongzhang commented Oct 14, 2022

Hi, team

I want to know if we can achieve the requirement like this with deck:

I have a shared plugin config custom-config with 4 args (a, b, c, d)

a, b, c have the same values for all services
but item d has different values for different services, see expected service configs like below:

_format_version: '3.0'

_plugin_configs:
  custom-config:
    a: value a
    b: value b
    c: value c
- host: a
  name: a
  port: 3000
  protocol: http
  routes:
  - hosts:
    - whatever
    name: a
    paths:
    - /api/v1
    plugins:
    - _config: custom-config
      config:
        d: item d value for a        < notice here
      enabled: true
      name: my plugin
    preserve_host: false
    strip_path: false    

- host: b
  name: b
  port: 3000
  protocol: http
  routes:
  - hosts:
    - whatever
    name: b
    paths:
    - /api/v2
    plugins:
    - _config: custom-config
      config:
        d: item d value for b        < notice here
      enabled: true
      name: my plugin
    preserve_host: false
    strip_path: false   

Are we able to do this?

@GGabriele
Copy link
Collaborator

Hi @yongzhang , thanks for the question!

Indeed you can overwrite specific config fields when using _plugin_config.

Let's say you have the following configuration: 2 rate-limiting configuration tiers (silver-tier-limit and gold-tier-limit) and a bunch of consumers belonging to the different tiers. More specifically, foo and bar are on silver tier while baz and fub on gold tier. Despite baz and fub share the same configuration, you decide to overwrite some configuration for fub because it's more special :) (setting minute: 50 instead of the gold value of 20)

$ cat kong.yaml
_format_version: "3.0"
_plugin_configs:
  silver-tier-limit:
    day: null
    fault_tolerant: true
    hide_client_headers: false
    hour: null
    limit_by: consumer
    minute: 14
    month: null
    policy: redis
    redis_database: 0
    redis_host: redis.common.svc
    redis_password: null
    redis_port: 6379
    redis_timeout: 2000
    second: null
    year: null
  gold-tier-limit:
    day: null
    fault_tolerant: true
    hide_client_headers: false
    hour: null
    limit_by: consumer
    minute: 20
    month: null
    policy: redis
    redis_database: 0
    redis_host: redis.common.svc
    redis_password: null
    redis_port: 6379
    redis_timeout: 2000
    second: null
    year: null
consumers:
- username: foo
  tags:
  - silver-tier
  plugins:
  - name: rate-limiting
    _config: silver-tier-limit
    enabled: true
    protocols:
    - http
    - https
- username: bar
  tags:
  - silver-tier
  plugins:
  - name: rate-limiting
    _config: silver-tier-limit
    enabled: true
    protocols:
    - http
    - https
- username: baz
  tags:
  - gold-tier
  plugins:
  - name: rate-limiting
    _config: gold-tier-limit
    enabled: true
    protocols:
    - http
    - https
- username: fub
  tags:
  - gold-tier
  plugins:
  - name: rate-limiting
    _config: gold-tier-limit
    config:
      minute: 50
    enabled: true
    protocols:
    - http
    - https
# sync the configuration
$ deck sync
creating consumer baz
creating consumer fub
creating consumer bar
creating consumer foo
creating plugin rate-limiting for consumer fub
creating plugin rate-limiting for consumer baz
creating plugin rate-limiting for consumer bar
creating plugin rate-limiting for consumer foo
Summary:
  Created: 8
  Updated: 0
  Deleted: 0
# verify the configuration

# silver tier
$  http :8001/consumers/foo/plugins |  jq ".data[0].config.minute"
14

# silver tier
$  http :8001/consumers/bar/plugins |  jq ".data[0].config.minute"
14

# gold tier
$ http :8001/consumers/baz/plugins |  jq ".data[0].config.minute"
20

# gold tier, but with the override
$ http :8001/consumers/fub/plugins |  jq ".data[0].config.minute"
50

@yongzhang
Copy link
Author

ohhhh, this is cool, looks like the feature is not documented.

@GGabriele
Copy link
Collaborator

Yeah we definitely need to improve the docs on this feature.

If you are interested, we are also working on adding support to plugins de-duplication also to dump: #581

@yongzhang
Copy link
Author

Yeah we definitely need to improve the docs on this feature.

If you are interested, we are also working on adding support to plugins de-duplication also to dump: #581

yea I saw this PR a few hours ago, that's super useful! can't wait it to be released!

@hbagdi
Copy link
Member

hbagdi commented Oct 26, 2022

@GGabriele Please open a documentation ticket to get this documented.

@JamesKeys
Copy link

Does this support the case below where I want to change one of the nested config values but leave the rest alone? I'm wondering if this will lead to timeout and exit_on_fail to be overridden to not exist. Not a huge deal here, but if I have 6 layers deep and want to add one value, is that possible here within the config?

_format_version: "3.0"
_plugin_configs:
  silver-tier-limit:
    fault_tolerant:
        timeout: 1000
        send_message: false
        exit_on_fail: true
    year: null

- username: foo
  tags:
  - silver-tier
  plugins:
  - name: rate-limiting
    _config: silver-tier-limit
    enabled: true
    protocols:
    - http
    - https
- username: bar
  tags:
  - silver-tier
  plugins:
  - name: rate-limiting
    _config: silver-tier-limit
    config:
        fault_tolerant:
            send_message: true
    enabled: true
    protocols:
    - http
    - https

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

4 participants