Skip to content

Commit

Permalink
fix: diff with not-existing WS must not fail due to defaults
Browse files Browse the repository at this point in the history
decK dynamically discovers entities defaults by interacting
with the Kong Admin API. Queries to retrieve entities schema
for a workspace that doesn't exist yet would fail though.
When running `diff`, in order to prevent a failure, decK simply
skips defaults injection for all entities, but it was still
wrongly running queries for plugins, making the run fail.

This PR makes sure plugins defaults injection is treated the
same as other entities when running `diff` against a
not-existing workspace.
  • Loading branch information
GGabriele authored and rainest committed Jul 8, 2022
1 parent f483570 commit 2f283c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package file

import (
"context"
"errors"
"fmt"

"github.com/blang/semver/v4"
Expand Down Expand Up @@ -42,6 +43,8 @@ var uuid = func() *string {
return kong.String(utils.UUID())
}

var ErrWorkspaceNotFound = fmt.Errorf("workspace not found")

func (b *stateBuilder) build() (*utils.KongRawState, *utils.KonnectRawState, error) {
// setup
var err error
Expand Down Expand Up @@ -825,7 +828,7 @@ func (b *stateBuilder) getPluginSchema(pluginName string) (map[string]interface{
return nil, fmt.Errorf("ensure workspace exists: %w", err)
}
if !exists {
return schema, nil
return schema, ErrWorkspaceNotFound
}

schema, err = b.client.Plugins.GetFullSchema(b.ctx, &pluginName)
Expand All @@ -842,6 +845,9 @@ func (b *stateBuilder) addPluginDefaults(plugin *FPlugin) error {
}
schema, err := b.getPluginSchema(*plugin.Name)
if err != nil {
if errors.Is(err, ErrWorkspaceNotFound) {
return nil
}
return fmt.Errorf("retrieve schema for %v from Kong: %v", *plugin.Name, err)
}
return kong.FillPluginsDefaults(&plugin.Plugin, schema)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
_workspace: test
services:
- name: svc1
host: mockbin.org
host: mockbin.org
plugins:
- name: rate-limiting
config:
minute: 123

0 comments on commit 2f283c7

Please sign in to comment.