Skip to content
main
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
pkg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

yamlpatch test Go Reference

This is a command line tool to apply a JSON Patch to a YAML Document preserving position and comments.

Features

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 API

Apply a patch:

yamlpatch -p '[{ "op": "replace", "jsonpath": "$.spec.template.spec.containers[0].image", "value": nginx:1.19 }]' < testdata/fixture1.yaml

Result:

# 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

About

Apply JSON Patch to YAML Document preserving positions and comments

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.