Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Runtime templating #254

Merged
merged 4 commits into from
Jul 15, 2021
Merged

Add Runtime templating #254

merged 4 commits into from
Jul 15, 2021

Conversation

olblak
Copy link
Member

@olblak olblak commented Jul 13, 2021

Add runtime templating

Fix #158

This pull request is a third attempt to introduce runtime templating.
Some refactoring was needed to avoid templating unwanted information such as changelogs containing mustache syntax.

On top of #242
I modified the pipeline template function to only fetch information from context such as stage Results. I keep it undocumented for now
I introduce the source template to quickly retrieve a source result

This pr also fix minor issues such as:

  • Wrong message Since version 1.2.0... become Since version 0.2.0
  • Run every condition even if one of them is failing, so we directly have visibility on what needs to be fixed
  • Remove duplicate error message

The following snippet is an example of how to use the source function in a template to reuse source output.
Just insert this syntax {{ source "<< source id >>" }}

sources:
  stable:
    kind: jenkins
conditions:
  stabledockerImage:
    name: 'Is docker image jenkins/jenkins:{{ source "stable" }} published?'
    kind: dockerImage
    sourceID: stable
    spec:
      image: jenkins/jenkins
      tag: '{{ source "stable" }}-jdk11'
  weeklydockerImage:
    name: 'Is docker image tag{{ pipeline "Sources.weekly.Output" }} published?'
    kind: dockerImage
    sourceID: weekly
    spec:
      image: jenkins/jenkins
      tag: '{{ pipeline "Sources.weekly.Output" }}-jdk11'

Test

To test this pull request, you can run the following commands:

  make test-short
  export GITHUB_TOKEN=xxx
  go build -o bin/updatecli
  ./bin/updatecli diff --config examples/updateCli.generic/runtimeTemplating.tpl --values  examples/values.yaml

Additionnal Information

Tradeoff

I am missing a lot of UT in this specific area but I also lack of time. 馃槥

Potential improvement

Additional refactoring is needed for the engine package
Additional tests are needed for the engine package

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 added the enhancement New feature or request label Jul 13, 2021
@olblak olblak changed the title Runtime templating Add Runtime templating Jul 13, 2021
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak
Copy link
Member Author

olblak commented Jul 14, 2021

After back and forth thinking, I am removing the go template function pipeline.

  • pipeline is a bit too dangerous as it creates a strong binding between the data structure context used inside updatecli and upatecli configuration.
  • pipeline is now redundant with the basic templating feature as we don't anymore modify the configuration at runtime.

For now, I'll just document the source function template as it solves the initial need which was being able to reuse source output in other configuration

@olblak olblak merged commit 4148317 into updatecli:main Jul 15, 2021
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