Skip to content

Commit

Permalink
fix: added fix to allow one consumer to
Browse files Browse the repository at this point in the history
be in >1 consumer-groups.

gdr version 1.39.2 introduced a bug where a consumer
was limited to only one consumer-group.
Adding the consumer in >1 group was resulting in an
error on deck. This PR adds the fix for the same and
an integration test.

See: Kong/deck#1384
  • Loading branch information
Prashansa-K committed Sep 4, 2024
1 parent 0b1b75f commit 08dd5e2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/state/consumer_group_consumers.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,21 @@ func getConsumerGroupConsumer(txn *memdb.Txn, consumerGroupID string, IDs ...str

for _, id := range IDs {
for _, index := range indexes {
res, err := txn.First(consumerGroupConsumerTableName, index, id)
res, err := txn.Get(consumerGroupConsumerTableName, index, id)
if err != nil {
return nil, err
}
if res != nil {
consumer := res.(*ConsumerGroupConsumer)

for {
resultValue := res.Next()
if resultValue == nil {
break
}
consumer, ok := resultValue.(*ConsumerGroupConsumer)
if !ok {
break
}

if *consumer.ConsumerGroup.ID == consumerGroupID {
return consumer, nil
}
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5686,3 +5686,42 @@ func Test_Sync_PluginAutoFields(t *testing.T) {
})
})
}

// test scope:
// - 3.x
func Test_Sync_MoreThanOneConsumerGroupForOneConsumer(t *testing.T) {
client, err := getTestClient()
require.NoError(t, err)

expectedState := utils.KongRawState{
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group1"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
{
ConsumerGroup: &kong.ConsumerGroup{
Name: kong.String("group2"),
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
},
},
Consumers: []*kong.Consumer{
{
Username: kong.String("my-test-consumer"),
},
},
}
require.NoError(t, sync("testdata/sync/xxx-more-than-one-consumer-group-with-a-consumer/kong.yaml"))
testKongState(t, client, false, expectedState, nil)
}
1 change: 1 addition & 0 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool,
cmpopts.IgnoreFields(kong.Vault{}, "ID", "CreatedAt", "UpdatedAt"),
cmpopts.IgnoreFields(kong.Certificate{}, "ID", "CreatedAt"),
cmpopts.IgnoreFields(kong.SNI{}, "ID", "CreatedAt"),
cmpopts.IgnoreFields(kong.Consumer{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.ConsumerGroup{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.ConsumerGroupPlugin{}, "CreatedAt", "ID"),
cmpopts.IgnoreFields(kong.KeyAuth{}, "ID", "CreatedAt"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_format_version: "3.0"
consumer_groups:
- name: group1
- name: group2
consumers:
- username: my-test-consumer
groups:
- name: group1
- name: group2

0 comments on commit 08dd5e2

Please sign in to comment.