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: konnect cli flags getting considered for online validation. #1424

Merged
merged 2 commits into from
Oct 22, 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents

- [v1.41.1](#v1411)
- [v1.41.0](#v1410)
- [v1.40.3](#v1403)
- [v1.40.2](#v1402)
Expand Down Expand Up @@ -97,6 +98,13 @@
- [v0.2.0](#v020)
- [v0.1.0](#v010)

## [v1.41.1]
> Release date: 2024/10/22

### Fixes
- `deck gateway validate` for Konnect supports Konnect configs passed by CLI flags now.
Earlier, the validation was failing if control plane information was passed via CLI flags.

## [v1.41.0]
> Release date: 2024/10/21

Expand Down Expand Up @@ -1835,6 +1843,7 @@ No breaking changes have been introduced in this release.

Debut release of decK

[v1.41.1]: https://github.com/Kong/deck/compare/v1.40.0...v1.41.1
[v1.41.0]: https://github.com/Kong/deck/compare/v1.40.3...v1.41.0
[v1.40.3]: https://github.com/Kong/deck/compare/v1.40.2...v1.40.3
[v1.40.2]: https://github.com/Kong/deck/compare/v1.40.1...v1.40.2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ the GitHub [release page](https://github.com/kong/deck/releases)
or install by downloading the binary:

```shell
$ curl -sL https://github.com/kong/deck/releases/download/v1.41.0/deck_1.41.0_linux_amd64.tar.gz -o deck.tar.gz
$ curl -sL https://github.com/kong/deck/releases/download/v1.41.1/deck_1.41.1_linux_amd64.tar.gz -o deck.tar.gz
$ tar -xf deck.tar.gz -C /tmp
$ sudo cp /tmp/deck /usr/local/bin/
```
Expand All @@ -84,7 +84,7 @@ If you are on Windows, you can download the binary from the GitHub
[release page](https://github.com/kong/deck/releases) or via PowerShell:

```shell
$ curl -sL https://github.com/kong/deck/releases/download/v1.41.0/deck_1.41.0_windows_amd64.tar.gz -o deck.tar.gz
$ curl -sL https://github.com/kong/deck/releases/download/v1.41.1/deck_1.41.1_windows_amd64.tar.gz -o deck.tar.gz
$ tar -xzvf deck.tar.gz
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func executeValidate(cmd *cobra.Command, _ []string) error {
}

if validateKonnectCompatibility || (mode == modeKonnect && validateOnline) {
if errs := validate.KonnectCompatibility(targetContent); len(errs) != 0 {
if errs := validate.KonnectCompatibility(targetContent, dumpConfig); len(errs) != 0 {
return validate.ErrorsWrapper{Errors: errs}
}

Expand Down
13 changes: 9 additions & 4 deletions tests/integration/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ func Test_Validate_Konnect(t *testing.T) {
errorString: "[workspaces] not supported by Konnect - use control planes instead",
},
{
name: "validate with no konnect config in file",
name: "validate with no konnect config in file, passed via cli flag konnect control plane",
stateFile: "testdata/validate/konnect_invalid.yaml",
additionalArgs: []string{},
errorExpected: true,
errorString: "[konnect] section not specified - ensure details are set via cli flags",
additionalArgs: []string{"--konnect-control-plane-name=default"},
errorExpected: false,
},
{
name: "validate with no konnect config in file, passed via cli flag konnect runtime group",
stateFile: "testdata/validate/konnect_invalid.yaml",
additionalArgs: []string{"--konnect-runtime-group-name=default"},
errorExpected: false,
},
}

Expand Down
5 changes: 3 additions & 2 deletions validate/konnect_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strconv"

"github.com/kong/go-database-reconciler/pkg/dump"
"github.com/kong/go-database-reconciler/pkg/file"
"github.com/kong/go-kong/kong"
)
Expand Down Expand Up @@ -39,14 +40,14 @@ func checkPlugin(name *string, config kong.Configuration) error {
return nil
}

func KonnectCompatibility(targetContent *file.Content) []error {
func KonnectCompatibility(targetContent *file.Content, dumpConfig dump.Config) []error {
var errs []error

if targetContent.Workspace != "" {
errs = append(errs, errors.New(errWorkspace))
}

if targetContent.Konnect == nil {
if targetContent.Konnect == nil && dumpConfig.KonnectControlPlane == "" {
Copy link
Member

Choose a reason for hiding this comment

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

is it always going to be "" or could it also be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a string value. So, always "".

errs = append(errs, errors.New(errKonnect))
}

Expand Down
25 changes: 21 additions & 4 deletions validate/konnect_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (
"fmt"
"testing"

"github.com/kong/go-database-reconciler/pkg/dump"
"github.com/kong/go-database-reconciler/pkg/file"
"github.com/kong/go-kong/kong"
"github.com/stretchr/testify/assert"
)

func Test_KonnectCompatibility(t *testing.T) {
tests := []struct {
name string
content *file.Content
expected []error
name string
content *file.Content
dumpConfig dump.Config
expected []error
}{
{
name: "version invalid",
Expand All @@ -26,6 +28,7 @@ func Test_KonnectCompatibility(t *testing.T) {
ControlPlaneName: "s",
},
},
dumpConfig: dump.Config{},
expected: []error{
errors.New(errWorkspace),
errors.New(errBadVersion),
Expand All @@ -36,6 +39,7 @@ func Test_KonnectCompatibility(t *testing.T) {
content: &file.Content{
FormatVersion: "3.1",
},
dumpConfig: dump.Config{},
expected: []error{
errors.New(errKonnect),
},
Expand All @@ -60,6 +64,7 @@ func Test_KonnectCompatibility(t *testing.T) {
}},
},
},
dumpConfig: dump.Config{},
expected: []error{
fmt.Errorf(errPluginIncompatible, "oauth2"),
},
Expand Down Expand Up @@ -95,6 +100,7 @@ func Test_KonnectCompatibility(t *testing.T) {
}},
},
},
dumpConfig: dump.Config{},
expected: []error{
fmt.Errorf(errPluginIncompatible, "oauth2"),
fmt.Errorf("[%s] keys are automatically encrypted in Konnect, use the key auth plugin instead", "key-auth-enc"),
Expand Down Expand Up @@ -128,15 +134,26 @@ func Test_KonnectCompatibility(t *testing.T) {
},
},
},
dumpConfig: dump.Config{},
expected: []error{
fmt.Errorf(errPluginNoCluster, "response-ratelimiting"),
fmt.Errorf("[%s] keys are automatically encrypted in Konnect, use the key auth plugin instead", "key-auth-enc"),
},
},
{
name: "no konnect info in file, but passed via cli flag",
content: &file.Content{
FormatVersion: "3.1",
},
dumpConfig: dump.Config{
KonnectControlPlane: "default",
},
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
errs := KonnectCompatibility(tt.content)
errs := KonnectCompatibility(tt.content, tt.dumpConfig)
assert.Equal(t, tt.expected, errs)
})
}
Expand Down
Loading