k8t icon indicating copy to clipboard operation
k8t copied to clipboard

validation misses nested values

Open AFriemann opened this issue 5 years ago • 3 comments

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

AFriemann avatar Jan 30 '20 10:01 AFriemann

possible solution via jinja2schema

https://stackoverflow.com/questions/42589514/how-to-get-nested-undeclared-variables-in-python-jinja2

Stack Overflow
I 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,

AFriemann avatar Jan 30 '20 15:01 AFriemann

the merged PR now raises a proper error when nested values are missing but validation still can't detect them properly.

AFriemann avatar Feb 06 '20 18:02 AFriemann

@AFriemann, the easiest way to check for existence of nested variables is dry-run of rendering. But here we need to choose:

  1. Fail on first undefined nested variable during render, means that if we find undefined, we will interrupt validation.
  2. Fail on first undefined nested variable in every template, means that we still can validate other templates.
  3. 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

sl4vr avatar Jun 16 '20 13:06 sl4vr