Comments (7)
FYI this is what I'm getting when trying this in v1.6.0:
$ kontemplate template my-cluster.yaml
kontemplate: error: Error loading context: Context loading failed on file my-cluster.yaml due to:
error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"gitHEAD":interface {}(nil)}
Another approach could to be to inline this in the resource sets, example psudeoish config;
spec:
containers:
- image: xyz.ecr.eu-central-1.amazonaws.com/my-awesome-app:{{ getOrElse .version gitHEAD }}
name: my-awesome-app
from kontemplate.
Hey!
Due to how the context is deserialised it's not that easy to provide those at the top-level right now (Go was of course the wrong choice for this project as it doesn't allow useful generic traversal of data structures).
It could be done with some kind of extra key that is looked for specifically, but there are other concerns like evaluation order and whether a context interpolation even terminates etc.
TL;DR: It's possible, but I don't think I have capacity for it at the moment. If someone else wants to implement it, it'd be good to sanity-check the implementation with me first :)
In general I think it's easier to use things like the default
function (see here) in templates which basically does what your getOrElse
mockup-call does.
from kontemplate.
Oooh nice, thanks a bunch for the insight and protip about default
👍 If the latter does the trick, I'm more than happy to throw away the thought that demands a more complex solution of templating top-level vars.
from kontemplate.
Getting an error when trying to use default
since the version
variable is not defined (when not provided as CLI arg):
Loading resources for my-awesome-app
kontemplate: error: Error templating resource sets: Error while templating my-awesome-app/config.yaml: template: config.yaml:14:96: executing "config.yaml" at <.version>: map has no entry for key "version"
I can't seem to find any go template or sprig functions that can help me check if the version
is actually defined at all -- not just a empty or nil
check.
Could it be reasonable to create a custom templater function in kontemplate that enables us to check for defined variables?
from kontemplate.
Getting an error when trying to use default since the version variable is not defined
Hmm, that's probably a conflict between this setting and the way the default
function is implemented.
Could it be reasonable to create a custom templater function in kontemplate that enables us to check for defined variables?
It may be possible to write an alternative default function that inspects the whole context and takes a key out of that (or alternatively a default value), without ever directly accessing the key via the template engine's standard mechanism.
I'd probably accept a PR for that, but don't currently have time to look at it myself.
from kontemplate.
@phillipj Hey, is this issue still relevant for you or did the default
function fix it?
from kontemplate.
Yo! I think default covers my needs, thanks for much needed rubber ducking.
from kontemplate.
Related Issues (20)
- Interpolating yaml as a template variables HOT 1
- Kubectl errors not revealed by kontemplate apply HOT 3
- insertFile parameteres or function HOT 2
- Add change cause for "Kontemplate apply" HOT 2
- Version 1.6 values vs global HOT 22
- Allow specifying the kubectl executable HOT 4
- [Feature] Ability to exclude some resources (or files) from template processing HOT 5
- kontemplate create does not send everything to kubectl HOT 3
- allow passing variables from command line HOT 1
- Not able to use all sprig functions HOT 4
- 1.6 global settings work differently from 1.5 global settings HOT 2
- Can't access sub-values in the new default function HOT 5
- A way to apply config with options (--as-admin, --as-group) HOT 2
- Override nested variables HOT 3
- Ability to resuse the template vairable within the master template and k8s resources HOT 1
- Please make a new release HOT 2
- Help me to beat my issue HOT 1
- Add support for null checks HOT 1
- Wrong term in cluster config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kontemplate.