-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠️ 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
base: main
Are you sure you want to change the base?
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,38 @@ 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" { | ||
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 |
||
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 { | ||
subResourceBody := &unstructured.Unstructured{} | ||
if err := json.Unmarshal(data, 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
ApplyOptions
because that name is already used for the embedded field. I chose to embedd the field, because there is prior art of doing that in theSubResourcePatchOptions
and it seems ergonomical to do it that way, because modifying options doesn't requier to know whether they are defined inApplyOptions
orSubResourceApplyOptions
.