Skip to content

Commit 7f6ec07

Browse files
authored
feat: added partials to consumer-group plugins (#360)
* feat: added tls_sans property for service * tests: added unit and integration tests for services with tls_sans * tests: added dump tests for service tls sans * feat: added partials to consumer-group plugins * tests: added integration test for cg plugin with partial
1 parent d859d11 commit 7f6ec07

File tree

6 files changed

+114
-5
lines changed

6 files changed

+114
-5
lines changed

pkg/file/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ func (b *stateBuilder) ingestConsumerGroupScopedPlugins(cg FConsumerGroupObject)
254254
ConsumerGroup: &kong.ConsumerGroup{
255255
ID: cg.ID,
256256
},
257-
Tags: plugin.Tags,
257+
Partials: plugin.Partials,
258+
Tags: plugin.Tags,
258259
},
259260
ConfigSource: plugin.ConfigSource,
260261
})

pkg/file/kong_json_schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@
390390
"type": "string"
391391
},
392392
"type": "array"
393+
},
394+
"partials": {
395+
"items": {
396+
"type": "object"
397+
},
398+
"type": "array"
393399
}
394400
},
395401
"additionalProperties": false,

pkg/file/writer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,11 @@ func populateConsumerGroups(kongState *state.KongState, file *Content,
878878
utils.ZeroOutID(plugin, plugin.Name, config.WithID)
879879
utils.ZeroOutID(plugin.ConsumerGroup, plugin.ConsumerGroup.Name, config.WithID)
880880
group.Plugins = append(group.Plugins, &kong.ConsumerGroupPlugin{
881-
ID: plugin.ID,
882-
Name: plugin.Name,
883-
Config: plugin.Config,
884-
Tags: plugin.Tags,
881+
ID: plugin.ID,
882+
Name: plugin.Name,
883+
Config: plugin.Config,
884+
Tags: plugin.Tags,
885+
Partials: plugin.Partials,
885886
})
886887
}
887888
}

pkg/state/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func buildKong(kongState *KongState, raw *utils.KongRawState) error {
138138
Config: p.Config,
139139
ConsumerGroup: cg.ConsumerGroup,
140140
ConfigSource: p.ConfigSource,
141+
Partials: p.Partials,
141142
Tags: p.Tags,
142143
},
143144
},

tests/integration/sync_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8588,6 +8588,49 @@ func Test_Sync_Partials_Plugins(t *testing.T) {
85888588
require.Error(t, err)
85898589
assert.ErrorContains(t, err, "partial for plugin rate-limiting-advanced: missing required fields - name or id")
85908590
})
8591+
8592+
t.Run("partial linking with a consumer-group scoped plugin works fine", func(t *testing.T) {
8593+
mustResetKongState(ctx, t, client, dumpConfig)
8594+
currentState, err := fetchCurrentState(ctx, client, dumpConfig)
8595+
require.NoError(t, err)
8596+
8597+
targetState := stateFromFile(ctx, t, "testdata/sync/038-partials/cg-plugin-partial.yaml", client, dumpConfig)
8598+
syncer, err := deckDiff.NewSyncer(deckDiff.SyncerOpts{
8599+
CurrentState: currentState,
8600+
TargetState: targetState,
8601+
8602+
KongClient: client,
8603+
})
8604+
require.NoError(t, err)
8605+
8606+
stats, errs, changes := syncer.Solve(ctx, 1, false, true)
8607+
require.Empty(t, errs, "Should have no errors in syncing")
8608+
logEntityChanges(t, stats, changes)
8609+
8610+
newState, err := fetchCurrentState(ctx, client, dumpConfig)
8611+
require.NoError(t, err)
8612+
8613+
// check for partial
8614+
partials, err := newState.Partials.GetAll()
8615+
require.NoError(t, err)
8616+
require.NotNil(t, partials)
8617+
8618+
require.Len(t, partials, 1)
8619+
assert.Equal(t, "my-redis-ee", *partials[0].Name)
8620+
assert.Equal(t, "redis-ee", *partials[0].Type)
8621+
8622+
// check for plugin
8623+
plugins, err := newState.Plugins.GetAll()
8624+
require.NoError(t, err)
8625+
require.NotNil(t, plugins)
8626+
require.Len(t, plugins, 1)
8627+
assert.Equal(t, "rate-limiting-advanced", *plugins[0].Name)
8628+
assert.IsType(t, []*kong.PartialLink{}, plugins[0].Partials)
8629+
require.Len(t, plugins[0].Partials, 1)
8630+
assert.Equal(t, *partials[0].ID, *plugins[0].Partials[0].ID)
8631+
assert.Equal(t, "config.redis", *plugins[0].Partials[0].Path)
8632+
assert.Equal(t, "foo", *plugins[0].ConsumerGroup.Name)
8633+
})
85918634
}
85928635

85938636
func Test_Sync_Partials(t *testing.T) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
_format_version: "3.0"
2+
consumer_groups:
3+
- name: foo
4+
plugins:
5+
- config:
6+
compound_identifier: null
7+
consumer_groups: null
8+
dictionary_name: kong_rate_limiting_counters
9+
disable_penalty: false
10+
enforce_consumer_groups: false
11+
error_code: 429
12+
error_message: API rate limit exceeded
13+
header_name: null
14+
hide_client_headers: false
15+
identifier: consumer
16+
limit:
17+
- 10
18+
lock_dictionary_name: kong_locks
19+
namespace: w8YrKXnDFXNJGynDdUhmeyrZWa7p5B2P
20+
path: null
21+
retry_after_jitter_max: 0
22+
strategy: redis
23+
sync_rate: -1
24+
window_size:
25+
- 60
26+
window_type: sliding
27+
name: rate-limiting-advanced
28+
partials:
29+
- id: c252219a-ace0-4f35-9dc7-156ef259981f
30+
name: my-redis-ee
31+
path: config.redis
32+
partials:
33+
- config:
34+
cluster_max_redirections: null
35+
cluster_nodes: null
36+
connect_timeout: 2000
37+
connection_is_proxied: false
38+
database: 0
39+
host: 127.0.0.1
40+
keepalive_backlog: 0
41+
keepalive_pool_size: 256
42+
password: null
43+
port: 6000
44+
read_timeout: 2000
45+
send_timeout: 2000
46+
sentinel_master: null
47+
sentinel_nodes: null
48+
sentinel_password: null
49+
sentinel_role: null
50+
sentinel_username: null
51+
server_name: null
52+
ssl: false
53+
ssl_verify: false
54+
username: null
55+
id: c252219a-ace0-4f35-9dc7-156ef259981f
56+
name: my-redis-ee
57+
type: redis-ee

0 commit comments

Comments
 (0)