JSON Patch由IETF在RFC 6902中规范.JavaScript Object Notation (JSON) Patch
JSON Path是描述JSON文档变化的格式. 使用它可以避免在只需要修改某一部分的时候发送整个文档内容. 当与HTTP PATCH方法混合使用的时候, 它允许在标准规范的基础上使用HTTP APIs进行部分更新.
A JSON Patch document is a JSON [RFC4627] document that represents an
array of objects. Each object represents a single operation to be
applied to the target JSON document.
The following is an example JSON Patch document, transferred in an
HTTP PATCH request:
PATCH /my/data HTTP/1.1
Host: example.org
Content-Length: 326
Content-Type: application/json-patch+json
If-Match: "abc123"
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
]
kubevirt 通过vm类型控制虚拟机启动和关闭,下面是json patch 方式修改配置的方式,启动虚拟机.
[wjh@node1 mubot]$ kl get vm
NAME AGE STATUS READY
mlcmlc0 13d Stopped False
mlcmlc1 13d Running True
mlcmlc2 13d Stopped False
[wjh@node1 mubot]$ kl get vmi
NAME AGE PHASE IP NODENAME READY
mlcmlc1 13d Running 172.17.0.18 node1 True
[wjh@node1 mubot]$ kl patch vm mlcmlc0 --type json -p '[{"op":"replace","path":"/spec/running","value":true}]'
virtualmachine.kubevirt.io/mlcmlc0 patched
[wjh@node1 mubot]$ kl get vm
NAME AGE STATUS READY
mlcmlc0 13d Starting False
mlcmlc1 13d Running True
mlcmlc2 13d Stopped False
[wjh@node1 mubot]$ kl get vmi
NAME AGE PHASE IP NODENAME READY
mlcmlc0 6m46s Running 172.17.0.17 node1 True
mlcmlc1 13d Running 172.17.0.18 node1 True
Leave a Reply