From dd609522107d951241e35f2852dae221bd151c16 Mon Sep 17 00:00:00 2001 From: Prashansa Kulshrestha Date: Wed, 8 Jan 2025 12:40:36 +0530 Subject: [PATCH] fix: fixing consumer-group related dump config for deck. With changes added in go-kong, to skip listing consumers while doing a GET call on a consumer_group, dump config with gw 3.9+ starting showing issues. Associations between a consumer and consumer-group were missing. Thus, we are pushing the no listing consumers feature behind a flag for now, applicable only for dump command as a starting point. --- cmd/gateway_dump.go | 4 +++ tests/integration/dump_test.go | 26 +++++++++++++++++ tests/integration/test_utils.go | 4 +-- .../expected-with-flag.yaml | 14 +++++++++ .../expected-without-flag.yaml | 29 +++++++++++++++++++ .../kong.yaml | 20 +++++++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml create mode 100644 tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-without-flag.yaml create mode 100644 tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml diff --git a/cmd/gateway_dump.go b/cmd/gateway_dump.go index f37e15ad6..4970d27c8 100644 --- a/cmd/gateway_dump.go +++ b/cmd/gateway_dump.go @@ -188,6 +188,10 @@ configure Kong.`, false, "assume `yes` to prompts and run non-interactively.") dumpCmd.Flags().BoolVar(&dumpConfig.SkipCACerts, "skip-ca-certificates", false, "do not dump CA certificates.") + dumpCmd.Flags().BoolVar(&dumpConfig.SkipConsumersWithConsumerGroups, "skip-consumers-with-consumer-groups", + false, "do not show the association between consumer and consumer-group.\n"+ + "If set to true, deck skips listing consumers with consumer-groups,\n"+ + "thus gaining some performance with large configs.") if deprecated { dumpCmd.Flags().StringVarP(&dumpCmdKongStateFileDeprecated, "output-file", "o", fileOutDefault, "file to which to write Kong's configuration."+ diff --git a/tests/integration/dump_test.go b/tests/integration/dump_test.go index ac0e76a92..fd81af46c 100644 --- a/tests/integration/dump_test.go +++ b/tests/integration/dump_test.go @@ -344,3 +344,29 @@ func Test_Dump_FilterChains(t *testing.T) { }) } } + +func Test_SkipConsumersWithConsumerGroups(t *testing.T) { + runWhen(t, "enterprise", ">=3.9.0") + setup(t) + + require.NoError(t, sync("testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml")) + + // With flag set + var output string + flags := []string{"-o", "-", "--skip-consumers-with-consumer-groups"} + output, err := dump(flags...) + assert.NoError(t, err) + + expected, err := readFile("testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml") + assert.NoError(t, err) + assert.Equal(t, expected, output) + + // Without flag set - default behaviour + flags = []string{"-o", "-"} + output, err = dump(flags...) + assert.NoError(t, err) + + expected, err = readFile("testdata/dump/004-skip-consumers-with-consumer-groups/expected-without-flag.yaml") + assert.NoError(t, err) + assert.Equal(t, expected, output) +} diff --git a/tests/integration/test_utils.go b/tests/integration/test_utils.go index 41a23b40e..2d871d0d1 100644 --- a/tests/integration/test_utils.go +++ b/tests/integration/test_utils.go @@ -268,7 +268,7 @@ func setup(t *testing.T) { func sync(kongFile string, opts ...string) error { deckCmd := cmd.NewRootCmd() - args := []string{"sync", "-s", kongFile} + args := []string{"gateway", "sync", kongFile} if len(opts) > 0 { args = append(args, opts...) } @@ -300,7 +300,7 @@ func diff(kongFile string, opts ...string) (string, error) { func dump(opts ...string) (string, error) { deckCmd := cmd.NewRootCmd() - args := []string{"dump"} + args := []string{"gateway", "dump"} if len(opts) > 0 { args = append(args, opts...) } diff --git a/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml new file mode 100644 index 000000000..d78edb6d8 --- /dev/null +++ b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml @@ -0,0 +1,14 @@ +_format_version: "3.0" +consumer_groups: +- name: gold + tags: + - tag1 + - tag2 +- name: silver + tags: + - tag1 + - tag3 +consumers: +- username: bar +- username: baz +- username: foo diff --git a/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-without-flag.yaml b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-without-flag.yaml new file mode 100644 index 000000000..80618e070 --- /dev/null +++ b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/expected-without-flag.yaml @@ -0,0 +1,29 @@ +_format_version: "3.0" +consumer_groups: +- name: gold + tags: + - tag1 + - tag2 +- name: silver + tags: + - tag1 + - tag3 +consumers: +- groups: + - name: silver + tags: + - tag1 + - tag3 + username: bar +- groups: + - name: silver + tags: + - tag1 + - tag3 + username: baz +- groups: + - name: gold + tags: + - tag1 + - tag2 + username: foo diff --git a/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml new file mode 100644 index 000000000..b50eeac90 --- /dev/null +++ b/tests/integration/testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml @@ -0,0 +1,20 @@ +_format_version: "3.0" +consumer_groups: +- name: silver + tags: + - tag1 + - tag3 +- name: gold + tags: + - tag1 + - tag2 +consumers: +- username: foo + groups: + - name: gold +- username: bar + groups: + - name: silver +- username: baz + groups: + - name: silver