-
Couldn't load subscription status.
- Fork 48
OCPCLOUD-3172: machinesetsync: refactor to a generalized differ which can work independent of types #382
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
base: main
Are you sure you want to change the base?
Conversation
|
@chrischdi: This pull request references OCPCLOUD-3172 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/test unit |
|
@chrischdi: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
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 think this is great and a clear improvement. I have some follow-on ideas, but I would personally gladly merge this and iterate on it in the unlikely event it ever became worth it.
I shared a thought inline based on something similar we did in ORC with field indexers.
Not at all important, but I also feel that Unstructured is an internal implementation detail: e.g. the Diff method could be implemented with reflection and the signature would not change.
| differ := UnstructuredDiffer[clusterv1.MachineSetStatus]{ | ||
| customDiff: []func(a clusterv1.MachineSetStatus, b clusterv1.MachineSetStatus) ([]string, error){ | ||
| func(a, b clusterv1.MachineSetStatus) ([]string, error) { | ||
| return compareCAPIMachineSetConditions(a.Conditions, b.Conditions), nil | ||
| }, | ||
| }, | ||
| ignoreFields: [][]string{{"conditions"}}, | ||
| } |
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.
differ := UnstructuredDiffer[clusterv1.MachineSetStatus]()
differ = WithCustomDiff(differ,
"conditions",
func(x *clusterv1.MachineSetStatus) []clusterv1.Condition {return x.conditions},
compareCAPIConditions)
func compareCAPIConditions(a, b []clusterv1.Conditions) []string {
...
}WithCustomDiff unfortunately can't be a method on UnstructuredDiffer as it has an additional type argument([]clusterv1.Condition).
Advantages of this approach:
- ignoreField is a required argument of CustomDiff, removing a footgun
- compareCAPIConditions is now reusable by all types with CAPI conditions
Disadvantages:
- The argument to pull a field out is a bit ugly
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.
ignoreField is a required argument of CustomDiff, removing a footgun
Are there cases when we want to ignore fields without custom diffs no? Maybe around deprecated fields?
|
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
| "k8s.io/apimachinery/pkg/runtime" | ||
| ) | ||
|
|
||
| type UnstructuredDiffer[T any] struct { |
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.
Godoc missing
| "k8s.io/apimachinery/pkg/runtime" | ||
| ) | ||
|
|
||
| type UnstructuredDiffer[T any] struct { |
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.
If this is unstructured, why is it also generic? Does it make this simpler than using runtime.Object for the a, b arguments?
|
|
||
| diff := deep.Equal(unstructuredA, unstructuredB) | ||
| if len(diff) > 0 { | ||
| diffs["deep.Equal"] = diff |
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.
Why the deep.Equal key? Does this get exposed to end users? Is this a magic word?
| // Maybe we can also have it this way: | ||
| // differ := NewUnstructuredDiffer( | ||
| // WithIgnoreField[clusterv1.MachineSetStatus]("conditions"), | ||
| // WithCustomDiff(func(a, b clusterv1.MachineSetStatus) ([]string, error) { | ||
| // return compareCAPIMachineSetConditions(a.Conditions, b.Conditions), nil | ||
| // }), | ||
| // ) |
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 prefer this
| differ := UnstructuredDiffer[clusterv1.MachineSetStatus]{ | ||
| customDiff: []func(a clusterv1.MachineSetStatus, b clusterv1.MachineSetStatus) ([]string, error){ | ||
| func(a, b clusterv1.MachineSetStatus) ([]string, error) { | ||
| return compareCAPIMachineSetConditions(a.Conditions, b.Conditions), nil | ||
| }, | ||
| }, | ||
| ignoreFields: [][]string{{"conditions"}}, | ||
| } |
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.
ignoreField is a required argument of CustomDiff, removing a footgun
Are there cases when we want to ignore fields without custom diffs no? Maybe around deprecated fields?
No description provided.