Skip to content

Commit b38d241

Browse files
committed
docu for state support
1 parent 168b8c1 commit b38d241

File tree

5 files changed

+227
-104
lines changed

5 files changed

+227
-104
lines changed

README.md

Lines changed: 156 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ resource:
2727
```
2828
2929
spiff is a command line tool and declarative YAML templating system, specially designed for generating deployment
30-
manifests (for example BOSH manifests or [kubernetes](https://github.com/kubernetes) manifests).
30+
manifests (for example BOSH or [kubernetes](https://github.com/kubernetes) manifests).
3131
3232
Contents:
3333
- [Installation](#installation)
@@ -118,8 +118,6 @@ Contents:
118118
- [(( x509publickey(key) ))](#-x509publickeykey-)
119119
- [(( x509cert(spec) ))](#-x509certspec-)
120120
- [(( lambda |x|->x ":" port ))](#-lambda-x-x--port-)
121-
- [(( &temporary ))](#-temporary-)
122-
- [(( &inject ))](#-inject-)
123121
- [(( catch[expr|v,e|->v] ))](#-catchexprve-v-)
124122
- [(( sync[expr|v,e|->defined(v.field),v.field|10] ))](#-syncexprve-definedvfieldvfield10-)
125123
- [Mappings](#mappings)
@@ -136,6 +134,11 @@ Contents:
136134
- [Projections](#projections)
137135
- [(( expr.[*].value ))](#-exprvalue-)
138136
- [(( list.[1..2].value ))](#-list12value-)
137+
- [Markers](#markers)
138+
- [(( &temporary ))](#-temporary-)
139+
- [(( &local ))](#-local-)
140+
- [(( &inject ))](#-inject-)
141+
- [(( &state ))](#-state-)
139142
- [Templates](#templates)
140143
- [<<: (( &template ))](#--template-)
141144
- [(( *foo.bar ))](#-foobar-)
@@ -172,10 +175,6 @@ Example:
172175
spiff merge cf-release/templates/cf-deployment.yml my-cloud-stub.yml
173176
```
174177

175-
The ` merge` command offers the option `--partial`. If this option is
176-
given spiff handles incomplete expression evaluation. All errors are ignored
177-
and the unresolvable parts of the yaml document are returned as strings.
178-
179178
It is possible to read one file from standard input by using the file
180179
name `-`. It may be used only once. This allows using spiff as part of a
181180
pipeline to just process a single stream or to process a stream based on
@@ -188,12 +187,32 @@ The result is the stream of processed documents in the same order.
188187
For example, this can be used to generate *kubernetes* manifests to be used
189188
by `kubectl`.
190189

191-
With the option `--json` the output will be in JSON format instead of YAML.
192-
The Option `--path <path>` can be used to output a nested path, instead of the
193-
the complete processed document.
190+
The ` merge` command offers several options:
194191

195-
If the output is a list, the option `--split` outputs every list element as
196-
deparate document.
192+
- The option `--partial`. If this option is
193+
given spiff handles incomplete expression evaluation. All errors are ignored
194+
and the unresolvable parts of the yaml document are returned as strings.
195+
196+
- With the option `--json` the output will be in JSON format instead of YAML.
197+
198+
- The Option `--path <path>` can be used to output a nested path, instead of the
199+
the complete processed document.
200+
201+
- If the output is a list, the option `--split` outputs every list element as
202+
separate documen. The _yaml_ format uses as usual `---` as separator line.
203+
The _json_ format outputs a sequence of _json_ documents, one per line.
204+
205+
- With `--select <field path>` is is possible to select a dedicated field of the
206+
processed document for the output
207+
208+
- The option `--state <path>` enables the state support of _spiff_. If the
209+
given file exists it is put on top of the configured stub list for the
210+
merge processing. Additionally to the output of the processed document
211+
it is filtered for nodes marked with the [`&state` marker](#-state-).
212+
This filtered document is then stored under the denoted file, saving the old
213+
state file with the `.bak` suffix. This can be used together with a manual
214+
merging as offered by the [state](libraries/state/README.md) utility library.
215+
197216

198217
The folder [libraries](libraries/README.md) offers some useful
199218
utility libraries. They can also be used as an example for the power
@@ -2876,85 +2895,6 @@ value: (( .mult2(3) ))
28762895

28772896
If a complete expression is a lambda expression the keyword `lambda` can be omitted.
28782897

2879-
## `(( &temporary ))`
2880-
2881-
Maps, lists or simple value nodes can be marked as *temporary*. Temporary nodes are removed from the final output document, but are available during merging and dynaml evaluation.
2882-
2883-
e.g.:
2884-
2885-
```yaml
2886-
temp:
2887-
<<: (( &temporary ))
2888-
foo: bar
2889-
2890-
value: (( temp.foo ))
2891-
```
2892-
2893-
yields:
2894-
2895-
```yaml
2896-
value: bar
2897-
```
2898-
Adding `- <<: (( &temporary ))` to a list can be used to mark a list as temporary.
2899-
2900-
The temporary marker can be combined with regular dynaml expressions to tag plain fields. Hereby the
2901-
parenthesised expression is just appended to the marker
2902-
2903-
e.g.:
2904-
2905-
```yaml
2906-
data:
2907-
alice: (( &temporary ( "bar" ) ))
2908-
foo: (( alice ))
2909-
```
2910-
2911-
yields:
2912-
2913-
```yaml
2914-
data:
2915-
foo: bar
2916-
```
2917-
2918-
The temporary marker can be combined with the [template marker](#templates) to omit templates from the final output.
2919-
2920-
The marker `&local` acts similar to `&temporary` but local nodes are always
2921-
removed from a stub directly after resolving dynaml expressions. Such nodes
2922-
are therefore not available for merging.
2923-
2924-
## `(( &inject ))`
2925-
2926-
This marker requests the marked item to be injected into the next stub level,
2927-
even is the hosting element (list or map) does not requests a merge.
2928-
This only works if the next level stub already contains the hosting element.
2929-
2930-
e.g.:
2931-
2932-
**template.yaml**
2933-
```yaml
2934-
alice:
2935-
foo: 1
2936-
```
2937-
2938-
**stub.yaml**
2939-
```yaml
2940-
alice:
2941-
bar: (( &inject(2) ))
2942-
nope: not injected
2943-
bob:
2944-
<<: (( &inject ))
2945-
foobar: yep
2946-
2947-
```
2948-
2949-
is merged to
2950-
2951-
```yaml
2952-
alice:
2953-
foo: 1
2954-
bar: 2
2955-
bob:
2956-
foobar: yep
2957-
```
29582898
## `(( catch[expr|v,e|->v] ))`
29592899

29602900
This expression evaluates an expression (`expr`) and then
@@ -3412,6 +3352,130 @@ names:
34123352
- peter
34133353
```
34143354

3355+
## Markers
3356+
3357+
Nodes of the yaml document can be marked to enable dedicated behaviours for this
3358+
node. Such markers are part of the _dynaml_ syntax and may be prepended to
3359+
any dynaml expression. They are denoted by the `&` character directly followed
3360+
by a marker name. If the expression is combination of markers and regular
3361+
expressions, the expression follows the marker list enclosed in brackets
3362+
(for example `(( &temporary( a + b ) ))`).
3363+
3364+
### `(( &temporary ))`
3365+
3366+
Maps, lists or simple value nodes can be marked as *temporary*. Temporary nodes
3367+
are removed from the final output document, but are available during merging and
3368+
dynaml evaluation.
3369+
3370+
e.g.:
3371+
3372+
```yaml
3373+
temp:
3374+
<<: (( &temporary ))
3375+
foo: bar
3376+
3377+
value: (( temp.foo ))
3378+
```
3379+
3380+
yields:
3381+
3382+
```yaml
3383+
value: bar
3384+
```
3385+
Adding `- <<: (( &temporary ))` to a list can be used to mark a list as temporary.
3386+
3387+
The temporary marker can be combined with regular dynaml expressions to tag plain fields. Hereby the
3388+
parenthesised expression is just appended to the marker
3389+
3390+
e.g.:
3391+
3392+
```yaml
3393+
data:
3394+
alice: (( &temporary ( "bar" ) ))
3395+
foo: (( alice ))
3396+
```
3397+
3398+
yields:
3399+
3400+
```yaml
3401+
data:
3402+
foo: bar
3403+
```
3404+
3405+
The temporary marker can be combined with the [template marker](#templates) to omit templates from the final output.
3406+
3407+
### `(( &local ))`
3408+
3409+
The marker `&local` acts similar to `&temporary` but local nodes are always
3410+
removed from a stub directly after resolving dynaml expressions. Such nodes
3411+
are therefore not available for merging and they are not used for further
3412+
merging of stubs and finally the template.
3413+
3414+
3415+
### `(( &inject ))`
3416+
3417+
This marker requests the marked item to be injected into the next stub level,
3418+
even is the hosting element (list or map) does not requests a merge.
3419+
This only works if the next level stub already contains the hosting element.
3420+
3421+
e.g.:
3422+
3423+
**template.yaml**
3424+
```yaml
3425+
alice:
3426+
foo: 1
3427+
```
3428+
3429+
**stub.yaml**
3430+
```yaml
3431+
alice:
3432+
bar: (( &inject(2) ))
3433+
nope: not injected
3434+
bob:
3435+
<<: (( &inject ))
3436+
foobar: yep
3437+
3438+
```
3439+
3440+
is merged to
3441+
3442+
```yaml
3443+
alice:
3444+
foo: 1
3445+
bar: 2
3446+
bob:
3447+
foobar: yep
3448+
```
3449+
3450+
### `(( &state ))`
3451+
3452+
Nodes marked as *state* are handled during the merge processing as if the
3453+
marker would not be present. But there will be a special handling for enabled
3454+
state processing [(option `--state <path>`)](#usage) at the end of the
3455+
template processing.
3456+
Additionally to the regular output a document consisting only of state nodes
3457+
(plus all nested nodes) will be written to a state file. This file will be used
3458+
as top-level stub for further merge processings with enabled state support.
3459+
3460+
This enables to keep state between two merge processings. For regular
3461+
merging sich nodes are only processed during the first processing. Later
3462+
processings will keep the state from the first one, because those nodes
3463+
will be overiden by the state stub added to the end of the sub list.
3464+
3465+
If those nodes additionally disable merging (for example using
3466+
`(( &state(merge none) ))`) dynaml expressions in sub level nodes may
3467+
perform explicit merging using the function `stub()` to refer to
3468+
values provided by already processed stubs (especially the implicitly added
3469+
state stub). For an example please refer to the
3470+
[state library](libraries/state/README.md).
3471+
3472+
### `(( &template ))`
3473+
3474+
Nodes marked as *template* will not be evaluated at the place of their
3475+
occurrence. Instead, they will result in a template value stored as value for
3476+
the node. They can later be instantiated inside a _dynaml_ expression
3477+
(see [below](#templates)).
3478+
34153479
## Templates
34163480

34173481
A map can be tagged by a dynaml expression to be used as template. Dynaml expressions in a template are not evaluated at its definition location in the document, but can be inserted at other locations using dynaml.
@@ -3441,7 +3505,7 @@ The template marker can be combined with the [temporary marker](#-temporary-) to
34413505

34423506
### `(( *foo.bar ))`
34433507

3444-
The dynaml expression `*<refernce expression>` can be used to evaluate a template somewhere in the yaml document.
3508+
The dynaml expression `*<reference expression>` can be used to evaluate a template somewhere in the yaml document.
34453509
Dynaml expressions in the template are evaluated in the context of this expression.
34463510

34473511
e.g.:

libraries/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ the package finally offering the functionality.
3434

3535
## Library Overview
3636

37+
### Certificate Generation
38+
39+
This [library](certs/README.md) offers useful lambda functions to generate
40+
certificates for self signed certificate authorities, and key/certificate pairs
41+
using the [state library](state/README.md).
42+
3743
### Simple Graph Library
3844

3945
This [library](graph/README.md) offers simple graph analysis for directed graphs, like cycle
4046
detection and dependeny closures, or inverting a directed graph.
4147

4248
### State Handling
4349

44-
This [library](state/README.md) offers simple state handling support together
50+
This [library](state/README.md) offers a simple state handling support together
4551
with a small shell script example.
4652

0 commit comments

Comments
 (0)