-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathkgextlang-rfc.yaml
188 lines (144 loc) · 5.36 KB
/
kgextlang-rfc.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
## The kubegen extension language in kubegen allows for basic typed operation on structured
## data while keeping the semantics of JSON and YAML formats, and without levereging
## uncommon features (such as YAML tags), so that formats can be converated automatically
## and mapping is one-to-one. It also doesn't overload string value with a non-transparent
## mini-languages.
##
## The extension language is very simple, and intended to be least surprising.
## There are no loops or user-defined functions, there are only lookups, combinatory operations
## for arrays and objects, string joins and conditional statements.
##
## First of all, there two types of documents – bundle and modules.
## A module contains one or more documets that have none or some number number of
## parameters. Parameters may have default values, or otherwise are required to be
## set be set by the user.
## Parameter types are the basic JSON types, i.e. strings, numbers, booleans, arrays
## and objects.
## The way to test a module is to use `kubegen module [-v paramKey=paramValue] -s ./myModule/`.
## The user can create a bundle and reference a set of one or more modules which.
## When user runs `kubegen bundle myBundle.yml`, all modules reference in `myBundle.yml`
## will be evaluated based on what parameters the user has defined.
##
## Basic Rules & Assumptions:
##
## 1. root of the document is always an object (as in Kubernetes API)
## 2. parent of `kubegen.<type>.Lookup` must be a element of an array or an object
## 3. undefined parameters or any ambiguity results in an error
## 4. on success the output will always adhere to JSON or YAML spec
## 5. more generally, the output will alway result in valid Kubernetes API object
##
## See usage examples below.
## Lookup Strings
---
kubegen.String.Lookup: "stringParameter"
## will result in
---
"<value>"
## Lookup Object
---
kubegen.Object.Lookup: "objectParameter"
## will result in
---
{ <value> }
## Lookup Array
kubegen.Array.Lookup: "arrayParameter"
# will result in
[ <value> ]
## Array Operations - concatenation
foo:
- kubegen.Array.Lookup: "arrayParameter1"
- kubegen.Array.Lookup: "arrayParameter2"
## will result in concatenated values of two array parameters
## given `arrayParameter1=[1,2,3]` and `arrayParameter2=[3,4,5]`, we will get
foo:
- 1
- 2
- 3
- 3
- 4
- 5
## Array Operations - nesting
foo:
- [ kubegen.Array.Lookup: "arrayParameter1" ]
- [ kubegen.Array.Lookup: "arrayParameter2" ]
## will result in two arrays being nested in parent array
## given `arrayParameter1=[1,2,3]` and `arrayParameter2=[3,4,5]`, we will get
foo:
- [ 1, 2, 3 ]
- [ 3, 4, 5 ]
## Array Operations – mixing with objects and other types
foo:
- kubegen.Array.Lookup: "arrayParameter1"
- [ kubegen.Array.Lookup: "arrayParameter2" ]
- kubegen.Object.Lookup: "objectParameter2"
- kubegen.String.Lookup: "stringParameter1"
## will result in one arrays being concatenated with the parent, one nested array,
## one nested object object, and one string being appended to the parent array
## given `arrayParameter1=[1,2,3]` and `arrayParameter2=[3,4,5]`, `objectParameter2={}`
## and `stringParameter1="bar"`, we will get
foo:
- 1
- 2
- 3
- [ 3, 4, 5 ]
- { }
- "bar"
## Object Operations - merge
## Lookup two objects and merge both (second object take prevalence)
---
kubegen.Object.Lookup: [ "objectParameter", "objectParameter" ]
## Lookup an object and merge with parent object (parent object take prevalence)
---
kubegen.Object.Lookup: "objectParameter"
foo: bar
## Lookup an object and merge with parent object wich shares key `foo` that point
## to an array (`foo` in parent object take prevalence)
---
kubegen.Object.Lookup: "objectParameter"
foo: [ bar ]
## Lookup an object and merge with parent object wich shares key `foo` that point
## to an array, as `foo` in parent object take prevalence, array concatenation has
## to be explicit (extended child lookup syntax)
---
kubegen.Object.Lookup: "objectParameter"
foo:
- bar
- kubegen.Array.Lookup: "objectParameter.foo[0]"
## Conditionals
## Undefined params in conditionals will cause an error
## Conditionals are evaluated prior to lookups (KeywordEvalPhaseA)
---
kubegen.If: "boolParameter" # true if defined and true
foo: bar
---
kubegen.If: "numberParameter" # true if defined and >= 1
foo: bar
---
kubegen.If: "stringParameter" # true if defined and not empty
foo: bar
---
kubegen.If: "objectParameter" # true if defined and not empty
foo: bar
---
kubegen.If: "arrayParameter" # true if defined and not empty
foo: bar
---
kubegen.If: "objectParameter.bar"
foo: bar
## Parameters and Internals
## Parameters are externally settable attributes of a module.
## Internals are internally settable attributes of a module,
## these aren't different from parameters, however aren't visible
## to user, they are meant for private use within a module, e.g.
## shared objects that reused by some parts of a module or
## objects loaded from a JSON/YAML file that needs to be included
## in part, perhaps based on a given condition, and path to such
## file could be determined by a parameter.
## A parameter can be required or may have a default value, while
## internals always must have a value.
## File Readers
data:
kubegen.String.ReadFile: "some_binary_file"
kubegen.Object.LoadJSON:
kubegen.String.Lookup: "json_state_file"
kubegen.Object.LoadYAML: ["yaml1", "yaml2"]