-
Notifications
You must be signed in to change notification settings - Fork 893
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
Implementing the AggregateStatus hook #1253
Conversation
cc @XiShanYongYe-Chang |
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.
Nice job! Thanks 👍
76858ff
to
474021b
Compare
All comments addressed, PTAL @RainbowMango @XiShanYongYe-Chang 56cd871 /hold |
9e85728
to
a051e0d
Compare
a051e0d
to
fb463b2
Compare
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.
Thanks, LGTM
/cc @RainbowMango
fb463b2
to
81c1c24
Compare
/hold cancel |
pkg/detector/detector.go
Outdated
newStatus, _, err := unstructured.NestedFieldNoCopy(newObj.Object, "status") | ||
if err != nil { | ||
return err | ||
} | ||
oldStatus, _, err := unstructured.NestedFieldNoCopy(obj.Object, "status") | ||
if err != nil { | ||
return err | ||
} |
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.
We don't need to parse the .status
, we can just compare the obj
and newObj
, since the Interpreter
won't change anything but .status
, so if obj
!= newObj
means the status has been aggregated
, then we do update
operation.
In addition, we seem can't assume there is a .status
field. See InterpretStatus.
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.
Something like this:
if reflect.DeepEqual(obj, newObj) {
klog.V(3).Infof("ignore update resource(%s/%s/%s) status as up to date", resource.Kind, resource.Namespace, resource.Name)
return nil
}
Maybe we can't use retry.RetryOnConflict
for this case,
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.
Maybe we can't use retry.RetryOnConflict for this case
What is this for? I can compare two objects directly, but it doesn't seem to affect the use of RetryOnConflict
, is it because the newObj
may also not have status?
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 it doesn't seem to affect the use of RetryOnConflict, is it because the newObj may also not have status?
As after we get
a new copy of the object, we have to set the status, do you mean to call the webhook
again in retry
?
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.
Nope, Is there a problem with the current retry 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.
The thing is
if err = unstructured.SetNestedField(obj.Object, newStatus, "status"); err != nil {
return err
}
Personally, I'm hesitant to assume there is a .status
filed(Maybe no problem for 99.9% cases).
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 am not so familiar with SetNestedField
, but by looking at the source code, if the original object does not have a status field, it should not report an error when setting for it, it will only report an error if the value is not compliant.
The workload object initially had no status field, but SetNestedField
added it, as expected.
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 mean we can't assume all resource's status represent by .status
, that might be .status-xxx
or something else. That's why we design InterpretStatus
operation for.
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 get your point now, it seems we can't use retry in this case, let's return the error directly to trigger its resync.
examples/customresourceinterpreter/webhook/app/workloadwebhook.go
Outdated
Show resolved
Hide resolved
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.
Good Job! @iawia002
Generally looks good to me. Just two nits.
81c1c24
to
b83d53e
Compare
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.
/lgtm
Just the nolint
need to be clarified.
Signed-off-by: Xinzhao Xu <[email protected]>
b83d53e
to
2f55e6c
Compare
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango 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 |
Signed-off-by: Xinzhao Xu [email protected]
What type of PR is this?
/kind feature
What this PR does / why we need it:
Part of #1237
This patch implements the
AggregateStatus
hook, check resource interpreter webhook proposal for more info.The original code to modify the status of core resources such as
Deployment
andJob
has been changed to use default interpreters. After the update, the status collection of the sample deployment is the same as before:for custom resources, users only need to implement the corresponding webhook and return the patch data:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: