Skip to content

Commit

Permalink
fix: raise error if files have different Runtime Groups
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Sep 6, 2023
1 parent 55fb115 commit 444876b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion file/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// file, depending on the type of each item in filenames, merges the content of
// these files and renders a Content.
func getContent(filenames []string, mockEnvVars bool) (*Content, error) {
var workspaces []string
var workspaces, runtimeGroups []string
var res Content
var errs []error
for _, fileOrDir := range filenames {
Expand All @@ -38,6 +38,9 @@ func getContent(filenames []string, mockEnvVars bool) (*Content, error) {
if content.Workspace != "" {
workspaces = append(workspaces, content.Workspace)
}
if content.Konnect != nil && len(content.Konnect.RuntimeGroupName) > 0 {
runtimeGroups = append(runtimeGroups, content.Konnect.RuntimeGroupName)
}
err = mergo.Merge(&res, content, mergo.WithAppendSlice)
if err != nil {
return nil, fmt.Errorf("merging file contents: %w", err)
Expand All @@ -50,6 +53,9 @@ func getContent(filenames []string, mockEnvVars bool) (*Content, error) {
if err := validateWorkspaces(workspaces); err != nil {
return nil, err
}
if err := validateRuntimeGroups(runtimeGroups); err != nil {
return nil, err
}
return &res, nil
}

Expand Down
6 changes: 6 additions & 0 deletions file/readfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ kong.log.set_serialize_value("span_id", parse_traceid(ngx.ctx.KONG_SPANS[1].span
want: nil,
wantErr: true,
},
{
name: "different runtime groups",
args: args{[]string{"testdata/differentruntimegroup"}},
want: nil,
wantErr: true,
},
{
name: "same workspaces",
args: args{[]string{"testdata/sameworkspace"}},
Expand Down
6 changes: 6 additions & 0 deletions file/testdata/differentruntimegroup/bar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_format_version: "3.0"
_konnect:
runtime_group_name: bar
services:
- name: svc2
host: 2.example.com
6 changes: 6 additions & 0 deletions file/testdata/differentruntimegroup/foo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_format_version: "3.0"
_konnect:
runtime_group_name: foo
services:
- name: svc1
host: 1.example.com
10 changes: 10 additions & 0 deletions file/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ func validateWorkspaces(workspaces []string) error {
}
return nil
}

func validateRuntimeGroups(names []string) error {
utils.RemoveDuplicates(&names)
if len(names) > 1 {
return fmt.Errorf("it seems like you are trying to sync multiple Konnect Runtime Groups "+
"at the same time (%v).\ndecK doesn't support syncing multiple Runtime Groups at the same time, "+
"please sync one Runtime Group at a time", names)
}
return nil
}

0 comments on commit 444876b

Please sign in to comment.