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: correct plugins config comparison #93

Merged
merged 4 commits into from
May 27, 2024

Conversation

GGabriele
Copy link
Collaborator

This commit fixes a bug with the way Plugins config are compared: when unsorted nested arrays are present, reflect.DeepEqual considers the equal unsorted arrays as unequal, triggering the plugin update and showing misleading diffs.

This commit is introducing a few helper functions to recursively sort arrays within the Kong Plugins configs.

Summary

SUMMARY_GOES_HERE

Full changelog

  • [Implement ...]
  • [Fix ...]

Issues resolved

Fix #XXX

Documentation

Testing

  • Unit tests
  • E2E tests
  • Manual testing on Universal
  • Manual testing on Kubernetes

This commit fixes a bug with the way Plugins config
are compared: when unsorted nested arrays are present,
`reflect.DeepEqual` considers the equal unsorted arrays
as unequal, triggering the plugin update and showing
misleading diffs.

This commit is introducing a few helper functions to
recursively sort arrays within the Kong Plugins configs.
@GGabriele GGabriele requested a review from a team May 22, 2024 08:58
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 41.16%. Comparing base (ff4cfa3) to head (e7654d4).

Files Patch % Lines
pkg/state/types.go 85.71% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   41.02%   41.16%   +0.14%     
==========================================
  Files          74       74              
  Lines       10760    10795      +35     
==========================================
+ Hits         4414     4444      +30     
- Misses       5886     5890       +4     
- Partials      460      461       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 558 to 575
// Helper function to sort a slice of interface{}
func sortInterfaceSlice(slice []interface{}) []interface{} {
// Convert []interface{} to []string for sorting
strSlice := make([]string, len(slice))
for i, v := range slice {
strSlice[i] = fmt.Sprintf("%v", v)
}

sort.Strings(strSlice)

// Convert back to []interface{}
sortedSlice := make([]interface{}, len(strSlice))
for i, v := range strSlice {
sortedSlice[i] = v
}

return sortedSlice
}
Copy link
Member

Choose a reason for hiding this comment

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

How about using a type that can be sorted and thus not allocating unnecessarily?

Something like this: d7c9b78

WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like a nice improvement!

Copy link
Member

Choose a reason for hiding this comment

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

Pushed it directly to this PR: d7c9b78.

PTAL

@GGabriele GGabriele merged commit 52a75e3 into main May 27, 2024
42 checks passed
@GGabriele GGabriele deleted the fix/plugin-config-diff-nested-arrays branch May 27, 2024 12:09
GGabriele added a commit to Kong/deck that referenced this pull request May 27, 2024
GGabriele added a commit to Kong/deck that referenced this pull request May 27, 2024
GGabriele added a commit to Kong/deck that referenced this pull request May 27, 2024
GGabriele added a commit to Kong/deck that referenced this pull request May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants