Hi I am following this doc https://github.com/kubernetes/kubernetes/blob/master/docs/devel/api-conventions.md#strategic-merge-patch for strategic-merge-patch to partially update the JSON objects using PATCH REST API. The document says that it can add or delete the object, but I have tried, whenever I add new object to existing JSON it just replaces that instead of adding new. I am trying this to modify pod definition in OpenShift 3.2. can anyone please help me how it works, probably with example. I need to use delete operation also , where I can delete the value by name.
Asked
Active
Viewed 3,190 times
6
-
Can you provide example JSON files? – eljefedelrodeodeljefe Jan 01 '17 at 23:08
-
1Please provide the JSON files you are trying to PATCH. It's easier to help or let you know where you are going wrong. :) – Nikhita Raghunath Apr 19 '17 at 17:12
1 Answers
3
As documented it depends on annotations of the types. AFAIS the strategic merge only works if patchStrategy
and patchMergeKey
are given. For example, this is the case in pod.spec.containers
and pod.spec.volumes
.
For an example you need to provide more information about the type you want to merge.

svenwltr
- 17,002
- 12
- 56
- 68
-
1Where is it "documented"? Been looking several hours for such documentation and found 0 documentation on that. All there is, is the extremely terse "documentation" (if you can call those explanations that feel like 2 half-assed sentences that) on strategic merge patches in general. I am trying to add a volume to an existing deployment through a strategic merge patch and it just won't work. How are the elements you mentioned to be adjusted for the patch to work in the explained scenario? – Akito Feb 28 '21 at 22:41
-
Probably this can help someone: https://stackoverflow.com/questions/71165168/can-someone-explain-patchesstrategicmerge – Hari Kishore Feb 18 '22 at 16:54
-
This is documented here https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md – 13013SwagR Mar 30 '23 at 16:35