-
Notifications
You must be signed in to change notification settings - Fork 181
Reset the object status after patching resource metadata & spec. #48
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
Reset the object status after patching resource metadata & spec. #48
Conversation
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.
not clean as mentioned in the description but ok for now
Some log artifacts showing that
the call looks like err = r.kc.Patch(
ctx,
latest.RuntimeObject(),
client.MergeFrom(clearedDesired.RuntimeObject()),
)
I have verified by creating diff that
|
latestCopy := latest.DeepCopy() | ||
err = r.kc.Patch( | ||
ctx, | ||
latest.RuntimeObject(), |
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.
could we accomplish the same thing as this PR's changes by just doing this here?
latest.RuntimeObject().DeepCopy(),
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.
The SetStatus()
method in AWSResource interface uses AWSResource
as parameter type. If we do the above we will need to create another method that can accept runtime.Object and update the status using it.
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.
But what I'm saying is that you wouldn't need to call latest.SetStatus()
below if latest.RuntimeObject().DeepCopy()
is used here because the latest
variable would not be mutated, and you are calling latest.SetStatus(latestCopy)
below to "undo" that mutation.
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.
And if we do latest.RuntimeObject().DeepCopy() inside kc.Patch, then we will run into resource version and optimistic lock issues we saw earlier.right? @RedbackThomson
the latest variable would not be mutated
I believe we want metadata of latest to be mutated after kc.Patch call.
/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 |
Description of changes: Commit#1 - Adds the implementation of AWSResource.DeepCopy() method. aws-controllers-k8s/runtime#48 Commit#2 - Fixes the patching bug in lateInitialize code to unblock sagemaker team - BUG: rm.LateInitialize() method was adding lateInitialized fields to the same object passed in the parameter and returning as output. ```go lateInitializedLatest, err := rm.LateInitialize(ctx, latest) rlog.Exit("rm.LateInitialize", err) // Always patch after late initialize because some fields may have been initialized while // others require a retry after some delay. // This patching does not hurt because if there is no diff then 'patchResourceMetadataAndSpec' // acts as a no-op. if ackcompare.IsNotNil(lateInitializedLatest) { patchErr := r.patchResourceMetadataAndSpec(ctx, latest, lateInitializedLatest) // Throw the patching error if reconciler is unable to patch the resource with late initializations if patchErr != nil { err = patchErr } } ``` - Since lateInitializedLatest and latest were same object, above `patchResourceMetadataAndSpec` call sees no diff and does not patch lateInitialized fields into etcd. - This PR solves the bug by adding lateInitialized fields in a copy of latest and returning that copy (without modifying latest) By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description of changes:
DeepCopy
method in AWSResource interface(a) Passing empty status in the base parameter during
kc.Patch()
call, but thekc.Patch
call resets the status by reading it from etcd.kc.Patch
operation better, we can improve on it.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.