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

enable Sprig functions for embedded Go templates #1863

Open
qrkourier opened this issue Mar 22, 2024 · 2 comments
Open

enable Sprig functions for embedded Go templates #1863

qrkourier opened this issue Mar 22, 2024 · 2 comments

Comments

@qrkourier
Copy link
Member

Templating YAML is tedious and error prone, but we can make it less so by introducing the Sprig library (github.com/Masterminds/sprig).

For example, our embedded YAML templates currently have a meaningful number of space characters carefully placed to render with proper indentation. With Sprig, we can instead say "print this string at indentation level 2."

Before:

// note the invisible two spaces preceding "listeners:"
{{ if .Router.IsPrivate }}#{{ end }}  listeners:

After:

{{ if .Router.IsPrivate }}#{{ end }}{{- "listeners:" | nindent 2 }}
@dovholuknf
Copy link
Member

personally, i don't see the need for another dependency for this. agree it's annoying but i'm fine with the annoyance to keep yet another dependency out of our code

@qrkourier
Copy link
Member Author

I found another way to make the template slightly less error prone:

{{- if and (not .Router.IsFabric) (eq .Router.TunnelerMode "tproxy") (.Router.Edge.LanInterface) }}
      lanIf: {{ .Router.Edge.LanInterface }}
{{- end }}
{{- if and (not .Router.IsFabric) (eq .Router.TunnelerMode "tproxy") (.Router.Edge.DnsSvcIpRange ) }}
      dnsSvcIpRange: {{ .Router.Edge.DnsSvcIpRange }}
{{- end }}

This way, the conditionally-rendered lines are left-justified, so indentation errors are more visible at a glance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants