Visitar URL original
Add runtime templating in configuration by olblak · Pull Request #242 · updatecli/updatecli · GitHub
Skip to content

Add runtime templating in configuration - #242

Merged
olblak merged 10 commits into
updatecli:mainfrom
olblak:template
Jul 7, 2021
Merged

olblak merged 10 commits into
updatecli:mainfrom
olblak:template

Conversation

@olblak

@olblak olblak commented Jun 20, 2021 •

Copy link
Copy Markdown
Member

This PR is an attempt to partially fix #158 and superseded #181

Runtime templating

It allows templating configuration based on runtime information.
The function "pipeline" accepts one parameter where the value corresponds to a updatecli configuration key, a value where the key is case insensitive.

which can be defined like:

title: {{ pipeline "Source.Output" }}
sources:
default:
name: Get Latest helm release version
kind: githubRelease
spec:
owner: "helm"
repository: "helm"
token: {{ requiredEnv .github.token }}
username: olblak
version: latest

The configuration is updated after each stage, if it finds a function configuration value set to pipeline "updatecli_config", then it tries to replace with a value but only if the value exists otherwise it keeps pipeline "updatecli_config" for the next run .

While working on this PR, I took the following shortcuts

  • the function pipeline can't be used for [sources, conditions, target] map key such as
title: {{ pipeline "Source.Output" }}
conditions:
  {{ pipeline "source.default":
    name: ...
    kind: githubRelease
    spec:
        ...
  • I now mix context variable and global configuration, and I should split those two pieces of information into different variables such as sources.default.result should become context.sources.default.result
  • We need a way to define resource order, because sources, conditions, and targets are maps, the order is not guaranteed so we can't reference source information from another source.

Depends_on

A depends_on key can be use to specify resources dependencies within a stage.
So in the following example the depends_on assume that we have another source with the id "weekly"
otherwise we fail the pipeline

sources:
  stable:
    kind: jenkins
    depends_on:
      - weekly
    name: Get Latest Jenkins stable version
    spec:
      github:
        token: {{ requiredEnv .github.token }}
        username: {{ .github.username }}

Errors

In case of a dependency loop detected, we return the following error

#########################
# RUNTIMETEMPLATING.TPL #
#########################

ERROR: Depency loop detected between Sources["weekly"] and Sources["stable"]
ERROR: ✗ dependency loop detected

In case of a wrong depends_on

#########################
# RUNTIMETEMPLATING.TPL #
#########################

ERROR: no valid depends_on value:"weeklyy"
ERROR: ✗ no valid depends_on value

Signed-off-by: Olivier Vernin olivier@vernin.me

olblak added 2 commits June 20, 2021 19:50
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak
olblak requested a review from dduportal June 20, 2021 18:11
Signed-off-by: Olivier Vernin <olivier@vernin.me>
olblak added 2 commits June 25, 2021 14:19
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak
olblak marked this pull request as draft June 28, 2021 15:30
olblak added 4 commits June 28, 2021 21:01
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak
olblak marked this pull request as ready for review June 29, 2021 13:48
@olblak olblak changed the title Add runtime templating Add runtime templating in configuration Jul 7, 2021
@olblak
olblak merged commit b07e0e6 into updatecli:main Jul 7, 2021
dduportal added a commit to dduportal/updatecli that referenced this pull request Jul 8, 2021
olblak pushed a commit that referenced this pull request Jul 8, 2021
olblak added a commit that referenced this pull request Jul 10, 2021
@olblak olblak mentioned this pull request Jul 13, 2021
@olblak
olblak deleted the template branch March 13, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to define and use multiple sources

1 participant