error during helmfile.yaml.part.0 parsing : - devops

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

Related

Howto change output of inja2 template with ansible

In the Ansible Jinja Template, I have to Change the output charaktere
This works without any Letters
{{% endraw %} should eq {{ test_yml['php::settings']['PHP/max_execution_time'] }} {% raw %}}
Output Result = 60
{{% endraw %} should eq {{ test_yml['php::settings']['PHP/memory_limit'] }} {% raw %}}
Output Result = 16M, but I need this Result '16M' with the charaktere 'output'
I tested the following
[ {{'}} 'PHP/max_execution_time' {{'}} ]
[ (') 'PHP/max_execution_time' (') ] .....

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 }}

What is different between {{ ... }} and {{- ... -}} syntax in 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.

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']```

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