-
Notifications
You must be signed in to change notification settings - Fork 18
Add custom cmp.Options when comparing k8s objects #486
Conversation
fix 484 Signed-off-by: Siva Kommuri <[email protected]>
I am unable to assign. Requesting feedback from @squeedee @mamachanko @scothis |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #486 +/- ##
=======================================
Coverage 61.03% 61.03%
=======================================
Files 27 27
Lines 2556 2556
=======================================
Hits 1560 1560
Misses 909 909
Partials 87 87 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recognize your need for working with APIs that reconciler-runtime is not yet appreciatively compatible with! iirc you are working with https://pkg.go.dev/istio.io/client-go/pkg/apis/networking/v1beta1#DestinationRule and https://pkg.go.dev/istio.io/client-go/pkg/apis/networking/v1beta1#WorkloadEntry in particular, aren't you?
In general terms, I am not in favour of a global option. Rather I think we should solve this local to the reconciler. I am not saying that we should revive SemanticEquals
(see #266), but it's the level of API I have in mind.
Nonetheless, which particular CmpOptions
would you plan to set? I am wondering if those would be candidates to added instead. It's not that uncommon to work with APIs that have protobuf integration. Are looking to set different CmpOptions
for tests and production?
It's not relevant yet and I don't ask you to provide those, but tests and docs would help understand the wider context.
I generally agree with @mamachanko about avoiding globals. For the non-test code, the diff is only used for log statements. If there is a way to ignore all unexpected fields, we should use that (I'm not sure there is, at least not built-in). While I think we should open up cmp options to be user configurable, I personally find depending on a third party API to be an anti-pattern. In controllers I've created that use external apis (outside of the built-in k8s types) I'll create a copy of those types that I control that mirrors the API shape. This not only avoids issues with how the types are defined, but also avoids dependency hell by not pulling in the all the dependencies of that API package. The k8s ecosystem has trouble not making breaking changes in point releases that cause the entire ecosystem to be on either one side of that break or the other. The fewer dependencies you have, the easier it is to upgrade past that breaking change. |
Thank you for the feedback. In order to accommodate these types using this fix , I am able to move on by doing the following:
and when I need to use SemanticEquals (irrespective of this PR) , I have been doing this:
I am happy to provide test cases and additional documentation to get this MR merged provided this is the fix we want. Which at this point, it seems to me we want to go in a different direction. Please advise. |
Hi folks, requesting feedback for next steps |
Inspired by @scothis's points, how about the following:
|
This fix allows adding custom comparator options and is especially useful when non standard k8s objects are used and may require custom comparators.
Resolves #484