Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render multiple configs to single template #17

Open
dibi-codes opened this issue Apr 4, 2019 · 2 comments
Open

Render multiple configs to single template #17

dibi-codes opened this issue Apr 4, 2019 · 2 comments

Comments

@dibi-codes
Copy link

Maybe i've missed something but I'm looking for a way to do a rendering for multiple input files.

Example:
My template is deployment.yml. I have multiple config files in one directory config1.yml and config2.yml.

deployment.yml contains:

# kubetpl:syntax:go-template

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}

config1.yml contains:

NAME: a

config2.yml contains:

NAME: b

What I expect to happen:

$ kubetpl r templates/deployment.yml -i configs/*.yml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: a
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: b

what actually happens:

$ kubetpl r templates/deployment.yml -i configs/*.yml

Resource "kind" is missing 

Is there any way to accomplish this scenario?

@dibi-codes dibi-codes changed the title Render multiple ENV to for single template Render multiple configs to single template Apr 4, 2019
@shyiko
Copy link
Owner

shyiko commented Apr 4, 2019

Hey Daniel,

The reason kubetpl r templates/deployment.yml -i configs/*.yml isn't working is shell expansion. kubetpl r templates/deployment.yml -i configs/*.yml is interpreted (by the shell) as kubetpl r templates/deployment.yml -i configs/config1.yml configs/config2.yml (not kubetpl r templates/deployment.yml -i configs/config1.yml -i configs/config2.yml) and so kubetpl thinks it's got 2 templates to render - templates/deployment.yml and configs/config2.yml.

On a side note, I do agree the error is confusing (I'll keep this ticket open until the error message is updated to include the path to a file that failed to render).

Getting back to the original question, kubetpl merges data from all -i <file> and so the only way to render the same template multiple times given different configs is (unfortunately) to

for cfg in configs/*.yml; do kubetpl r templates/deployment.yml -i $cfg; done

@dibi-codes
Copy link
Author

OK, got you. Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants