yamlpatch

This is a command line tool to apply a JSON Patch to a YAML Document preserving position and comments.
Features
- Support both JSON Pointer and JSON Path (depends on vmware-labs/yaml-jsonpath)
- Passed the conformance tests of JSON Patch
- Single binary
Note: currently only op=replace mode is implemented
Getting Started
TODO: install
Example: Replace a field in Kubernetes YAML
Input:
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3 # at least 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
- name: envoy
image: envoyproxy/envoy:v1.16.2
args:
- --bootstrap-version
- "3" # required for v3 APIApply a patch:
yamlpatch -p '[{ "op": "replace", "jsonpath": "$.spec.template.spec.containers[0].image", "value": nginx:1.19 }]' < testdata/fixture1.yamlResult:
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3 # at least 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19
- name: envoy
image: envoyproxy/envoy:v1.16.2
args:
- --bootstrap-version
- "3" # required for v3 API