-
Notifications
You must be signed in to change notification settings - Fork 1.3k
⚠️ Add subresource apply support #3321
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1335,6 +1335,42 @@ func (sw *fakeSubResourceClient) statusPatch(body client.Object, patch client.Pa | |
| return sw.client.patch(body, patch, &patchOptions.PatchOptions) | ||
| } | ||
|
|
||
| func (sw *fakeSubResourceClient) Apply(ctx context.Context, obj runtime.ApplyConfiguration, opts ...client.SubResourceApplyOption) error { | ||
| if sw.subResource != "status" { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is different from IMHO it is better to error out rather than to silenly do the wrong thing. We could fo a follow-up to do the same in Patch for consistency (and/or implement the subresources we support through
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think tracking a follow-up would be good
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a point to the tracking issue |
||
| return errors.New("fakeSubResourceClient currently only supports Apply for status subresource") | ||
| } | ||
|
|
||
| applyOpts := &client.SubResourceApplyOptions{} | ||
| applyOpts.ApplyOpts(opts) | ||
|
|
||
| data, err := json.Marshal(obj) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal apply configuration: %w", err) | ||
| } | ||
|
|
||
| u := &unstructured.Unstructured{} | ||
| if err := json.Unmarshal(data, u); err != nil { | ||
| return fmt.Errorf("failed to unmarshal apply configuration: %w", err) | ||
| } | ||
|
|
||
| patchOpts := &client.SubResourcePatchOptions{} | ||
| patchOpts.Raw = applyOpts.AsPatchOptions() | ||
|
|
||
| if applyOpts.SubResourceBody != nil { | ||
sbueringer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| subResourceBodySerialized, err := json.Marshal(applyOpts.SubResourceBody) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to serialize subresource body: %w", err) | ||
| } | ||
| subResourceBody := &unstructured.Unstructured{} | ||
| if err := json.Unmarshal(subResourceBodySerialized, subResourceBody); err != nil { | ||
| return fmt.Errorf("failed to unmarshal subresource body: %w", err) | ||
| } | ||
| patchOpts.SubResourceBody = subResourceBody | ||
| } | ||
|
|
||
| return sw.Patch(ctx, u, &fakeApplyPatch{}, patchOpts) | ||
| } | ||
|
|
||
| func allowsUnconditionalUpdate(gvk schema.GroupVersionKind) bool { | ||
| switch gvk.Group { | ||
| case "apps": | ||
|
|
||
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.
This differs from our typical naming convention of naming these
ApplyOptionsbecause that name is already used for the embedded field. I chose to embedd the field, because there is prior art of doing that in theSubResourcePatchOptionsand it seems ergonomical to do it that way, because modifying options doesn't requier to know whether they are defined inApplyOptionsorSubResourceApplyOptions.