Giter Club home page Giter Club logo

Comments (7)

phillipj avatar phillipj commented on September 22, 2024

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.

tazjin avatar tazjin commented on September 22, 2024

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.

phillipj avatar phillipj commented on September 22, 2024

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.

phillipj avatar phillipj commented on September 22, 2024

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.

tazjin avatar tazjin commented on September 22, 2024

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.

tazjin avatar tazjin commented on September 22, 2024

@phillipj Hey, is this issue still relevant for you or did the default function fix it?

from kontemplate.

phillipj avatar phillipj commented on September 22, 2024

Yo! I think default covers my needs, thanks for much needed rubber ducking.

from kontemplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.