diff --git a/dump/dump.go b/dump/dump.go index d1e94ec00..9888e7d80 100644 --- a/dump/dump.go +++ b/dump/dump.go @@ -6,7 +6,6 @@ import ( "fmt" "net/http" - "github.com/kong/deck/konnect" "github.com/kong/deck/utils" "github.com/kong/go-kong/kong" "golang.org/x/sync/errgroup" @@ -78,11 +77,7 @@ func getConsumerGroupsConfiguration(ctx context.Context, group *errgroup.Group, err error consumerGroups []*kong.ConsumerGroupObject ) - if config.KonnectRuntimeGroup != "" { - consumerGroups, err = GetAllKonnectConsumerGroups(ctx, client, config.SelectorTags) - } else { - consumerGroups, err = GetAllConsumerGroups(ctx, client, config.SelectorTags) - } + consumerGroups, err = GetAllConsumerGroups(ctx, client, config.SelectorTags) if err != nil { if kong.IsNotFoundErr(err) || kong.IsForbiddenErr(err) { return nil @@ -532,29 +527,6 @@ func GetAllUpstreams(ctx context.Context, return upstreams, nil } -// GetAllConsumerGroups queries Konnect for all the ConsumerGroups using client. -func GetAllKonnectConsumerGroups(ctx context.Context, - client *kong.Client, tags []string, -) ([]*kong.ConsumerGroupObject, error) { - var consumerGroupObjects []*kong.ConsumerGroupObject - opt := newOpt(tags) - cgs, err := konnect.ListAllConsumerGroups(ctx, client, opt.Tags) - if err != nil { - return nil, err - } - if err := ctx.Err(); err != nil { - return nil, err - } - for _, cg := range cgs { - r, err := konnect.GetConsumerGroupObject(ctx, client, cg.ID) - if err != nil { - return nil, err - } - consumerGroupObjects = append(consumerGroupObjects, r) - } - return consumerGroupObjects, nil -} - // GetAllConsumerGroups queries Kong for all the ConsumerGroups using client. func GetAllConsumerGroups(ctx context.Context, client *kong.Client, tags []string, diff --git a/file/builder.go b/file/builder.go index 12e158d56..e783db561 100644 --- a/file/builder.go +++ b/file/builder.go @@ -73,7 +73,7 @@ func (b *stateBuilder) build() (*utils.KongRawState, *utils.KonnectRawState, err b.checkRoutePaths = true } - if utils.Kong340Version.LTE(b.kongVersion) { + if utils.Kong340Version.LTE(b.kongVersion) || b.isKonnect { b.isConsumerGroupScopedPluginSupported = true } diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 0bc86b27f..eeb5f90c9 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -623,20 +623,6 @@ var ( Username: kong.String("bar"), }, }, - Plugins: []*kong.ConsumerGroupPlugin{ - { - Name: kong.String("rate-limiting-advanced"), - Config: kong.Configuration{ - "limit": []*int32{int32p(7)}, - "retry_after_jitter_max": int32p(1), - "window_size": []*int32{int32p(60)}, - "window_type": kong.String("sliding"), - }, - ConsumerGroup: &kong.ConsumerGroup{ - ID: kong.String("521a90ad-36cb-4e31-a5db-1d979aee40d1"), - }, - }, - }, }, { ConsumerGroup: &kong.ConsumerGroup{ @@ -3231,12 +3217,54 @@ func Test_Sync_ConsumerGroupsKonnect(t *testing.T) { }, }, { - name: "creates consumer groups and plugin", - kongFile: "testdata/sync/016-consumer-groups-and-plugins/kong3x.yaml", - kongFileInitial: "testdata/sync/016-consumer-groups-and-plugins/kong3x-initial.yaml", + kongFile: "testdata/sync/023-consumer-groups-scoped-plugins/kong3x.yaml", expectedState: utils.KongRawState{ - Consumers: consumerGroupsConsumers, - ConsumerGroups: consumerGroupsWithRLAKonnect, + Consumers: consumerGroupsConsumers, + ConsumerGroups: []*kong.ConsumerGroupObject{ + { + ConsumerGroup: &kong.ConsumerGroup{ + Name: kong.String("silver"), + }, + Consumers: []*kong.Consumer{ + { + Username: kong.String("bar"), + }, + }, + }, + { + ConsumerGroup: &kong.ConsumerGroup{ + Name: kong.String("gold"), + }, + Consumers: []*kong.Consumer{ + { + Username: kong.String("foo"), + }, + }, + }, + }, + Plugins: consumerGroupScopedPlugins, + Services: svc1_207, + Routes: route1_20x, + KeyAuths: []*kong.KeyAuth{ + { + Consumer: &kong.Consumer{ + ID: kong.String("87095815-5395-454e-8c18-a11c9bc0ef04"), + }, + Key: kong.String("i-am-special"), + }, + { + Consumer: &kong.Consumer{ + ID: kong.String("5a5b9369-baeb-4faa-a902-c40ccdc2928e"), + }, + Key: kong.String("i-am-not-so-special"), + }, + { + Consumer: &kong.Consumer{ + ID: kong.String("e894ea9e-ad08-4acf-a960-5a23aa7701c7"), + }, + Key: kong.String("i-am-just-average"), + }, + }, }, }, } @@ -3247,7 +3275,9 @@ func Test_Sync_ConsumerGroupsKonnect(t *testing.T) { defer teardown(t) // set up initial state - sync(tc.kongFileInitial) + if tc.kongFileInitial != "" { + sync(tc.kongFileInitial) + } // update with desired final state sync(tc.kongFile) @@ -3966,7 +3996,7 @@ func Test_Sync_ConsumerGroupsScopedPlugins_Pre340(t *testing.T) { kongFile: "testdata/sync/023-consumer-groups-scoped-plugins/kong3x.yaml", expectedError: errors.New( "a rate-limiting-advanced plugin with config.consumer_groups\n" + - "and/or config.enforced_consumer_group was found. Please use Consumer Groups scoped\n" + + "and/or config.enforce_consumer_group was found. Please use Consumer Groups scoped\n" + "Plugins when running against Kong Enterprise 3.4.0 and above.\n\n" + "Check DOC_LINK for more information"), },