k8t
k8t copied to clipboard
validation misses nested values
missing values like {{ foo.bar }} will be missed during validation if foo is defined.
leaving it undefined only recognizes the top level variable as missing
01_configmaps.yaml.j2: ✗
- undefined variable: aws
possible solution via jinja2schema
https://stackoverflow.com/questions/42589514/how-to-get-nested-undeclared-variables-in-python-jinja2
Stack OverflowI have an xml template and I'm loadind data into it using jinja2 template engine. I'm trying to validate that all the variables in the template are supplied:from jinja2 import Environment,
the merged PR now raises a proper error when nested values are missing but validation still can't detect them properly.
@AFriemann, the easiest way to check for existence of nested variables is dry-run of rendering. But here we need to choose:
- Fail on first undefined nested variable during render, means that if we find undefined, we will interrupt validation.
- Fail on first undefined nested variable in every template, means that we still can validate other templates.
- Evaluate expression that should raise undefined error to empty string, log error into standard output and proceed.
I've already made a Proof of Concept for third option: https://github.com/ClarkSource/k8t/pull/69