furiko icon indicating copy to clipboard operation
furiko copied to clipboard

Proposal: Change templating language syntax

Open irvinlim opened this issue 2 years ago • 0 comments

There are some issues with the current templating language used for context variables, such as ${context.var_name}:

  1. Looks too similar to shell variables. We have to clear all unsubstituted variables to avoid Bad substitution errors when sending the substituted text to /bin/bash.
  2. Does not support filters/pipelines (i.e. Jinja2 filters, or Golang text/template pipelines). In some cases, simple transformation may be needed (e.g. lowercase/uppercase, trim spaces, defaulting)
  3. Does not support conditionals. Usually worked around by using shell conditionals after substitution, but it is quite clunky.

The initial design was to maintain compatibility with Rundeck's context variables, which uses this exact format. However, we don't even use the same set of context variables as Rundeck any more (just the same format), which kind of defeats the purpose in the first place...

I suggest changing to use a more modern templating language entirely, and drop the "backwards compatibility" with Rundeck. Some possible options:

  1. Jinja2: Widely known syntax (at least to my circles), but it is a bit dated and surface area may be too wide.
    • pongo2: Jinja2 implementation for Go
  2. text/template: Also widely known to Go developers. Some possible offshoots:
    • sprig: Used by Helm, so highly possible that users are familiar with it.

Some requirements:

  1. The templating language should support contexts. This can be as simple as dictionary indexing or struct field access (e.g. .ctx.jobConfig.name).
  2. We need to be able to "send" variables between resources. Currently this is done via the substitutions field when creating a Job from a JobConfig (see doc). This means we need to be able to encode/decode each context variable as a string.

Ideally, we should choose a syntax that is already widely known to the community. We can drop support for the original Rundeck-like variable syntax altogether once implemented.

irvinlim avatar Apr 11 '22 19:04 irvinlim