- 
                Notifications
    
You must be signed in to change notification settings  - Fork 180
 
Fix reusing merge objects for patch without copying #34
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
Conversation
| ctx, | ||
| latest.RuntimeObject(), | ||
| client.MergeFrom(desired.RuntimeObject()), | ||
| latest.RuntimeObject().DeepCopyObject(), | 
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 intentionally did not use the DeepCopyObject() here and I hope this does not introduce the exception that underlying object has been changed.
The doc of this method says that pass the pointer of the object so that changes applied from patch can be reflected back. If we use .DeepCopyObject() then latest will not have the changes reflected back in latest object.
if this new way works, I may have misunderstood the working. Can you share your delve logs to help my understanding?
Also you will have to update the unit tests to incorporate this new DeepCopyObject method.
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.
Do we really need to DeepCopyObject() the latest here?
| 
           /approve  | 
    
| 
           @RedbackThomson nice detective job! /lgtm  | 
    
| 
           [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, RedbackThomson, vijtrip2 The full list of commands accepted by this bot can be found here. The pull request process is described here 
Needs approval from an approver in each of these files:
 
      
 Approvers can indicate their approval by writing   | 
    
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 learned from @RedbackThomson that he had had private conversations with @vijtrip2 and @a-hilaly about this where he explained that the reason his code works is because in the original code, the runtime object pointer that is passed to patchResourceMetadataAndSpec ends up being modified by MergeFrom so that the Status struct of both the latest and desired runtime object pointers are identical, which causes patchResourceStatus to not actually patch anything.
I'm saying this PR needs changes because this is NON-obvious and therefore requires a code comment explaining exactly WHY we use DeepCopyObject here. Otherwise, I guarantee that in 3 months, when one of us goes looking at this code, one of us will be like "oh, this can be sped up by removing DeepCopyObject and boom, we'll be back in the same bug situation.
| 
           Here are logs which prove the effect I've described above: Printing on the first reconcile loop 
 Continuing to the next reconcile loop: Here the  After the changes in this PR the result is: Now you can see   | 
    
I was seeing an issue where there was a delta in the spec, but it was never being applied back to the object. I tracked down that the
latestobject returned fromsdkFindwas correct, but the patch was not being applied.When using the method that patches both spec and status, changes to the
latestwere being applied in the spec, but not in the status. The root cause of this is that theclient.MergeFromis overriding thestatusfields when merging thespecwithdesired. Therefore after patching the specdesired == latest. This patch ensures that we copy thelatestobject as part of patching so as to not override changes when usingclient.MergeFrom.