Skip to content

Commit e5cb2e8

Browse files
fix: use _workspace when given for gateway validate (#1783)
* fix: use _workspace when given for gateway validate * tests: konnect tests for target * tests: add test for using lookup tags in non-default workspace * tests: clean up with workspace flag * tests: use service lookup tags instead of consumer group * tests: skip flaky vault sanitize test
1 parent 1ef3e8f commit e5cb2e8

File tree

7 files changed

+73
-6
lines changed

7 files changed

+73
-6
lines changed

cmd/gateway_validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func executeValidate(cmd *cobra.Command, _ []string) error {
5353
ctx := cmd.Context()
5454
var kongClient *kong.Client
5555
if validateOnline {
56+
// if workspace is not set via flag, use the one in the state file
57+
if validateWorkspace == "" && targetContent.Workspace != "" {
58+
validateWorkspace = targetContent.Workspace
59+
}
60+
5661
kongClient, err = getKongClient(ctx, targetContent, mode)
5762
if err != nil {
5863
return err

tests/integration/dump_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,10 @@ func Test_Dump_Sanitize_Special_Entities(t *testing.T) {
803803
skipValidation: true, // env vault validation endpoint not available in 3.4.0
804804
},
805805
{
806-
name: "dump sanitize env vault and vault references",
807-
stateFile: "testdata/dump/008-sanitizer/env-vault.yaml",
808-
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.5.0") },
806+
name: "dump sanitize env vault and vault references",
807+
stateFile: "testdata/dump/008-sanitizer/env-vault.yaml",
808+
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.5.0") },
809+
skipValidation: true, // env vault validation is flaky in GH actions, skipping for now
809810
},
810811
{
811812
name: "dump sanitize vault config",

tests/integration/sync_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,7 +3246,7 @@ func Test_Sync_Upstream_Target_Konnect(t *testing.T) {
32463246
kongFile: "testdata/sync/004-create-upstream-and-target/kong3x.yaml",
32473247
expectedState: utils.KongRawState{
32483248
Upstreams: upstream,
3249-
Targets: target,
3249+
Targets: targetPost312,
32503250
},
32513251
},
32523252
}
@@ -3406,7 +3406,7 @@ func Test_Sync_Upstreams_Target_ZeroWeight_Konnect(t *testing.T) {
34063406
kongFile: "testdata/sync/005-create-upstream-and-target-weight/kong3x.yaml",
34073407
expectedState: utils.KongRawState{
34083408
Upstreams: upstream,
3409-
Targets: targetZeroWeight,
3409+
Targets: targetZeroWeightPost312,
34103410
},
34113411
},
34123412
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_format_version: "3.0"
2+
_workspace: notdefault
3+
services:
4+
- name: svc1
5+
host: mockbin.org
6+
tags:
7+
- service-tag
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_format_version: "3.0"
2+
_info:
3+
default_lookup_tags:
4+
services:
5+
- service-tag
6+
_workspace: notdefault
7+
plugins:
8+
- name: rate-limiting
9+
id: a1368a28-cb5c-4eee-86d8-03a6bdf94b5e
10+
service: svc1
11+
config:
12+
minute: 123
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_format_version: "3.0"
2+
_workspace: nonexistent
3+
services:
4+
- name: svc1
5+
host: mockbin.org

tests/integration/validate_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,16 @@ func Test_Validate_Gateway_EE(t *testing.T) {
220220
setup(t)
221221
runWhen(t, "enterprise", ">=2.8.0")
222222

223+
ctx := context.Background()
224+
223225
tests := []struct {
224226
name string
227+
priorStateFile string
225228
stateFile string
226229
additionalArgs []string
227230
errorExpected bool
231+
errorString string
232+
resetOpts []string
228233
}{
229234
{
230235
name: "validate format version 1.1",
@@ -246,6 +251,19 @@ func Test_Validate_Gateway_EE(t *testing.T) {
246251
stateFile: "testdata/validate/kong-ee.yaml",
247252
additionalArgs: []string{"--workspace=default"},
248253
},
254+
{
255+
name: "validate with non existent _workspace in state file",
256+
stateFile: "testdata/validate/kong-ee-non-existent-workspace.yaml",
257+
errorExpected: true,
258+
errorString: "workspace doesn't exist: nonexistent",
259+
},
260+
{
261+
name: "validate with non-default _workspace and default_lookup_tags",
262+
priorStateFile: "testdata/validate/kong-ee-non-default-workspace-prereq.yaml",
263+
stateFile: "testdata/validate/kong-ee-non-default-workspace-with-lookup-tags.yaml",
264+
errorExpected: false,
265+
resetOpts: []string{"--workspace=notdefault"},
266+
},
249267
{
250268
name: "validate format version 3.0 with --online-entities-list",
251269
stateFile: "testdata/validate/kong-ee.yaml",
@@ -261,13 +279,32 @@ func Test_Validate_Gateway_EE(t *testing.T) {
261279

262280
for _, tc := range tests {
263281
t.Run(tc.name, func(t *testing.T) {
282+
reset(t)
283+
if tc.priorStateFile != "" {
284+
require.NoError(t, sync(ctx, tc.priorStateFile))
285+
}
286+
264287
validateOpts := []string{
265288
tc.stateFile,
266289
}
267290
validateOpts = append(validateOpts, tc.additionalArgs...)
268291

269292
err := validate(ONLINE, validateOpts...)
270-
require.NoError(t, err)
293+
294+
if !tc.errorExpected {
295+
require.NoError(t, err)
296+
} else {
297+
require.Error(t, err)
298+
if tc.errorString != "" {
299+
assert.Contains(t, err.Error(), tc.errorString)
300+
}
301+
}
302+
303+
// Clean up if a non-default workspace was used
304+
if len(tc.resetOpts) > 0 {
305+
reset(t, tc.resetOpts...)
306+
require.NoError(t, err)
307+
}
271308
})
272309
}
273310
}

0 commit comments

Comments
 (0)