Skip to content

Commit e2cbddd

Browse files
author
Hannes Hörl
committed
Document different ways to consume inputs
Also laying out how e.g. process substitution is handled, and why one might need to override the file name for that. Signed-off-by: Hannes Hörl <hannes.hoerl+github@snowreporter.com>
1 parent c9812eb commit e2cbddd

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Inputs
3+
---
4+
5+
ytt supports different input sources:
6+
7+
- Files & Directories
8+
- Those are provided via the `-f`/`--file` flag
9+
10+
- ytt uses the file's name for its internal representation
11+
12+
If you have a tree like
13+
```terminal
14+
$ tree .
15+
.
16+
├── dir1
17+
│   └── some.yaml
18+
└── dir2
19+
└── sub
20+
├── another.yaml
21+
└── someother.yaml
22+
23+
4 directories, 3 files
24+
```
25+
and you call `ytt --file dir1/some.yaml --file dir2/ ...` then ytt loads
26+
- `dir1/some.yaml` as `some.yaml`
27+
- `dir2/sub/another.yaml` as `sub/another.yaml`
28+
- `dir2/sub/someother.yaml` as `sub/someother.yaml`
29+
30+
- ytt uses a file's extension to determine its type, e.g. a extension like
31+
`yaml` flags that file as "yaml-template"; you can read more about that in
32+
[File Marks](file-marks/)
33+
34+
- You can change a file's name, location, and also "type" by explicitly
35+
setting the file's name to be used by ytt, e.g. `ytt --file
36+
a/different/file.foo=dir1/some.yaml`, which would mean that ytt
37+
38+
- loads that file as `a/different/file.foo`
39+
- would not consider it as "yaml-template"/"yaml-plain", but as "data", because of its extension
40+
41+
Note: this only works for files, not for directories
42+
43+
- Explicitly setting file's names can be especially useful when consuming
44+
files where you have no control over their name, like process substitutions:
45+
46+
Running `ytt --file <(echo 'some: yaml')` (on Linux) would have the shell
47+
produce a file like `/dev/fd/63` and pass that on to ytt. This file, based
48+
on it's name "63", would not be considered yaml and thus interpreted as
49+
"data". To change that, you need to run `ytt --file subst.yaml=<(echo 'some:
50+
yaml')` to have ytt treat it as yaml.
51+
52+
- ytt can also consume stdin by using `-`, like: `ytt --file -`
53+
54+
Note: When using `-`, ytt automatically treats data on stdin as yaml, as it
55+
will use stdin as `stdin.yaml`, thus having an extension which flags it as
56+
"yaml-template". If you use some other means to consume stdin, e.g. `ytt
57+
--file /dev/stdin`, this does not happen and ytt treats stdin as a file
58+
`stdin` and thus as "data", because it has no extension marking it
59+
differently. You can still set a different file name explicitly, e.g. with
60+
`ytt --file my-stdin.yaml=/dev/stdin`.
61+
62+
- ytt can also consume files via http/s, e.g. `ytt --file
63+
https://raw.githubusercontent.com/carvel-dev/ytt/develop/.golangci.yml`
64+
65+
- ytt can also consume symlinks, however if a symlink's target is not a file
66+
you have already included into the set of files ytt should consider
67+
(`--file ...`), ytt will not allow that and print an error. You can
68+
explicitly allow additional symlink targets via the
69+
`--allow-symlink-destination ...` flag.
70+
71+
- To debug / inspect which files ytt considers and how it handles those, the
72+
flags `--files-inspect` & `--debug` can be helpful
73+
74+
75+
- Data Values & Data Values Schemas
76+
77+
You can read about how to define data-values schemas and how to consume and
78+
set Data Values and Schemas here:
79+
80+
- [Write Schema](how-to-write-schema/)
81+
- [Data Values Schema](lang-ref-ytt-schema/)
82+
- [Use Data Values](how-to-use-data-values/)
83+
- [Data Values](ytt-data-values/)
84+
85+
Generally you can provide Data Values
86+
- as strings
87+
- on the command line via the flags `--data-value`/`-v`
88+
- from the environment via the flag `--data-values-env`
89+
- from files via the flag `--data-value-file`
90+
- as structured data / yaml
91+
- on the command line via the flag `--data-value-yaml`
92+
- from the environment via the flag `--data-values-env-yaml`
93+
- from files via the flag `--data-values-file`

site/data/ytt/docs/ytt-develop-toc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ toc:
8585
url: /lang-ref-load
8686
- title: CLI configuration
8787
subfolderitems:
88+
- page: Inputs
89+
url: /inputs
8890
- page: Outputs
8991
url: /outputs
9092
- page: File Marks

0 commit comments

Comments
 (0)