con2 / emrichen

A Template engine for YAML & JSON
MIT License
107 stars 11 forks source link

!Loop - without a list #31

Closed hjanuschka closed 5 years ago

hjanuschka commented 5 years ago

i am trying to render multiple deployments based on a variable

vars.yaml

backend_mutations:
  - name: backend
    command: /run.sh
    replicas: 1
  - name: backend-editors
    command: /run.sh
    replicas: 1
  - name: backend-cron
    command: /cron.sh
    replicas: 1

template.yaml (redacted the rest of the deployment spec.)

!Loop
  over: !Var backend_mutations
  as: backend
  index_as: id
  template:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: !Lookup backend.name
      labels:
        krn: !Lookup backend.name

the problem is that !Loop produces a list. which is not apply'able to K8s.

ideally i would like to generate a single output file with multiple yaml files in it. seperated by ---

like my supposed output would be like:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  labels:
    krn: backend
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-editors
  labels:
    krn: backend-editors
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-cron
  labels:
    krn: backend-cron
---

is there anything i am missing - or is it currently not possible?

akx commented 5 years ago

This would definitely be useful! The root issue is that a single emrichenable template file itself could contain more than one YAML document, which would be handled correctly at present (i.e. emitted as multiple YAML documents in a single file), but that doesn't help in this case.

The patch should be pretty simple to implement, though. Please hold šŸ˜„

japsu commented 5 years ago

In case of k8s you can use kind: List. But I agree emrichen should support this.

On Thu, 4 Jul 2019 at 10.18, Aarni Koskela notifications@github.com wrote:

This would definitely be useful! The root issue is that a single emrichenable template file itself could contain more than one YAML document, which would be handled correctly at present (i.e. emitted as multiple YAML documents in a single file), but that doesn't help in this case.

The patch should be pretty simple to implement, though. Please hold šŸ˜„

ā€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/con2/emrichen/issues/31?email_source=notifications&email_token=AAA2WVN2CFIWRGICLN7F6EDP5WP3DA5CNFSM4H5UBVVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZGRU7A#issuecomment-508369532, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA2WVKWSXGQFNU5RZFH3BLP5WP3DANCNFSM4H5UBVVA .

-- Santtu Pajukanta

hjanuschka commented 5 years ago

@japsu i couldnt get the "Kind" list to work, "kubectl apply" refused the file. anyway can you review/merge/release #32 ? ā¤ļø thx for all your effort you are putting into this project šŸ¤š

hjanuschka commented 5 years ago

i succesfully avoided to get into python the last 20 years! can someone tell me how to run it locally so i can give the #32 a try?

hjanuschka commented 5 years ago

pip3 install git+https://github.com/con2/emrichen.git@multi-doc

tried it - works perfect

akx commented 5 years ago

32 was merged into master, so closing :)

For future readers of this thread, the change required is as_documents: true to the !Loop tag, e.g.

!Loop
  over: !Var backend_mutations
  as: backend
  index_as: id
  as_documents: true
  template:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: !Lookup backend.name
      labels:
        krn: !Lookup backend.name
akx commented 5 years ago

@hjanuschka Released in Emrichen 0.2.2 ā€“ you can just pip3 install -U emrichen :)