策略合并 patch
对于策略性合并 patch,列表可以根据其 patch 策略进行替换或合并。 patch 策略由 Kubernetes 源代码中字段标记中的 patchStrategy 键的值指定。 例如,PodSpec 结构体的 Containers 字段的 patchStrategy 为 merge:
type PodSpec struct {...Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" ...`
策略合并 patch 操作使用默认的 patch 策略,也就是 replace。
type PodSpec struct {...Tolerations []Toleration `json:"tolerations,omitempty" protobuf:"bytes,22,opt,name=tolerations"`
JSON 合并 patch
https://erosb.github.io/post/json-patch-vs-merge-patch/
As a quick example (taken from the spec) if we have the following document:
{"a": "b","c": {"d": "e","f": "g"}}
Then we can run the following patch on it:
{"a":"z","c": {"f": null}}
which will change the value of "a" to "z" and will delete the "f" key.
JSON patch
As a short example lets consider the following JSON document:
{"users" : [{ "name" : "Alice" , "email" : "alice@example.org" },{ "name" : "Bob" , "email" : "bob@example.org" }]}
We can run the following patch on it, which changes Alice’s email address then adds a new element to the array:
[{"op" : "replace" ,"path" : "/users/0/email" ,"value" : "alice@wonderland.org"},{"op" : "add" ,"path" : "/users/-" ,"value" : {"name" : "Christine","email" : "christine@example.org"}}]
The result will be:
{"users" : [{ "name" : "Alice" , "email" : "alice@wonderland.org" },{ "name" : "Bob" , "email" : "bob@example.org" },{ "name" : "Christine" , "email" : "christine@example.org" }]}
