Skip to content

Commit

Permalink
fix(crud): detect operation correctly
Browse files Browse the repository at this point in the history
fixes a bug that was introduced in
e72f4c2 where noops were still detected
as updates. That happened because of a check happening in plugin.go that
detected the crud operation based on a diff.
When done without considering default/auto fields, this check would see
differences where there were none. This resulted in unnecessary updates
to the DB and wrong diff strings during `sync` and `diff`.

This commit adds defaults/auto fields to the configuration used for that
diff.
  • Loading branch information
samugi committed Aug 28, 2024
1 parent 16b5cf1 commit 582099a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/types/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func NewEntity(t EntityType, opts EntityOpts) (Entity, error) {
kind: entityTypeToKind(Plugin),
currentState: opts.CurrentState,
targetState: opts.TargetState,
kongClient: opts.KongClient,
},
}, nil
case Consumer:
Expand Down
10 changes: 9 additions & 1 deletion pkg/types/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type pluginDiffer struct {
kind crud.Kind

currentState, targetState *state.KongState
kongClient *kong.Client
}

func (d *pluginDiffer) Deletes(handler func(crud.Event) error) error {
Expand Down Expand Up @@ -174,8 +175,15 @@ func (d *pluginDiffer) createUpdatePlugin(plugin *state.Plugin) (*crud.Event, er
}
currentPlugin = &state.Plugin{Plugin: *currentPlugin.DeepCopy()}
// found, check if update needed
// before checking the diff, fill in the defaults
schema, err := d.kongClient.Plugins.GetFullSchema(context.TODO(), plugin.Name)
pluginWithDefaults := &state.Plugin{Plugin: *plugin.DeepCopy()}
err = kong.FillPluginsDefaultsAutoFields(&pluginWithDefaults.Plugin, schema, &currentPlugin.Plugin)

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / test

undefined: kong.FillPluginsDefaultsAutoFields (typecheck)

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / test

undefined: kong.FillPluginsDefaultsAutoFields) (typecheck)

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / integration-tests / integration (kong:2.8)

undefined: kong.FillPluginsDefaultsAutoFields

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / integration-tests / integration (kong/kong:master)

undefined: kong.FillPluginsDefaultsAutoFields

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / enterprise-integration-tests / integration (kong/kong-gateway:3.4)

undefined: kong.FillPluginsDefaultsAutoFields

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / enterprise-integration-tests / integration (kong/kong-gateway:3.5)

undefined: kong.FillPluginsDefaultsAutoFields

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / enterprise-integration-tests / integration (kong/kong-gateway:3.7)

undefined: kong.FillPluginsDefaultsAutoFields

Check failure on line 181 in pkg/types/plugin.go

View workflow job for this annotation

GitHub Actions / enterprise-integration-tests / integration (kong/kong-gateway-dev:latest)

undefined: kong.FillPluginsDefaultsAutoFields
if err != nil {
return nil, fmt.Errorf("failed processing auto fields: %w", err)
}

if !currentPlugin.EqualWithOpts(plugin, false, true, false) {
if !currentPlugin.EqualWithOpts(pluginWithDefaults, false, true, false) {
return &crud.Event{
Op: crud.Update,
Kind: d.kind,
Expand Down

0 comments on commit 582099a

Please sign in to comment.