Skip to content

Commit adba5f4

Browse files
authored
fix: fixed foreign key reference under plugin config (#1597)
* fix: fixed foreign key reference under plugin config This change updates gdr version to v1.22.4 Here, we have relaxed the restrictions added in an earlier deck version to error out in case of foreign keys under a plugin config. Now, errors come up only if same type of entity is nested under an entity. This change has also fixed the resolution of foreign keys in case names are used, instead of IDs. * chore: fixed runWhen condition in test
1 parent 8afa848 commit adba5f4

21 files changed

+743
-8
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
github.com/fatih/color v1.18.0
1414
github.com/google/go-cmp v0.7.0
1515
github.com/kong/go-apiops v0.1.41
16-
github.com/kong/go-database-reconciler v1.22.3
17-
github.com/kong/go-kong v0.65.0
16+
github.com/kong/go-database-reconciler v1.22.4
17+
github.com/kong/go-kong v0.65.1
1818
github.com/mitchellh/go-homedir v1.1.0
1919
github.com/spf13/cobra v1.8.1
2020
github.com/spf13/pflag v1.0.6

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/q
246246
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
247247
github.com/kong/go-apiops v0.1.41 h1:1KXbQqyhO2E4nEnXJNqUDmHZU/LQ1U7Zoi+MAlcM2P0=
248248
github.com/kong/go-apiops v0.1.41/go.mod h1:sATq9Tz+ivzHKZU+tDXkRtEZnf64xroU3lgv3yXqP4I=
249-
github.com/kong/go-database-reconciler v1.22.3 h1:H7austovtuMGWnRgpP8pQPAJXknSCnTHgwRyO6ilWJg=
250-
github.com/kong/go-database-reconciler v1.22.3/go.mod h1:Jlo4eEe0/PHd2dIkWTH9tFfShydRwRxY09dZvKZBelU=
251-
github.com/kong/go-kong v0.65.0 h1:dZT+hiMhy7CQsrc9W5nHv3cFJGBGTrwlZhC5MLuf9H8=
252-
github.com/kong/go-kong v0.65.0/go.mod h1:sqdysTKrXIJ6mpxHwTwjgZhLW7jR1/puczTXHLUwJaE=
249+
github.com/kong/go-database-reconciler v1.22.4 h1:wTDmlDe1UdZrxjXN4D148HJ8cPkUJVjEk2EAgUwWAAY=
250+
github.com/kong/go-database-reconciler v1.22.4/go.mod h1:Usj3Eaj7H9WN2b5DQgaJQfg1mcbI0hBIY7fWc353jNg=
251+
github.com/kong/go-kong v0.65.1 h1:CM+8NlF+VbJckTxP2hGmSPKhA1GMliitXjQ7vJiPkaE=
252+
github.com/kong/go-kong v0.65.1/go.mod h1:sqdysTKrXIJ6mpxHwTwjgZhLW7jR1/puczTXHLUwJaE=
253253
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
254254
github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw=
255255
github.com/kong/kubernetes-configuration v1.1.0 h1:zCj7QlOiZgwQ2wSNlVNR0K6Z+plXTalfihtDzLXQWzs=

tests/integration/sync_test.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8333,3 +8333,146 @@ func Test_Sync_Avoid_Consumer_Group_Overwrite_On_Select_Tag_Mismatch_With_ID_Ent
83338333
})
83348334
}
83358335
}
8336+
8337+
// test scope:
8338+
//
8339+
// - >=2.8.0 <3.0.0
8340+
func Test_Sync_Plugins_Nested_Foreign_Keys(t *testing.T) {
8341+
runWhen(t, "kong", ">=2.8.0 <3.0.0")
8342+
setup(t)
8343+
8344+
ctx := context.Background()
8345+
8346+
tests := []struct {
8347+
name string
8348+
stateFile string
8349+
}{
8350+
{
8351+
name: "plugins with consumer reference - via name",
8352+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-consumers-via-names.yaml",
8353+
},
8354+
{
8355+
name: "plugins with consumer reference - via id",
8356+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-consumers-via-ids.yaml",
8357+
},
8358+
{
8359+
name: "plugins with route reference - via name",
8360+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-routes-via-names.yaml",
8361+
},
8362+
{
8363+
name: "plugins with route reference - via id",
8364+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-routes-via-ids.yaml",
8365+
},
8366+
{
8367+
name: "plugins with service reference - via name",
8368+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-services-via-ids.yaml",
8369+
},
8370+
{
8371+
name: "plugins with service reference - via id",
8372+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/1_1/kong-services-via-ids.yaml",
8373+
},
8374+
}
8375+
8376+
for _, tc := range tests {
8377+
t.Run(tc.name, func(t *testing.T) {
8378+
reset(t)
8379+
err := sync(ctx, tc.stateFile)
8380+
require.NoError(t, err)
8381+
8382+
// re-sync with no error
8383+
err = sync(ctx, tc.stateFile)
8384+
require.NoError(t, err)
8385+
})
8386+
}
8387+
}
8388+
8389+
// test scope:
8390+
//
8391+
// - >=3.0.0
8392+
// - konnect
8393+
func Test_Sync_Plugins_Nested_Foreign_Keys_3x(t *testing.T) {
8394+
runWhenKongOrKonnect(t, ">=3.0.0")
8395+
setup(t)
8396+
8397+
ctx := context.Background()
8398+
8399+
tests := []struct {
8400+
name string
8401+
stateFile string
8402+
}{
8403+
{
8404+
name: "plugins with consumer reference - via name",
8405+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-consumers-via-names.yaml",
8406+
},
8407+
{
8408+
name: "plugins with consumer reference - via id",
8409+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-consumers-via-ids.yaml",
8410+
},
8411+
{
8412+
name: "plugins with route reference - via name",
8413+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-routes-via-names.yaml",
8414+
},
8415+
{
8416+
name: "plugins with route reference - via id",
8417+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-routes-via-ids.yaml",
8418+
},
8419+
{
8420+
name: "plugins with service reference - via name",
8421+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-services-via-ids.yaml",
8422+
},
8423+
{
8424+
name: "plugins with service reference - via id",
8425+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-services-via-ids.yaml",
8426+
},
8427+
}
8428+
8429+
for _, tc := range tests {
8430+
t.Run(tc.name, func(t *testing.T) {
8431+
reset(t)
8432+
err := sync(ctx, tc.stateFile)
8433+
require.NoError(t, err)
8434+
8435+
// re-sync with no error
8436+
err = sync(ctx, tc.stateFile)
8437+
require.NoError(t, err)
8438+
})
8439+
}
8440+
}
8441+
8442+
// test scope:
8443+
//
8444+
// - >=3.0.0+enterprise
8445+
// - konnect
8446+
func Test_Sync_Plugins_Nested_Foreign_Keys_EE_3x(t *testing.T) {
8447+
// prior versions don't support a consumer_group foreign key with a value
8448+
runWhenEnterpriseOrKonnect(t, ">=3.6.0")
8449+
setup(t)
8450+
8451+
ctx := context.Background()
8452+
8453+
tests := []struct {
8454+
name string
8455+
stateFile string
8456+
}{
8457+
{
8458+
name: "plugins with consumer-group reference - via name",
8459+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-consumer-groups-via-names.yaml",
8460+
},
8461+
{
8462+
name: "plugins with consumer-group reference - via id",
8463+
stateFile: "testdata/sync/041-plugins-nested-foreign-keys/kong3x-consumer-groups-via-ids.yaml",
8464+
},
8465+
}
8466+
8467+
for _, tc := range tests {
8468+
t.Run(tc.name, func(t *testing.T) {
8469+
reset(t)
8470+
err := sync(ctx, tc.stateFile)
8471+
require.NoError(t, err)
8472+
8473+
// re-sync with no error
8474+
err = sync(ctx, tc.stateFile)
8475+
require.NoError(t, err)
8476+
})
8477+
}
8478+
}

tests/integration/testdata/diff/004-no-diff-plugin/protocol-initial-order-plugins.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ services:
1313
- grpc
1414
- https
1515
- name: prometheus
16-
service: mockbin
1716
tags:
1817
- o11y
1918
config:

tests/integration/testdata/diff/004-no-diff-plugin/protocol-reordered-plugins.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ services:
1313
- https
1414
- grpc
1515
- name: prometheus
16-
service: mockbin
1716
tags:
1817
- o11y
1918
config:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
_format_version: "1.1"
2+
3+
consumer_groups:
4+
- name: group-1
5+
id: 8ca63651-4068-4baa-b2b9-08dc99c296e0
6+
- name: group-2
7+
id: 8ca63651-4068-4baa-b2b9-08dc99c29666
8+
9+
services:
10+
- name: example-service
11+
port: 3200
12+
protocol: http
13+
host: localhost
14+
routes:
15+
- name: example-route-1
16+
paths:
17+
- /r1
18+
plugins:
19+
- config:
20+
limit_by: consumer
21+
minute: 6
22+
policy: local
23+
consumer_group: 8ca63651-4068-4baa-b2b9-08dc99c296e0 # group-1's id
24+
enabled: true
25+
name: rate-limiting
26+
protocols:
27+
- http
28+
29+
routes:
30+
- name: example-route-2
31+
paths:
32+
- /r2
33+
service:
34+
name: example-service
35+
plugins:
36+
- config:
37+
limit_by: consumer
38+
minute: 6
39+
policy: local
40+
consumer_group: 8ca63651-4068-4baa-b2b9-08dc99c29666 # group-2's id
41+
enabled: true
42+
name: rate-limiting
43+
protocols:
44+
- http
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
_format_version: "1.1"
2+
3+
consumer_groups:
4+
- name: group-1
5+
id: 8ca63651-4068-4baa-b2b9-08dc99c296e0
6+
- name: group-2
7+
id: 8ca63651-4068-4baa-b2b9-08dc99c29666
8+
9+
services:
10+
- name: example-service
11+
port: 3200
12+
protocol: http
13+
host: localhost
14+
routes:
15+
- name: example-route-1
16+
paths:
17+
- /r1
18+
plugins:
19+
- config:
20+
limit_by: consumer
21+
minute: 6
22+
policy: local
23+
consumer_group: group-1
24+
enabled: true
25+
name: rate-limiting
26+
protocols:
27+
- http
28+
29+
routes:
30+
- name: example-route-2
31+
paths:
32+
- /r2
33+
service:
34+
name: example-service
35+
plugins:
36+
- config:
37+
limit_by: consumer
38+
minute: 6
39+
policy: local
40+
consumer_group: group-2
41+
enabled: true
42+
name: rate-limiting
43+
protocols:
44+
- http
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
_format_version: "1.1"
2+
3+
consumers:
4+
- username: alice
5+
id: 8ca63651-4068-4baa-b2b9-08dc99c296e0
6+
- username: bob
7+
id: 8ca63651-4068-4baa-b2b9-08dc99c29666
8+
9+
services:
10+
- name: example-service
11+
port: 3200
12+
protocol: http
13+
host: localhost
14+
routes:
15+
- name: example-route-1
16+
paths:
17+
- /r1
18+
plugins:
19+
- config:
20+
limit_by: consumer
21+
minute: 6
22+
policy: local
23+
consumer: 8ca63651-4068-4baa-b2b9-08dc99c296e0 # alice's id
24+
enabled: true
25+
name: rate-limiting
26+
protocols:
27+
- http
28+
29+
routes:
30+
- name: example-route-2
31+
paths:
32+
- /r2
33+
service:
34+
name: example-service
35+
plugins:
36+
- config:
37+
limit_by: consumer
38+
minute: 6
39+
policy: local
40+
consumer: 8ca63651-4068-4baa-b2b9-08dc99c29666 # bob's id
41+
enabled: true
42+
name: rate-limiting
43+
protocols:
44+
- http
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
_format_version: "1.1"
2+
3+
consumers:
4+
- username: alice
5+
id: 8ca63651-4068-4baa-b2b9-08dc99c296e0
6+
- username: bob
7+
id: 8ca63651-4068-4baa-b2b9-08dc99c29666
8+
9+
services:
10+
- name: example-service
11+
port: 3200
12+
protocol: http
13+
host: localhost
14+
routes:
15+
- name: example-route-1
16+
paths:
17+
- /r1
18+
plugins:
19+
- config:
20+
limit_by: consumer
21+
minute: 6
22+
policy: local
23+
consumer: alice
24+
enabled: true
25+
name: rate-limiting
26+
protocols:
27+
- http
28+
29+
routes:
30+
- name: example-route-2
31+
paths:
32+
- /r2
33+
service:
34+
name: example-service
35+
plugins:
36+
- config:
37+
limit_by: consumer
38+
minute: 6
39+
policy: local
40+
consumer: bob
41+
enabled: true
42+
name: rate-limiting
43+
protocols:
44+
- http

0 commit comments

Comments
 (0)