I am trying to understand how to use PATCH apis available for various objects. I can't find any documentation for that. Also, what are the benefits of using PATCH over UPDATE api?
UPDATE will essentially rewrite the entire object according to what you've provided it, so anybody who might have submitted a change after you've opened the file but before you've submitted your change will have their change overwritten by your UPDATE. Currently, it seems like you have to generate your own patch strings (and convert them to byte arrays) in the same way you'd pass in a patch string to kubectl patch.
https://github.com/CrunchyData/postgres-operator
in that project, I was able to code some different forms of patch, hope that helps.
Thanks for the replies! I am exploring an idea to auto generate json patch and apply the JSON patch type. I have a working demo: https://github.com/tamalsaha/patch-demo/blob/master/main.go
What do you think about this?
This might also be of use: https://github.com/kubernetes/apimachinery/blob/master/pkg/util/strategicpatch/patch.go
I looked at the methods. It does not seem very useful for my case.
My use-case is, I have the full object (Deployment/RC). Then I want to add a side-car to it. If I do just update, sometimes it fails due to conflict. In my demo, I create the modified object as I would do for UPDATE calls. Then use mattbaird/jsonpatch to create a patch from the original struct and modified struct. Then I send the patch to Kube api. So, as far as my code is concerned, it never deals with []byte directly.
I have put together a util lib for this https://github.com/appscode/kutil, in case anyone is interested ,
Most helpful comment
Thanks for the replies! I am exploring an idea to auto generate json patch and apply the JSON patch type. I have a working demo: https://github.com/tamalsaha/patch-demo/blob/master/main.go
What do you think about this?