Skip to content
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

How to update or patch a k8s resource ? #2701

Closed
AllenZMC opened this issue Dec 30, 2020 · 4 comments · Fixed by #2975
Closed

How to update or patch a k8s resource ? #2701

AllenZMC opened this issue Dec 30, 2020 · 4 comments · Fixed by #2975
Assignees

Comments

@AllenZMC
Copy link

AllenZMC commented Dec 30, 2020

How to update or patch a k8s resource ? For example, pod or service , etc.

@AllenZMC AllenZMC changed the title How to update or patch a k How to update or patch a k8s resource ? Dec 30, 2020
@rohanKanojia
Copy link
Member

rohanKanojia commented Dec 30, 2020

Patching

We support full resource patching like this:

client.pods().inNamespace(namespace).withName(podName).patch(updatedPod);

We do have plans to support Strategic merge/JSON patches in upcoming releases(#2645)

Update

Updating can be done something like this:

client.pods().inNamespace("default").withName("foo")
     .edit()
         .editMetadata().addToAnnotations("new", "update").endMetadata()
     .done();

Note: This has been changed in 5.x versions of client, See Migration guide

@AllenZMC
Copy link
Author

Thanks! @rohanKanojia

@AllenZMC
Copy link
Author

Create or Replace some Pod with some existing object: client.pods().inNamespace("default").createOrReplace(aPod)
What does this mean and when is it used?

@rohanKanojia
Copy link
Member

createOrReplace() somewhat similar to kubectl apply, but there is a difference. It doesn't ignore PUT when you try to issue createOrReplace() multiple times on a same resource (#2454 ). You would want to use it for creating resources if you're not sure if it already exists in the cluster not.

@rohanKanojia rohanKanojia self-assigned this Apr 7, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 8, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 8, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 9, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 16, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 22, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 27, 2021
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 27, 2021
+ Allow option to configure PatchType in patch operation
+ Use MediaType in PatchType enum + Add merge-patch+json example
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 27, 2021
+ Allow option to configure PatchType in patch operation
+ Use MediaType in PatchType enum + Add merge-patch+json example
manusa pushed a commit that referenced this issue Apr 28, 2021
+ Allow option to configure PatchType in patch operation
+ Use MediaType in PatchType enum + Add merge-patch+json example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants