deepequal check in helper.CreateOrUpdateWork() always return false, because resource.MarshalJSON() will add \n at the end of JSON #5938
Labels
kind/bug
Categorizes issue or PR as related to a bug.
What happened:
deepequal check in
helper.CreateOrUpdateWork()
always return false, becauseresource.MarshalJSON()
will add\n
at the end of JSON, but the workloads read from work.Spec.Workload.Manifests never have this\n
. So everytime this function is called, an update operation will occur.Fortunately, the same thing doesn't happen to work-status-controller, rb/crb-status-controller. Although they are both using
DeepEqual()
onruntime.RawExtension
, but the byte slices are obtained from resource interpret webhook.What you expected to happen:
remove unecessary update operations.
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
@snowplayfire found this, I'm just providing some possible fixes here. Many thanks to her, I sincerely hope she has a happy holiday.
This is the root cause why binding controller can’t use
DeepEqual()
to skip the update operation when calling theensureWork()
. But for deepequal to work, we need another PR to copy part of the karmada webhook logic to the update operation, which I will complete as soon as possible.For fixing this issue, one way is just need one line: replace
resource.MarshalJSON()
withjson.Marshal(resource)
, it could work. #5939But deepequal checks should be used in semantic scenarios, not to judge byte streams. Therefore, if we want to use semantic deepequal checking to fix it, we need to directly judge the unmarshaled workload read from work. #5940
Environment:
kubectl-karmada version
orkarmadactl version
):The text was updated successfully, but these errors were encountered: