diff --git a/go.mod b/go.mod index cd88fe5..571ca63 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.5 github.com/hexops/gotextdiff v1.0.3 github.com/kong/deck v1.32.0 - github.com/kong/go-kong v0.51.0 + github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7 github.com/shirou/gopsutil/v3 v3.23.12 github.com/ssgelm/cookiejarparser v1.0.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index de4ccd8..9f92281 100644 --- a/go.sum +++ b/go.sum @@ -186,8 +186,8 @@ github.com/kong/deck v1.32.0 h1:ujLpVoBGToXxLiDOaFWrutUIUCLxm1oSJU4EX1CFWJE= github.com/kong/deck v1.32.0/go.mod h1:ptH2oAsaczpcxUs0npmDL6RCER6vleFBII9Kc3rSFZ8= github.com/kong/go-apiops v0.1.29 h1:c+AB8MmGIr+K01Afm4GB2xaOmJnD/8KWMJQkr9qssnc= github.com/kong/go-apiops v0.1.29/go.mod h1:ZNdiTZyVrAssB4wjEYWV7BfpcV9UME9LxnDDZhMPuNU= -github.com/kong/go-kong v0.51.0 h1:KuSvo+b265KuFGOkkdYONGtG6ci8WLomJ/5Xhs0XSHE= -github.com/kong/go-kong v0.51.0/go.mod h1:JdLpEwKi/Usq2TCTEtIS4f6ADWN7sdDMSS1PvvD1Ldw= +github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7 h1:/iV93Gwv410lIeJx8VCfCA4fpuvSuTw2LqZpDXsIE9Q= +github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7/go.mod h1:YNkLvjxfOqS+BZ1J2YWOy/83wc26JM5QJbAukoeg1sY= github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY= github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw= github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y= diff --git a/pkg/file/builder.go b/pkg/file/builder.go index bce525c..a725569 100644 --- a/pkg/file/builder.go +++ b/pkg/file/builder.go @@ -117,6 +117,7 @@ func (b *stateBuilder) ingestConsumerGroupScopedPlugins(cg FConsumerGroupObject) ID: cg.ID, }, }, + ConfigSource: plugin.ConfigSource, }) } return b.ingestPlugins(plugins) diff --git a/pkg/file/kong_json_schema.json b/pkg/file/kong_json_schema.json index 13fa79c..3e1bdca 100644 --- a/pkg/file/kong_json_schema.json +++ b/pkg/file/kong_json_schema.json @@ -333,6 +333,9 @@ }, "ConsumerGroupPlugin": { "properties": { + "_config": { + "type": "string" + }, "config": { "additionalProperties": true, "type": "object" diff --git a/pkg/state/builder.go b/pkg/state/builder.go index 7e76515..458d511 100644 --- a/pkg/state/builder.go +++ b/pkg/state/builder.go @@ -124,6 +124,7 @@ func buildKong(kongState *KongState, raw *utils.KongRawState) error { Name: p.Name, Config: p.Config, ConsumerGroup: cg.ConsumerGroup, + ConfigSource: p.ConfigSource, }, }, ) diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 669c4c8..7412bdc 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -4932,3 +4932,150 @@ func Test_Sync_PluginScopedToConsumerGroupAndRoute(t *testing.T) { testKongState(t, client, false, expectedState, nil) } + +// test scope: +// - 3.5.0+ +// - konnect +func Test_Sync_DeDupPluginsScopedToConsumerGroups(t *testing.T) { + t.Setenv("DECK_KONNECT_CONTROL_PLANE_NAME", "default") + runWhenEnterpriseOrKonnect(t, ">=3.5.0") + setup(t) + + client, err := getTestClient() + if err != nil { + t.Fatalf(err.Error()) + } + + expectedState := utils.KongRawState{ + ConsumerGroups: []*kong.ConsumerGroupObject{ + { + ConsumerGroup: &kong.ConsumerGroup{ + ID: kong.String("19275493-84d3-4c64-92e6-612e908a3a4f"), + Name: kong.String("gold"), + }, + Consumers: []*kong.Consumer{ + { + ID: kong.String("7b2c743c-2cec-4998-b9df-e7f8a9a20487"), + Username: kong.String("jeff"), + }, + }, + }, + { + ConsumerGroup: &kong.ConsumerGroup{ + ID: kong.String("48df7cd3-1cd0-4e53-af73-8f57f257be18"), + Name: kong.String("silver"), + }, + }, + }, + Consumers: []*kong.Consumer{ + { + ID: kong.String("7b2c743c-2cec-4998-b9df-e7f8a9a20487"), + Username: kong.String("jeff"), + }, + }, + Plugins: []*kong.Plugin{ + { + ID: kong.String("1c93dd1f-f188-473d-bec8-053bd526a693"), + Name: kong.String("rate-limiting-advanced"), + ConsumerGroup: &kong.ConsumerGroup{ + ID: kong.String("19275493-84d3-4c64-92e6-612e908a3a4f"), + }, + Config: kong.Configuration{ + "consumer_groups": nil, + "dictionary_name": string("kong_rate_limiting_counters"), + "disable_penalty": bool(false), + "enforce_consumer_groups": bool(false), + "error_code": float64(429), + "error_message": string("API rate limit exceeded"), + "header_name": nil, + "hide_client_headers": bool(false), + "identifier": string("consumer"), + "limit": []any{float64(1000)}, + "namespace": string("OsFDaDQxdb1MFGHBdZENho51f3zqMLy"), + "path": nil, + "redis": map[string]any{ + "cluster_addresses": nil, + "connect_timeout": nil, + "database": float64(0), + "host": nil, + "keepalive_backlog": nil, + "keepalive_pool_size": float64(256), + "password": nil, + "port": nil, + "read_timeout": nil, + "send_timeout": nil, + "sentinel_addresses": nil, + "sentinel_master": nil, + "sentinel_password": nil, + "sentinel_role": nil, + "sentinel_username": nil, + "server_name": nil, + "ssl": false, + "ssl_verify": false, + "timeout": float64(2000), + "username": nil, + }, + "retry_after_jitter_max": float64(0), + "strategy": string("local"), + "sync_rate": float64(-1), + "window_size": []any{float64(60)}, + "window_type": string("sliding"), + }, + Enabled: kong.Bool(true), + Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")}, + }, + { + ID: kong.String("bcb296c3-22bb-46f6-99c8-4828af750b77"), + Name: kong.String("rate-limiting-advanced"), + ConsumerGroup: &kong.ConsumerGroup{ + ID: kong.String("48df7cd3-1cd0-4e53-af73-8f57f257be18"), + }, + Config: kong.Configuration{ + "consumer_groups": nil, + "dictionary_name": string("kong_rate_limiting_counters"), + "disable_penalty": bool(false), + "enforce_consumer_groups": bool(false), + "error_code": float64(429), + "error_message": string("API rate limit exceeded"), + "header_name": nil, + "hide_client_headers": bool(false), + "identifier": string("consumer"), + "limit": []any{float64(100)}, + "namespace": string("OsFDaDQxdb1MFGHBdZENho51f3zqMLy"), + "path": nil, + "redis": map[string]any{ + "cluster_addresses": nil, + "connect_timeout": nil, + "database": float64(0), + "host": nil, + "keepalive_backlog": nil, + "keepalive_pool_size": float64(256), + "password": nil, + "port": nil, + "read_timeout": nil, + "send_timeout": nil, + "sentinel_addresses": nil, + "sentinel_master": nil, + "sentinel_password": nil, + "sentinel_role": nil, + "sentinel_username": nil, + "server_name": nil, + "ssl": false, + "ssl_verify": false, + "timeout": float64(2000), + "username": nil, + }, + "retry_after_jitter_max": float64(0), + "strategy": string("local"), + "sync_rate": float64(-1), + "window_size": []any{float64(60)}, + "window_type": string("sliding"), + }, + Enabled: kong.Bool(true), + Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")}, + }, + }, + } + require.NoError(t, sync("testdata/sync/030-plugin-dedup-consumer-groups/kong.yaml")) + testKongState(t, client, false, expectedState, nil) +} diff --git a/tests/integration/testdata/sync/030-plugin-dedup-consumer-groups/kong.yaml b/tests/integration/testdata/sync/030-plugin-dedup-consumer-groups/kong.yaml new file mode 100644 index 0000000..0481672 --- /dev/null +++ b/tests/integration/testdata/sync/030-plugin-dedup-consumer-groups/kong.yaml @@ -0,0 +1,41 @@ +_format_version: "3.0" +_plugin_configs: + route-default-limit: + hide_client_headers: false + identifier: consumer + limit: + - 100 + strategy: local + sync_rate: -1 + window_size: + - 60 + namespace: OsFDaDQxdb1MFGHBdZENho51f3zqMLy + gold-tier-limit: + hide_client_headers: false + identifier: consumer + limit: + - 1000 + strategy: local + sync_rate: -1 + window_size: + - 60 + namespace: OsFDaDQxdb1MFGHBdZENho51f3zqMLy +consumer_groups: +- id: 19275493-84d3-4c64-92e6-612e908a3a4f + name: gold + plugins: + - id: 1c93dd1f-f188-473d-bec8-053bd526a693 + name: rate-limiting-advanced + _config: gold-tier-limit +- id: 48df7cd3-1cd0-4e53-af73-8f57f257be18 + name: silver + plugins: + - id: bcb296c3-22bb-46f6-99c8-4828af750b77 + name: rate-limiting-advanced + _config: route-default-limit +consumers: +- groups: + - id: 19275493-84d3-4c64-92e6-612e908a3a4f + name: gold + id: 7b2c743c-2cec-4998-b9df-e7f8a9a20487 + username: jeff \ No newline at end of file