Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Feature: Ability to take a single YAML document from a YAML file, and loop (via templating) to create additional YAML documents from it #22

Open
ahuffman opened this issue May 4, 2021 · 2 comments
Labels
enhancement New feature or request v0.7.0

Comments

@ahuffman
Copy link
Contributor

ahuffman commented May 4, 2021

As a user, I have a collection of iterable values, a single document YAML file, and I would like to iterate over the initial YAML document (treated as a starting point/template) to generate 1 or many new YAML documents to be output to the YAML file from the iterable values.

This could either be a new action or simply a method to use a source document within a YAML file.

@ahuffman
Copy link
Contributor Author

ahuffman commented May 11, 2021

This is an idea I have floating around on how to potentially solve this particular issue, and is open to feedback and discussion:

Given values passed in with either the -d or -v parameters:

# values can be used for templating or iterable document creation
some:
  things:
    - name: thing1
      contents:
        - stuff
      meta:
        annotations:
          some: thing
    - name: thing2
      contents:
        - moreStuff
        - andEvenMoreStuff
       meta:
        annotations:
          another: thing

Given a yaml file (/my/template/file.yaml):

# scaffolded yaml file for example, but could include real data to start, which would allow for yot actions to do more here
metadata:
  annotations: {}
  name: ""
contents: []

Given an instruction file API schema:

# In this example, only the 'value' field can be populated. 
yamlFiles:
  - name: Generate a new yaml file with multiple documents using another file as a base template
    path: /my/template/file.yaml
    withIterable: some.things
    outputPath: newThings.yaml
    overlays:
      - name: populate annotations
        query: metadata.annotations
        value: meta.annotations
        action: replace
      - name: populate name
        query: metadata.name
        value: name
        action: replace
      - name: populate contents
        query:  contents
        value: contents
        action: replace

This would generate "newThings.yaml" with multiple yaml documents as such:

metadata:
  annotations:
    some: thing
  name: thing1
contents:
  - stuff
---
metadata:
  annotations:
    another: thing
  name: thing2
contents:
  - moreStuff
  - andEvenMoreStuff

Real-world example for this use-case is creating many storage-classes in a kubernetes cluster from a collection of iterable values. This is one example where templating yaml files works well, but this would close the gap.

@lander2k2
Copy link

FWIW the storage class use case totally makes sense to me. Not everyone will need this feature... but for those that do it could prevent them having to use another tool just to fill this gap.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request v0.7.0
Projects
None yet
Development

No branches or pull requests

2 participants