Open bdnf opened 3 years ago
Just ran into this as well, and it's pretty annoying.
I was attempting to select an inventory attribute by using a value given via env like this:
# kapitan inventory class file
---
parameters:
target_team_cn: "ug_?{env:env_vars/team}"
...
# Jinja template
{{ inventory.parameters.teams[inventory.parameters.target_team_cn] }}
But it fails because the env
value isn't resolved at compile time. Naturally, using --reveal
does not work either.
..devel/deploy on refac-purpose-config +1539 -596 [$✘»!+?] w 🐍 v3.8.10 (purpose-configuration) ☁️ default
🐟 ❯ kapitan compile
Rendered inventory (0.02s)
Jinja2 error: failed to render /home/deepbrook/devel/deploy/templates/team.tfvars: Jinja2 TemplateError: 'dict object' has no attribute 'ug_?{env:env_vars/team}', at /home/deepbrook/devel/deploy/templates/team.tfvars:8
Compile error: failed to compile target: team
This essentially forces me to do either of the following:
team
Since we also have secrets in these rendered templates, the latter solution isn't viable.
🐟 ❯ kapitan --version
0.31.0
This issue is stale because it has been open for 1 year with no activity. Remove the stale label or comment if this issue is still relevant for you. If not, please close it yourself.
Describe the bug/feature Secrets of type plain are not accessible during the compile time in
jsonnet
files. Hardcoded variables from parameters are accessible as expected. Though the behaviour might be intended for refs of type AWS KMS, Vaultkv, etc. the behaviour for types plain or env should allow to access files during the compile time.To Reproduce Steps to reproduce the behavior:
Assuming simple folder structure:
Contents of components/test-component.jsonnet:
local TOPIC = inventory.parameters.arguments.topic; assert TOPIC == "starting_offsets.TIER1": "topic strings don't match"; # assertion fail here assert std.asciiLower(TOPIC) == "starting_offsets.tier1": "lowercase topic strings don't match";
local database = std.asciiLower(inventory.parameters.arguments.mysql); assert database == "some-slq-database": "strings don't match";
{ 'job': { apiVersion: 'batch/v1', kind: 'Job', metadata: { labels: { database: database, topic: std.asciiLower(TOPIC), deployment_name: inventory.parameters.deployment_name, }, name: database + '-' + std.asciiLower(TOPIC), }, spec: {} } }
parameters: deployment_name: dev target_namespace: default
commit_tag: 1223456789
kapitan: vars: target: microservice
Jsonnet error: failed to compile /src/kapitan/components/test-component.jsonnet: RUNTIME ERROR: topic strings don't match /src/kapitan/components/test-component.jsonnet:(5:1)-(25:2)
Compile error: failed to compile target: microservice
Possible Bug
kapitan --version
: 0.29.5python --version
: Python 3.7.11pip3 --version
: pip 21.2.2 from /opt/venv/lib/python3.7/site-packages/pip (python 3.7)pyenv
Additional context
It would be nice to access variables that are set dynamically via plain ref type during the compile time. For example Kubernetes resources require that fields are lowercased and do not contain some special characters.
Additionally, it is not impossible to use
plain:variable
as a generated file name. The output file name is simple shown as:instead of:
It would be nice to access them by default, or at least with some additional argument, like so: