Skip to content

Instantly share code, notes, and snippets.

@ghostsquad
Last active June 24, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghostsquad/c92b54455ff3e4eb689662588dac2e09 to your computer and use it in GitHub Desktop.
Save ghostsquad/c92b54455ff3e4eb689662588dac2e09 to your computer and use it in GitHub Desktop.
Yaml/Json Cheatsheet
brew install jq
brew install yq
# render a helm chart to it's yaml parts
helm fetch --repo https://containous.github.io/traefik-helm-chart --untar --untardir ./charts traefik
helm template --output-dir ./manifests ./charts/traefik
# OR
helm template --output-dir ./loki-fluent-bit loki/fluent-bit
# given a large multi-document yaml file, convert it to a json array
yq r -d'*' crds.yaml --collect --tojson | jq '.' > crds.json
# convert a json array of kubernetes manifests into map
jq 'map( { (.kind + "." + .metadata.name|tostring): . } ) | add' crds.json > crds-named.json
# convert json to jsonnet (just the keys)
sed "s/\"\(\w+)\":/\1:/g" crds-named.json > crds-named.jsonnet
# convert a map to named yaml files
jsonnet -J vendor -m manifests example.jsonnet | xargs -I{} sh -c 'cat {} | yq r -P - > {}.yaml; rm -f {}' -- {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment