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: fixing consumer-group related dump config for deck. #1486

Merged
merged 6 commits into from
Jan 16, 2025
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
9 changes: 9 additions & 0 deletions cmd/gateway_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -48,6 +49,10 @@ func executeDump(cmd *cobra.Command, _ []string) error {
}

if inKonnectMode(nil) {
if dumpConfig.SkipConsumersWithConsumerGroups {
return errors.New("the flag --skip-consumers-with-consumer-groups can not be used with Konnect")
}

_ = sendAnalytics("dump", "", modeKonnect)
return dumpKonnectV2(ctx)
}
Expand Down Expand Up @@ -188,6 +193,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. This flag is not valid with Konnect.")
if deprecated {
dumpCmd.Flags().StringVarP(&dumpCmdKongStateFileDeprecated, "output-file", "o",
fileOutDefault, "file to which to write Kong's configuration."+
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/fatih/color v1.17.0
github.com/google/go-cmp v0.6.0
github.com/kong/go-apiops v0.1.40
github.com/kong/go-database-reconciler v1.17.0
github.com/kong/go-kong v0.61.0
github.com/kong/go-database-reconciler v1.18.0
github.com/kong/go-kong v0.63.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/q
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kong/go-apiops v0.1.40 h1:Dp4IHJ3h61VeOAeQkOisf1BcOP+Ww+gpqnv14HvC6DQ=
github.com/kong/go-apiops v0.1.40/go.mod h1:CNfsa9mHFRfAhT9E2IWTul0Mi1/BldTDmFu5fWcp2us=
github.com/kong/go-database-reconciler v1.17.0 h1:vL/KskveUR8fflbw+r/6QphSHxV8YahjfSDjNe9pDrI=
github.com/kong/go-database-reconciler v1.17.0/go.mod h1:3L4DP3/YGaDv9Hks4XA1YFm7HfPur2CuBxHI/4+r7NY=
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-database-reconciler v1.18.0 h1:j1gVZ1uPfKglBXTyLEqDn0N374z2y/oaXOuCnWRuQTE=
github.com/kong/go-database-reconciler v1.18.0/go.mod h1:T0SYIHeC/3DeHzThtUS+ooxouN5KBGeKWcjkuCg4MS8=
github.com/kong/go-kong v0.63.0 h1:8ECLgkgDqON61qCMq/M0gTwZKYxg55Oy692dRDOOBiU=
github.com/kong/go-kong v0.63.0/go.mod h1:ma9GWnhkxtrXZlLFfED955HjVzmUojYEHet3lm+PDik=
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/kubernetes-configuration v1.0.0 h1:f/OaX6oq8/MPur45KzcrIFGJ9Kl6OyTjlXqTJH+ij4s=
Expand Down Expand Up @@ -377,6 +377,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
105 changes: 105 additions & 0 deletions tests/integration/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,108 @@ func Test_Dump_FilterChains(t *testing.T) {
})
}
}

func Test_SkipConsumersWithConsumerGroups(t *testing.T) {
tests := []struct {
name string
stateFile string
expectedFile string
errorExpected bool
errorString string
skipConsumersWithConsumerGroups bool
runWhen func(t *testing.T)
}{
{
name: "dump with flag --skip-consumers-with-consumer-groups set: <3.0.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag_1.yaml",
skipConsumersWithConsumerGroups: true,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", "<3.0.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups not set: <3.0.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-no-flag_1.yaml",
skipConsumersWithConsumerGroups: false,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", "<3.0.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups set: <3.9.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml",
skipConsumersWithConsumerGroups: true,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.0.0 <3.9.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups not set: <3.9.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-no-flag.yaml",
skipConsumersWithConsumerGroups: false,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.0.0 <3.9.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups set: >=3.9.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-with-flag.yaml",
skipConsumersWithConsumerGroups: true,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.9.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups not set: >=3.9.0 ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-no-flag.yaml",
skipConsumersWithConsumerGroups: false,
runWhen: func(t *testing.T) { runWhen(t, "enterprise", ">=3.9.0") },
},
{
name: "dump with flag --skip-consumers-with-consumer-groups set: Konnect ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
skipConsumersWithConsumerGroups: true,
runWhen: func(t *testing.T) { runWhenKonnect(t) },
errorExpected: true,
errorString: "the flag --skip-consumers-with-consumer-groups can not be used with Konnect",
},
{
name: "dump with flag --skip-consumers-with-consumer-groups not set: Konnect ",
stateFile: "testdata/dump/004-skip-consumers-with-consumer-groups/kong3x.yaml",
expectedFile: "testdata/dump/004-skip-consumers-with-consumer-groups/expected-konnect.yaml",
skipConsumersWithConsumerGroups: false,
runWhen: func(t *testing.T) { runWhenKonnect(t) },
},
}

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

assert.NoError(t, sync(tc.stateFile))

var (
output string
err error
)
if tc.skipConsumersWithConsumerGroups {
output, err = dump(
"--skip-consumers-with-consumer-groups",
"-o", "-",
)
} else {
output, err = dump(
"-o", "-",
)
}

if tc.errorExpected {
assert.Equal(t, err.Error(), tc.errorString)
return
}

assert.NoError(t, err)

expected, err := readFile(tc.expectedFile)
assert.NoError(t, err)
assert.Equal(t, expected, output)
})
}
}
4 changes: 2 additions & 2 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down Expand Up @@ -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...)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
_format_version: "3.0"
_konnect:
control_plane_name: default
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
_format_version: "1.1"
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_format_version: "1.1"
consumer_groups:
- name: gold
tags:
- tag1
- tag2
- name: silver
tags:
- tag1
- tag3
consumers:
- username: bar
- username: baz
- username: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_format_version: "1.1"
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
Original file line number Diff line number Diff line change
@@ -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
Loading