This repository was archived by the owner on Oct 3, 2020. It is now read-only.
Patch subresources via separate API endpoints #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Kubernetes resources are now advised to have
status
&replica
as sub-resources — especially since Kubernetes 1.16.This requires separate PATCH requests to separate endpoints, instead of passing the status as part of the main payload of the PATCH request on the resource's body — it is just ignored there (i.e. not applied to the resource).
With this PR, a kwarg named
subresource=
is added to the object's.patch()
method. The default is to use the resource' main body, unless explicitly said to patch the sub-resource.A better way would be to internally analyse the CRD's declaration, and whether some subresources are declared separately or not, and to modify the patching method to send separate API requests if the relevant sub-fields are present in the patch's body. Thos way is much more complex, and potentially implies unexpected heuristic in the API client.
The explicit way seems more straightforward — leaving the decision on what and how to patch to the developers, who also declare their CRDs with/without sub-resources.
For reference, the Kubernetes client implements this as separate patching methods:
v1api. patch_namespaced_pod_status()
instead ofv1api. patch_namespaced_pod()
(link)