Skip to content

Commit f7eae2c

Browse files
authored
fix: plugin-relations fetched from intermediate state (#1627)
1 parent e144f79 commit f7eae2c

File tree

6 files changed

+136
-6
lines changed

6 files changed

+136
-6
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ 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.42
16-
github.com/kong/go-database-reconciler v1.22.5
16+
github.com/kong/go-database-reconciler v1.22.6
1717
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
2121
github.com/spf13/viper v1.19.0
2222
github.com/stretchr/testify v1.10.0
23-
golang.org/x/sync v0.12.0
23+
golang.org/x/sync v0.14.0
2424
k8s.io/api v0.32.1
2525
k8s.io/apiextensions-apiserver v0.32.1
2626
k8s.io/apimachinery v0.32.3

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ 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.42 h1:GF9KV1D06p/Ux2F5Dc4UJzGKFOeMzynpUWiAZwyEqxE=
248248
github.com/kong/go-apiops v0.1.42/go.mod h1:hKnHJ3UyeuG932SkI/yMpuT/PqSqGXNTS1zhno1lDqg=
249-
github.com/kong/go-database-reconciler v1.22.5 h1:QHfGnNgnn8WFb+k7m5sfr+1+YIEXogy1S7dSebHQBqw=
250-
github.com/kong/go-database-reconciler v1.22.5/go.mod h1:X8IjjS23H44Kzp9KjfCNM6WaQHnPhyeVYvntuI7fAkU=
249+
github.com/kong/go-database-reconciler v1.22.6 h1:G8rjG7057aVHem4q6tyyzEyJo3hH2weL0U9JAZk4H/0=
250+
github.com/kong/go-database-reconciler v1.22.6/go.mod h1:hLtPRsuxqTYv1rt6h/YrimjDQzkxlAFSIWoG1jEjWKE=
251251
github.com/kong/go-kong v0.65.1 h1:CM+8NlF+VbJckTxP2hGmSPKhA1GMliitXjQ7vJiPkaE=
252252
github.com/kong/go-kong v0.65.1/go.mod h1:sqdysTKrXIJ6mpxHwTwjgZhLW7jR1/puczTXHLUwJaE=
253253
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
@@ -536,8 +536,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
536536
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
537537
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
538538
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
539-
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
540-
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
539+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
540+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
541541
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
542542
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
543543
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

tests/integration/sync_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -8217,3 +8217,76 @@ func Test_Sync_Plugins_Nested_Foreign_Keys_EE_3x(t *testing.T) {
82178217
})
82188218
}
82198219
}
8220+
8221+
// test scope:
8222+
//
8223+
// - >=2.8.0
8224+
func Test_Sync_Scoped_Plugins_Check_Conflicts(t *testing.T) {
8225+
runWhenKongOrKonnect(t, ">=2.8.0")
8226+
setup(t)
8227+
8228+
ctx := context.Background()
8229+
8230+
stateFiles := []string{
8231+
"testdata/sync/042-scoped-plugins/plugins1.yaml",
8232+
"testdata/sync/042-scoped-plugins/plugins2.yaml",
8233+
}
8234+
8235+
tests := []struct {
8236+
name string
8237+
multiSync bool
8238+
emptyState bool
8239+
}{
8240+
{
8241+
name: "sync plugin files one by one, existing state: empty",
8242+
multiSync: false,
8243+
emptyState: true,
8244+
},
8245+
{
8246+
name: "sync plugin files one by one, existing state: non-empty",
8247+
multiSync: false,
8248+
emptyState: false,
8249+
},
8250+
{
8251+
name: "sync plugin files together, existing state: empty",
8252+
multiSync: true,
8253+
emptyState: true,
8254+
},
8255+
{
8256+
name: "sync plugin files together, existing state: non-empty",
8257+
multiSync: true,
8258+
emptyState: false,
8259+
},
8260+
}
8261+
8262+
for _, tc := range tests {
8263+
t.Run(tc.name, func(t *testing.T) {
8264+
reset(t)
8265+
if !tc.emptyState {
8266+
// syncing first state file to create initial state
8267+
err := sync(ctx, stateFiles[0])
8268+
require.NoError(t, err)
8269+
}
8270+
8271+
if tc.multiSync {
8272+
err := multiFileSync(ctx, stateFiles)
8273+
require.NoError(t, err)
8274+
8275+
// re-sync with no error
8276+
err = multiFileSync(ctx, stateFiles)
8277+
require.NoError(t, err)
8278+
8279+
return
8280+
}
8281+
8282+
for _, s := range stateFiles {
8283+
err := sync(ctx, s)
8284+
require.NoError(t, err)
8285+
8286+
// re-sync with no error
8287+
err = sync(ctx, s)
8288+
require.NoError(t, err)
8289+
}
8290+
})
8291+
}
8292+
}

tests/integration/test_utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,17 @@ func sync(ctx context.Context, kongFile string, opts ...string) error {
323323
return deckCmd.ExecuteContext(ctx)
324324
}
325325

326+
func multiFileSync(ctx context.Context, kongFiles []string, opts ...string) error {
327+
deckCmd := cmd.NewRootCmd()
328+
args := []string{"gateway", "sync"}
329+
args = append(args, kongFiles...)
330+
if len(opts) > 0 {
331+
args = append(args, opts...)
332+
}
333+
deckCmd.SetArgs(args)
334+
return deckCmd.ExecuteContext(ctx)
335+
}
336+
326337
func diff(kongFile string, opts ...string) (string, error) {
327338
deckCmd := cmd.NewRootCmd()
328339
args := []string{"diff", "-s", kongFile}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
_format_version: "3.0"
2+
plugins:
3+
- config:
4+
body: null
5+
content_type: null
6+
echo: false
7+
message: null
8+
status_code: 503
9+
trigger: null
10+
enabled: true
11+
name: request-termination
12+
protocols:
13+
- grpc
14+
- grpcs
15+
- http
16+
- https
17+
tags:
18+
- tag1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
_format_version: "3.0"
2+
services:
3+
- connect_timeout: 60000
4+
enabled: true
5+
host: httpbin.org
6+
name: anything-tag2
7+
path: /anything
8+
plugins:
9+
- config:
10+
body: null
11+
content_type: null
12+
echo: true
13+
message: null
14+
status_code: 503
15+
trigger: null
16+
enabled: true
17+
name: request-termination
18+
protocols:
19+
- grpc
20+
- grpcs
21+
- http
22+
- https
23+
tags:
24+
- tag2
25+
port: 80
26+
protocol: http
27+
read_timeout: 60000
28+
retries: 5

0 commit comments

Comments
 (0)