Skip to content

How to use patch on custom resources? #2166

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

Closed
csviri opened this issue Apr 27, 2020 · 6 comments
Closed

How to use patch on custom resources? #2166

csviri opened this issue Apr 27, 2020 · 6 comments

Comments

@csviri
Copy link
Contributor

csviri commented Apr 27, 2020

Hi,
I would like to add / delete some attributes using patch on custom resources. However its not clear to me how this should work using current API. (In my case I would like to add a finalizer)
This is the API I try to use

MyCustomResource resource = createMyCustomResourcePatchPojo() ;
MixedOperation  resourceOperation = .... ; 
resourceOperation.inNamespace(resource.getMetadata().getNamespace())
   .withName(resource.getMetadata().getName())
   .patch(resource);

I assume this should be then a merge patch like defined here:
https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment

And in this RFC: https://tools.ietf.org/html/rfc7386

Does this mean that I should only set values that will be added / altered in the custom resource POJO? And other values should be null? But then how should I delete a field?

Thanks!

(also Is there a way to use similar to Json-P ?)

@rohanKanojia
Copy link
Member

I think you can try createOrReplace() here is an example:

podSetClient = server.getClient().customResources(podSetCrd, PodSet.class, PodSetList.class, DoneablePodSet.class);
PodSet returnedPodSet = podSetClient.inNamespace("test").createOrReplace(getPodSet());

@rohanKanojia
Copy link
Member

We have a typeless api also with which you can use plain json/HashMap to deal with Custom Resources: https://github.com/fabric8io/kubernetes-client/blob/master/doc/CHEATSHEET.md#customresource-typeless-api

@csviri
Copy link
Contributor Author

csviri commented Apr 27, 2020

@rohanKanojia the createOrReplace is what I want to avoid. Since its not a patch it can lead to "lost update problem" if I don't use optimistic locking (i.e. lock version) - what I want to also avoid here.

(Also note that, kubernetes api supports https://tools.ietf.org/html/rfc6902, which I need to use in this case since want to do additive operation on a list)

But will check the typeless api, thank you for now!

@stale
Copy link

stale bot commented Jul 26, 2020

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Jul 26, 2020
@stale stale bot closed this as completed Aug 2, 2020
@janotav
Copy link

janotav commented Jan 29, 2021

@csviri have you managed to figure out how to safely patch using this library?

@csviri
Copy link
Contributor Author

csviri commented Feb 1, 2021

@janotav no. (We took other appraoch for unrelated reasons.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants