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 deep equal check failure on objects with runtime.RawExtension. #5940

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zach593
Copy link
Contributor

@zach593 zach593 commented Dec 11, 2024

What type of PR is this?
/kind bug

What this PR does / why we need it:
see #5938

Which issue(s) this PR fixes:
Fixes #5938

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 11, 2024
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 11, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 27.65957% with 34 lines in your changes missing coverage. Please review.

Project coverage is 48.15%. Comparing base (a6df137) to head (a59f918).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
pkg/util/equality.go 33.33% 23 Missing and 3 partials ⚠️
cmd/agent/app/agent.go 0.00% 4 Missing ⚠️
cmd/controller-manager/app/controllermanager.go 0.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5940      +/-   ##
==========================================
+ Coverage   48.09%   48.15%   +0.06%     
==========================================
  Files         663      665       +2     
  Lines       54769    54850      +81     
==========================================
+ Hits        26340    26415      +75     
+ Misses      26719    26717       -2     
- Partials     1710     1718       +8     
Flag Coverage Δ
unittests 48.15% <27.65%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@zach593 zach593 changed the title fix deep equal check failure in CreateOrUpdateWork(), by change the way we check it. [WIP]fix deep equal check failure in CreateOrUpdateWork(), by change the way we check it. Dec 11, 2024
@karmada-bot karmada-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 11, 2024
@zach593 zach593 changed the title [WIP]fix deep equal check failure in CreateOrUpdateWork(), by change the way we check it. [WIP]fix deep equal check failure on objects with runtime.RawExtension. Dec 12, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign whitewindmills for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 12, 2024
@zach593 zach593 changed the title [WIP]fix deep equal check failure on objects with runtime.RawExtension. fix deep equal check failure on objects with runtime.RawExtension. Dec 12, 2024
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 12, 2024
Comment on lines +63 to +69
var aObj, bObj unstructured.Unstructured
err := aObj.UnmarshalJSON(a.Raw)
if err != nil {
return false
}
err = bObj.UnmarshalJSON(b.Raw)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider the case where a.Raw is nil or an empty byte array?

	obj1 := &workv1alpha1.Work{
		Spec: workv1alpha1.WorkSpec{
			Workload: workv1alpha1.WorkloadTemplate{Manifests: []workv1alpha1.Manifest{{RawExtension: runtime.RawExtension{Raw: []byte{}}}}},
		},
	}
	obj2 := &workv1alpha1.Work{
		Spec: workv1alpha1.WorkSpec{
			Workload: workv1alpha1.WorkloadTemplate{Manifests: []workv1alpha1.Manifest{{RawExtension: runtime.RawExtension{Raw: nil}}}},
		},
	}
	checker := equality.Semantic.Copy()
	_ = RegisterEqualityCheckFunctions(&checker)
	fmt.Println(equality.Semantic.DeepEqual(obj1, obj2)) #true
	fmt.Println(checker.DeepEqual(obj1, obj2)) #false

Copy link
Contributor

Choose a reason for hiding this comment

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

How about

Suggested change
var aObj, bObj unstructured.Unstructured
err := aObj.UnmarshalJSON(a.Raw)
if err != nil {
return false
}
err = bObj.UnmarshalJSON(b.Raw)
if err != nil {
if (a.Raw == nil || len(a.Raw) == 0) != (b.Raw == nil || len(b.Raw) == 0) {
return false
}
if a.Raw == nil || len(a.Raw) == 0 {
return true
}
var aObj, bObj unstructured.Unstructured
err := aObj.UnmarshalJSON(a.Raw)
if err != nil {
return false
}
err = bObj.UnmarshalJSON(b.Raw)
if err != nil {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
4 participants