Commit graph

28 commits

Author SHA1 Message Date
Vincent Ambo
6d8214bfc8 test(context): Introduce an explicit value merging test
Introduces a test which will merge variables defined at every possible
layer together and ensure that the loaded context configuration is as
expected.

The test data provides an actual resource set template that can be
tested locally from a kontemplate source checkout:

    kontemplate template context/testdata/merging/context.yaml --var cliVar=cliVar
2018-06-26 21:06:38 +02:00
Vincent Ambo
4a6f087fbf chore(context): Remove previous value override test 2018-06-26 21:06:38 +02:00
Vincent Ambo
2db3bbcdbe refactor(context): Rewrite and explain value merging logic
Changes the logic for merging context values to be unambiguous and
easy to follow.

* loadDefaultVars returns the default vars directly instead of
  performing merging in addition
* all merging is performed in `mergeContextValues` using explicit
  explanations for every step of the merge.

After this commit the order of merging goes from least to most
"specific", please read the explanatory comments for more information.

This relates to #142.
2018-06-26 21:06:38 +02:00
Vincent Ambo
92c5c846e2 fix(context): Use SplitN to split CLI variable specifications
In some cases the value of a variable may contain an equals sign,
which would not work in the previous version.

This uses `SplitN` to split the variable specifier into a
pre-determined number (2) of sub-slices. Further `=`-symbols will then
be included in the second substring.
2018-06-21 14:07:47 +02:00
Vincent Ambo
77ca5b47cf fix(context): Global values have precedence over defaults 2018-06-09 21:16:27 +02:00
Vincent Ambo
ae6d960df9 feat(context): Support loading import variables from absolute paths
This lets users specify the paths from which to import additional
variables using absolute paths in addition to relative paths.

This enables both loading of configuration files placed outside of the
resource set folder (if desired), as well as special use-cases such as
specifying `/dev/stdin` as an input path to read variables from
standard input.

This change supersedes #131
2018-06-09 20:21:29 +02:00
Vincent Ambo
b33c353233 refactor(context): Implement more explicit merging of variables
The hierarchy for loading variables was previously not expressed
explicitly.

This commit refactors the logic for merging variables to explicitly
set the different layers of variables as values on the context object
and merge them for each resource set in `mergeContextValues`.
2018-06-09 19:16:23 +02:00
Phillip Johnsen
5cf9d53e80 feat(context): allow explicit variables to be defined as argument
These changes allows variables to be defined when executing
`kontemplate` via one or more `--variable` arguments.

With this in place one can either define new variables or override
existing variables loaded from a file:

```
$ kontemplate apply --variable version=v1.0 example/fancy-app.yaml
```

This avoids the need to write variables into a temporary file that is
only needed to provide "external variables" into resource sets.

Closes https://github.com/tazjin/kontemplate/issues/122
2018-06-09 19:16:23 +02:00
Vincent Ambo
3aa2cb8d3e refactor: Remove old error handling library
Removes the old error handling library and switches to plain
fmt.Errorf calls.

There are several reasons for this:

* There are no useful types or handling here anyways, so output format
  is the only priority.
* Users don't care about getting stacktraces.
* My emotional wellbeing.

Fin de siècle.
2018-03-09 15:23:57 +01:00
Vincent Ambo
bfad4a3932 feat(license): Relicense under GPLv3
All further kontemplate source code changes and releases will happen under the GPLv3.

Previous releases are still available under the MIT license.
2017-11-21 11:46:27 +01:00
Vincent Ambo
b20bc5f57a fix templater: Don't template default.yml files
After the change from #84 default variable files with the '.yml'
extension got templated as resource set templates accidentally.

This resolves the issue by moving the list reserved default file names
to a common place and reusing it in both the templater and context pkg.

This fixes #85
2017-08-31 18:41:57 +02:00
Vincent Ambo
063a3e9d30 fix context: Support ".yml" extension on default files
In other places in Kontemplate that deal with YAML files, both the
".yaml" and ".yml" extension are supported.

This fixes context loading code to support that for resource set
variables, too.

This fixes #83
2017-08-25 14:44:24 +02:00
Vincent Ambo
a159b71a19 style: Apply go fmt 2017-08-04 23:11:27 +02:00
Vincent Ambo
367c5d2b60 docs context: Document ResourceSet & Context struct fields 2017-08-04 23:11:27 +02:00
Vincent Ambo
7607f6dc0f feat context: Allow overriding resource set paths
Instead of always inferring the path at which files in a resource set
are located, let users override the path by specifying a `path` field.

This makes it possible to add the same resource set multiple times
with different values while still keeping distinct names for
addressability (for example when using include/exclude).

This fixes #70
2017-07-13 16:07:08 +02:00
Vincent Ambo
9d26c17f13 feat context: Add ability to import extra variables from files
Kontemplate context specifications can now load extra variables from YAML
or JSON files by specifying a list of files (relative to the context file)
under the `import` key.
2017-07-03 14:27:48 +02:00
Vincent Ambo
3728d0ae2e refactor context: Extract loadJsonOrYaml to util package
The logic to deserialise a structure from *either* JSON or YAML is reused several
times and can be easily extracted, which this commit does.
2017-07-03 14:27:48 +02:00
Vincent Ambo
7286751db7 fix test: Assert variable override order 2017-04-04 20:06:15 +02:00
Vincent Ambo
11cfc80020 feat context: Support resource set default values
This adds functionality to specify default values directly in resource sets.

The idea is that users can create a file called `values.yaml` or `values.json`
in a resource set's folder and have all variables specified in that file be
automatically merged into the resource set variables with the lowest priority.

This fixes #25
This fixes #30 (to a degree)
2017-04-04 20:06:15 +02:00
Vincent Ambo
45aee8257f style: Apply go fmt 2017-02-20 14:25:39 +01:00
Vincent Ambo
0147c3e13e feat ctx: Let sub-resource-sets inherit vars from parent
Users of kontemplate may expect variables defined on the parent resource to be
inherited by children.

This implements that functionality. Values defined twice are overwritten by the
child's definition.

Fixes #20
2017-02-14 19:12:53 +01:00
Vincent Ambo
75b6199c1b feat context: Add deserialisation tests 2017-02-08 22:12:34 +01:00
Vincent Ambo
dd2fdd63e5 fix templater & ctx: Correctly check resource set parent 2017-02-08 17:42:06 +01:00
Vincent Ambo
bace4dd895 fix context: Set sub resource names correctly 2017-02-08 17:34:49 +01:00
Vincent Ambo
4e8223ef34 feat context: Add support for resource set collections
A resource set collection is a resource set with an addition 'include' array
configured. It is a short-hand for importing multiple resource sets from the
same folder and for excluding/including them as a group.

See https://github.com/tazjin/kontemplate/issues/9 for more information.

Closes #9
2017-02-08 17:34:49 +01:00
Vincent Ambo
d94a0ffc25 feat context: Add YAML loading support
Closes #5
2017-02-08 13:13:21 +01:00
Vincent Ambo
7ac63613fb feat main: Add proper CLI support
Adds a basic CLI structure with a single "run" command that takes a --file (-f)
and --limit (-l) flag.

--limit can be used to only output certain resource sets.

Closes #4
2017-02-08 12:58:53 +01:00
Vincent Ambo
bb45bfa737 feat context: Add types and loading functions 2017-02-08 11:50:39 +01:00