Skip to content

Instantly share code, notes, and snippets.

@pivotaljohn
Last active October 31, 2022 22:05
Show Gist options
  • Save pivotaljohn/08f869ad19ce7e1ebdf61ebc9bcd2a6b to your computer and use it in GitHub Desktop.
Save pivotaljohn/08f869ad19ce7e1ebdf61ebc9bcd2a6b to your computer and use it in GitHub Desktop.
Transform a stream of YAML documents
---
field1: red1
field2:
field2a: red 2.a
filed2b: red 2.b
field3:
- red 3.a
- red 3.b
---
field1: green1
field2:
field2a: green 2.a
filed2b: green 2.b
field3:
- green 3.a
- green 3.b
---
field1: blue1
field2:
field2a: blue 2.a
filed2b: blue 2.b
field3:
- blue 3.a
- blue 3.b
#@ load("@ytt:yaml", "yaml")
#@ load("@ytt:data", "data")
#@ def transform(old):
apiVersion: v1alpha1
kind: NewHotness
metadata:
name: #@ old["field1"]
annotations: #@ old["field2"]
spec:
containers:
#@ for app in old["field3"]:
- name: #@ app
image: #@ "{}:latest".format(app)
#@ end
#@ end
#@ old_docs_data = data.read("old-docs.yamldata").split("\n---\n")
#@ for doc_data in old_docs_data:
#@ if doc_data == "": continue
--- #@ transform(yaml.decode(doc_data))
#@ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment