Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensuring consumer-group scoped plugins show tags #151

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hexops/gotextdiff v1.0.3
github.com/kong/deck v1.34.0
github.com/kong/go-kong v0.60.0
github.com/kong/go-kong v0.61.0
github.com/samber/lo v1.47.0
github.com/shirou/gopsutil/v3 v3.24.5
github.com/ssgelm/cookiejarparser v1.0.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/sync v0.8.0
golang.org/x/term v0.24.0
k8s.io/code-generator v0.31.2
k8s.io/code-generator v0.31.3
sigs.k8s.io/yaml v1.4.0
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ github.com/kong/deck v1.34.0 h1:iKSa5Cq8t7bdCv5R3XRV8UH+7FvnZB/YxhRTuih4rgg=
github.com/kong/deck v1.34.0/go.mod h1:IUAixgNa1YSvEphgX9OIHmDyyi1JRaGTB0bYieuD9qo=
github.com/kong/go-apiops v0.1.29 h1:c+AB8MmGIr+K01Afm4GB2xaOmJnD/8KWMJQkr9qssnc=
github.com/kong/go-apiops v0.1.29/go.mod h1:ZNdiTZyVrAssB4wjEYWV7BfpcV9UME9LxnDDZhMPuNU=
github.com/kong/go-kong v0.60.0 h1:CVrLXRLVE+Gl4IZ3tdvpO7xNDz3c9YLTmra/HvT4oM8=
github.com/kong/go-kong v0.60.0/go.mod h1:t1eMY8GRS6778uQNzxgzRgnA3YKBXSZOEvYbNocH/aA=
github.com/kong/go-kong v0.61.0 h1:EWnQVMk1u1gy8//Hvui3NVCJZZ+fBnifVcoaIyLq60A=
github.com/kong/go-kong v0.61.0/go.mod h1:e0zgpuCnCbOXQN6e0e235TFJr4IYY8dDg9nLQgG9m7A=
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw=
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
Expand Down Expand Up @@ -312,8 +312,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
Expand Down Expand Up @@ -472,8 +472,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/code-generator v0.31.2 h1:xLWxG0HEpMSHfcM//3u3Ro2Hmc6AyyLINQS//Z2GEOI=
k8s.io/code-generator v0.31.2/go.mod h1:eEQHXgBU/m7LDaToDoiz3t97dUUVyOblQdwOr8rivqc=
k8s.io/code-generator v0.31.3 h1:Pj0fYOBms+ZrsulLi4DMsCEx1jG8fWKRLy44onHsLBI=
k8s.io/code-generator v0.31.3/go.mod h1:/umCIlT84g1+Yu5ZXtP1KGSRTnGiIzzX5AzUAxsNlts=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
Expand Down
1 change: 1 addition & 0 deletions pkg/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (b *stateBuilder) ingestConsumerGroupScopedPlugins(cg FConsumerGroupObject)
ConsumerGroup: &kong.ConsumerGroup{
ID: cg.ID,
},
Tags: plugin.Tags,
},
ConfigSource: plugin.ConfigSource,
})
Expand Down
6 changes: 6 additions & 0 deletions pkg/file/kong_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@
},
"name": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down
1 change: 1 addition & 0 deletions pkg/file/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ func populateConsumerGroups(kongState *state.KongState, file *Content,
ID: plugin.ID,
Name: plugin.Name,
Config: plugin.Config,
Tags: plugin.Tags,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/state/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func buildKong(kongState *KongState, raw *utils.KongRawState) error {
Config: p.Config,
ConsumerGroup: cg.ConsumerGroup,
ConfigSource: p.ConfigSource,
Tags: p.Tags,
},
},
)
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,24 @@ var (
Protocols: []*string{kong.String("http"), kong.String("https")},
},
}

consumerGroupScopedPluginWithTags = []*kong.Plugin{{
Name: kong.String("request-transformer"),
Config: kong.Configuration{
"add": map[string]any{"body": []any{}, "headers": []any{}, "querystring": []any{}},
"append": map[string]any{"body": []any{}, "headers": []any{}, "querystring": []any{}},
"http_method": string("GET"),
"remove": map[string]any{"body": []any{}, "headers": []any{string("test-header")}, "querystring": []any{}},
"rename": map[string]any{"body": []any{}, "headers": []any{}, "querystring": []any{}},
"replace": map[string]any{"body": []any{}, "headers": []any{}, "querystring": []any{}, "uri": nil},
},
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("58076db2-28b6-423b-ba39-a79719301700"),
},
Tags: kong.StringSlice("tag1", "tag2"),
Enabled: kong.Bool(true),
Protocols: []*string{kong.String("grpc"), kong.String("grpcs"), kong.String("http"), kong.String("https")},
}}
)

// test scope:
Expand Down Expand Up @@ -2800,6 +2818,47 @@ func Test_Sync_PluginsOnEntitiesFrom_3_0_0(t *testing.T) {
}
}

// test scope:
// - 3.4.0+
func Test_Sync_PluginsOnConsumerGroupsWithTagsFrom_3_4_0(t *testing.T) {
// setup stage
client, err := getTestClient()
if err != nil {
t.Fatalf(err.Error())
}

tests := []struct {
name string
kongFile string
expectedState utils.KongRawState
}{
{
name: "create plugins on consumer-groups",
kongFile: "testdata/sync/xxx-plugins-on-entities/kong-cg-plugin.yaml",
expectedState: utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("foo"),
},
},
},
Plugins: consumerGroupScopedPluginWithTags,
},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhenEnterpriseOrKonnect(t, ">=3.4.0")
setup(t)

sync(tc.kongFile)
testKongState(t, client, false, tc.expectedState, nil)
})
}
}

// test scope:
// - 3.0.0+
func Test_Sync_PluginOrdering(t *testing.T) {
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for xxx in the name :) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the recent convention. Earlier folders were numbered, but then xxx became the prefix.
I assumed we did so because we had already reached 35 folders.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Is 35 a magic number of sorts for us ? 🙃 Nothing against the prefix, just curious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 No! I can change the name. As I said, I just looked at the last few entries and added the xxx

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_format_version: "3.0"

consumer_groups:
- id: 58076db2-28b6-423b-ba39-a79719301700
name: foo
plugins:
- name: request-transformer
tags:
- tag1
- tag2
config:
http_method: GET
remove:
headers:
- test-header
Loading