What is different between {{ ... }} and {{- ... -}} syntax in Helm3? - helm3

I couldn't find any documentation, but I keep seeing examples.
Like:
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{- include "example.serviceAccountName" . -}} ##<=== {{- -}}
example: {{ .Values.example.example }} ##<=== {{ }}
labels:
{{- include "alma.labels" . | nindent 4 }} ##<=== {{- }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

Helm uses standard Go templating. Have a look at https://pkg.go.dev/text/template#hdr-Text_and_spaces In short {{- something }} means "trim left whitespace" and {{ something -}} means "trim right whitespace". | nindent 4 means "add 4 spaces before". You need this operators for correct indenting your yaml.

Related

error during helmfile.yaml.part.0 parsing :

I am running my pipeline in gitlab .. and this pipeline pull a helmfile from a github repo.. and when i am trying to deploy this error appears when start to put parsing because my values file like that
kubeContext: cech027
this is the helmfile
`
# Make sure we have the ENV variable set: {{ requiredEnv "ENV" }}
environments:
default:
values:
- environments/defaults.yaml.gotmpl
- versions.yaml
- {{ env "ENVCONFIG" |default ".." }}/config/defaults.yaml.gotmpl
- {{ env "ENVCONFIG" |default ".." }}/config/{{ requiredEnv "ENV" }}/values.yaml.gotmpl
- systemVersion: {{ (exec "./utils/git-version.sh" (list "")) }}
- kubeVersion: {{ (exec "./utils/kube-version.sh" (list .Values.kubeContext)) }}
secrets:
- {{ env "ENVCONFIG" |default ".." }}/config/secrets.yaml
- {{ env "ENVCONFIG" |default ".." }}/config/{{ requiredEnv "ENV" }}/secrets.yaml
local:
values:
- environments/defaults.yaml.gotmpl
- versions.yaml
- environments/local/values.yaml.gotmpl
- environments/local/secrets.yaml
{{- if eq (exec "./utils/fileexists.sh" (list "overrides.yaml.gotmpl")) "true"}}
- overrides.yaml.gotmpl
{{- end }}
{{- if eq (exec "./utils/fileexists.sh" (list "overrides.yaml")) "true"}}
- overrides.yaml
{{- end }}
- systemVersion: {{ (exec "./utils/git-version.sh" (list "dev")) }}
- kubeVersion: {{ (exec "./utils/kube-version.sh" (list .Values.kubeContext)) }}
---
repositories:
{{- if .Values.helm }}
- name: softsense
url: {{ .Values.helm.url }}
username: {{ .Values.helm.username }}
password: {{ .Values.helm.password }}
{{- if .Values.allowSnapshots }}
- name: softsense-dev
url: {{ .Values.helm.devURL }}
username: {{ .Values.helm.username }}
password: {{ .Values.helm.password }}
{{- end }}
{{- end }}
helmDefaults:
cleanupOnFail: true
verify: false # does not work with charts in directories
wait: true
timeout: 900
recreatePods: false # recreatePods is not supported in helm3
force: false
kubeContext: {{ .Values.kubeContext }} # force usage of a specific kube-context
createNamespace: false
`
but i have this error since a week ( and we did not do any changes) ..
the gitlab uses a runner to run this pipeline..
this is the error : rror during helmfile.yaml.part.0 parsing: template: stringTemplate:11:69: executing "stringTemplate" at <.Values.kubeContext>: map has no entry for key "kubeContext"
and when i run from my local machine it deployed successfully

Iterating through Helm Yaml Block

I have existing Configmap:
apiVersion: v1
kind: ConfigMap
metadata:
name: student
namespace: {{ .Release.Namespace }}
data:
student-1: |-
id: 4
name: "s1"
group_list:
- maths
- science
student-2: |-
id: 5
name: "s2"
group_list:
- finance
- history
I need to create mutliple configmaps student-1 , student-2 from the above configmap with following data.
For student-1:
apiVersion: v1
kind: ConfigMap
metadata:
name: student-1
annotation: "maths,science"
data:
enrolled: "maths,science"
For student-2:
enrolled: "finance,history"
Please help me to get the desired output format. Thank you !
Helm Template:
{{- range $k, $v := (lookup "v1" "ConfigMap" "default" "student").data }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $k }}
annotation: {{ $v1 | quote }}
data:
{{- range $k1, $v1 := fromYaml $v }}
enrolled: {{ $v1 | quote }}
{{- end }}
---
{{- end }}

Prometheus Opsgenie Integration

We use Prometheus alert manager for alerts, we have configured two receivers as attached below, Slack and Opsgenie.
The issue is that we are getting alerts in slack only but we are not receiving alerts in Opsgenie, we use the API keys and it's a working key, we tested it.
Not able to figure why we are not receiving alerts in Opsgenie too.
global:
resolve_timeout: 5m
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 30m
receiver: 'prod_alert_slack'
routes:
# Send severity=page alerts to the pager.
- match:
severity: critical|warning|page
receiver: team-pager
receivers:
- name: team-pager
opsgenie_configs:
- responders:
- name: 'Oncall'
type: 'team'
api_key: XXXXXXXXXXXXXXXXX
- name: 'prod_alert_slack'
slack_configs:
- api_url: https://hooks.slack.com/services/XXXXXXXX/XXXXXXXXXXXX
channel: '#prodslack'
send_resolved: true
username: '{{ template "slack.default.username" . }}'
color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
title: '{{ template "slack.default.title" . }}'
title_link: '{{ template "slack.default.titlelink" . }}'
pretext: '{{ .CommonAnnotations.summary }}'
text: |-
{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
*Description:* {{ .Annotations.description }}
*Message:* {{ .Annotations.message }}
*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
fallback: '{{ template "slack.default.fallback" . }}'
icon_emoji: '{{ template "slack.default.iconemoji" . }}'
icon_url: '{{ template "slack.default.iconurl" . }}'
#text: "summary: {{ .CommonAnnotations.summary }}\ndescription: {{ .CommonAnnotations.description }}"
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']```

How to translate a config file in Hugo?

I'm using Hugo for the first time and I'm having troubles with translations.
More specifically, I'm using the hugo-theme-bootstrap theme. In config\_default, I have a file named author.toml that contains information like the author's name, bio, city, etc. It looks like this:
name = "Pascal Bergeron"
avatar = "images/profile.jpg"
bio = "Description française."
location = "Montréal"
The issue is that this file is used for both the English and French versions of my website. However, I need the bio and location fields to change according to the language. I've tried creating a file named author.fr.toml, but its settings end up being ignored. In fact, if I even rename author.toml to author.en.toml, the settings will be ignored for the English language. It's as if I can only have a author.toml file. This is strange because I can translate all other files in my config folder that way (I have a params.en.toml and a params.fr.toml file for instance).
I've done some digging in the layouts folder of my theme and I've found the file where the author.toml is used to create the HTML code. It looks like this:
{{- with .Site.Author -}}
<section class="profile surface row">
<div class="col-xl-6 d-flex align-items-center justify-content-center">
<img class="profile-avatar img-fluid" src="{{ absURL (default "images/profile.webp" .avatar) }}" alt="{{ .name }}" loading="lazy">
</div>
<div class="col-xl-6">
<h5 class="profile-name my-2">{{ .name }}</h5>
{{- with .bio -}}
<div class="profile-bio mb-2">{{ . }}</div>
{{- end -}}
{{- with .company -}}
<div class="profile-company mb-2"><i class="fas fa-fw fa-building"></i>{{ . }}</div>
{{- end -}}
{{- with .location -}}
<div class="profile-location mb-2"><i class="fas fa-fw fa-map-marker-alt"></i>{{ . }}</div>
{{- end -}}
{{- if .about -}}
<div class="profile-about mb-2"><i class="fas fa-fw fa-info-circle"></i><a target="_blank" href="{{ .about }}">{{ i18n "about_me" }}</a></div>
{{- else -}}
{{- with $.GetPage "about" -}}
<div class="profile-about mb-2"><i class="fas fa-fw fa-info-circle"></i>{{ .Title }}</div>
{{- end -}}
{{- end -}}
</div>
</section>
{{- end -}}
How can I have a author.toml file for each language?
(TLDR - The site author set-up the author data as 1 config file - i.e. Theme is built for 1 author for the entire site).
Hello Pascal, so, really appreciated you took the time to answer me.
To clarify:
This isn't a "hugo" thing, but the way this chap built this theme.
You are going to have to modify his theme (or reach out to him). The specific file in question, as you point out, I believe is profile.html in sidebar:
{{- if .Site.Author -}}
{{- $layout := default "" .Site.Author.params.layout -}}
{{- if eq $layout "compact" -}}
{{- partial "sidebar/profile/compact" . -}}
{{- else -}}
{{- partial "sidebar/profile/default" . -}}
{{- end -}}
{{- end -}}
If you follow the various partials this calls, i.e. down the rabbit whole you will find an example (this is one of many), like you describe and quote in your question, it has the specific comment {{ - with .Site.Author - }} meaning, it's looking for exactly 1 file, with a specific name.
[https://gohugo.io/content-management/multilingual/][1]
covers how to set-up a hugo multilingual - and there is SUPPOSED to be 1 Config file per site (which has it's own meaning in Hugo - see above page)
Point being, this is a theme issue, and I would suggest asking the theme creator to adapt edit.
My suggestion would be if the theme creator isn't helpful - would be to remove the dependency for the TOML file, and simply reference a headless bundle which has the author data, and as the theme has i18n, integrate the two (see above link) so that their is a headless bundle per language.

confd newbie trying to get if in template to work getting "invalid type for comparison"

I have exported a variable:
export myparam=one
I have template: file.tmpl :
myproptmpl =
{{ if eq .myparam "one" }}
{{ "one" }}
{{ else }}
{{ "something else" }}
{{ end }}
And when I run confd I get:
# /usr/bin/confd -onetime -backend env
2016-04-20T15:21:58Z 8faae31d53a1 /usr/bin/confd[91]: ERROR template: file.tmpl:70:6: executing "file.tmpl" at <eq .myparam "one">: error calling eq: invalid type for comparison
I'm a newbie on confd. How can I compare an OS environment variable to values and based on them generate different resulting output file out of template?
You need get the variable first and after that then you can compare.
Ex.:
myproptmpl =
{{ if eq (getv .myparam) "one" }}
{{ "one" }}
{{ else }}
{{ "something else" }}
{{ end }}

Resources