ytt: Missing ability to include another YAML file in a short way (ie combine load + func call)
In ytt, there is the possibility to load values from files, but it does not seem that it is possible to load another YAML file from the main ytt file.
Could this be considered as an addition?
Something like this:
main.yaml
---
test: #@ include("hello.yaml")
hello.yaml
---
#@ def world()
"world"
#@ end
hello: #@ world()
the result would be:
---
test:
hello: "world"
Having a way to pass variables to the included file would be nice. What this is is basically a #@ load()
but with the function definition implicit in the included file.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 36 (33 by maintainers)
@carlosflorencio no specific date, but given more interest, i can throw in some help changing @mildred PR to get it merged.
after spending morning with @nimakaviani we have came to the following proposal:
(above follows naming from python: https://docs.python.org/3/tutorial/modules.html)
load path format:
examples covering all variations:
note that
@:common/stuff.yml
case covers the ability to include modules from packages relative to current library root (instead of supporting symlinks or../..
in paths). for exampleload("@:common/funcs.lib.yml", "common1")
would work fromapp1/config.yml
, assuming that directory structure is:this loading behaviour can also be used with
library
module fromstd
library (included viaload("@std:library", "library")
).what do you think @mildred ?
Yes, I understand, but I wanted a way to avoid having to explicitly declare the functions. I would like to have instead of
funcs.lib.yml
func.lib.yml
:without the
#@ def func1():
. The whole file would be by itself a single function.Perhaps that can be made into the
load()
builtin. So when there is no#@ def
in the loaded file, an implicit_main
function could be defined.The main template could then be:
main.yml
which would result in:
It’s just that I’m used to have include statements, and having to define functions seems a bit odd when you mean to have the whole file as a single function.
hi @mildred ,
ytt in fact allows for loading files with function definitions in other files.
Here is an example from the ytt playground with a very similar usecase to what you explained above: https://get-ytt.io/#example:example-load
https://github.com/k14s/ytt/releases/tag/v0.24.0 includes ability to use / in load statement to load files relative to library root.
correct it’s not possible to use
../
in load paths.thanks as well for letting us know that this will be helpful for your use case.
to unblock you for now, you can do the following (as prev proposed by @mildred in a different issue):
given above fs structure, you can use
--allow-symlink-destination
to allow “inside project” symlinks:Not sure if it related to that particular PR, but it makes my situation solved. What I want - is to have some “templates” or “main” set component, would place that into root folder and then reuse in each particular implementation of that component, something like:
And in each of those deployments, I would refer to common component file, like:
load("../components.lib.yaml", "deployment")
However, it seems not possible yet (tested with
ytt
0.18.0)That proposal in the comment above and related PR would solve my issue too.