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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Sprig functions available in config template #1177

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

croissong
Copy link
Contributor

@croissong croissong commented Feb 26, 2023

This change makes all functions from the Sprig template library available in the manifest.

Coming from Helm/Helmfile, I was missing the various utility functions provided by Sprig while building my config.
For example, my personal config I am iterating over a packages map and would like to merge each package config with a default (showing the use of mergeOverwrite from Sprig):

# values.yml

defaults:
  trimPrefix: true

packages:
  sheldon:
    owner: rossmacarthur
    trimPrefix: false

  sttr:
    owner: abhimanyu003

  updatecli:
    owner: updatecli
# updatecli.yaml

sources:
  {{ range $name, $package := . packages }}

  # set defaults
  {{ $package = mergeOverwrite .defaults $package }}
  ...

Test

I slightly refactored pkg/core/config/template.go to be able to mock the filesystem interactions, and I added some basic tests for the templating functionality.

Docs

I created updatecli/website#672 to mention Sprig in the docs.

@ghost
Copy link

ghost commented Feb 26, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@olblak
Copy link
Member

olblak commented Feb 27, 2023

Waouw that's something I wanted so much \o/
Let me run some tests

pkg/core/config/template.go Outdated Show resolved Hide resolved
@olblak olblak added the enhancement New feature or request label Feb 27, 2023
@olblak olblak added this to the 0.45.0 milestone Feb 27, 2023
@olblak
Copy link
Member

olblak commented Feb 27, 2023

Thanks @croissong for the pullrequest. It looks great. Once merged I'll take a few days to test the main branch, before releasing 0.45 as I did a few changes around git operation which may introduce regression and I want to be extra safe

@croissong croissong force-pushed the feat/add-sprig-template-functions branch from 1f06a1b to 76d1211 Compare February 27, 2023 08:55
@olblak olblak enabled auto-merge (squash) February 27, 2023 10:07
@olblak olblak merged commit b4003a1 into updatecli:main Feb 27, 2023
@olblak olblak changed the title feat(core/config): make Sprig functions available in config template Make Sprig functions available in config template Feb 27, 2023
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.

None yet

2 participants