#helmfile - April 2023

Ivo
Ivoover 3 years ago(edited)
What is the best way to check for a directory existence in a helmfile.yaml template? Value files can be safely ignored if they don't exist, but I have a use-case for conditionally including a chart folder. And if that folder doesn't exist, the release will fail.
Ivo
Ivoover 3 years ago
I currently have this little snippet but it's failing for me with the following error: can't evaluate field Environment in type fs.DirEntry
{{ range $index,$item := readDirEntries "./policies" }}
{{- if eq $item.Name .Environment.Name -}}
- name: policies-{{ .Environment.Name }}
  chart: ./policies/{{ .Environment.Name }}
{{- end -}}
{{- end -}}
Ivo
Ivoover 3 years ago
Seems a little stupid to iterate over all the directories but I couldn't find a 'direct' check. Is there any way to avoid the dot being evaluated as a fs.DirEntry and use the environment name instead?
Ivo
Ivoover 3 years ago
Putting it in a variable outside the loop {{ $env := .Environment.Name }} seems to trigger the same error.
Alexander Taran
Alexander Taranover 3 years ago
Hi gents
Is it possible to somehow use template values un Chart.yaml?
I have a library chart and based on environment I need to specify registry for the lib chart.
Chart.yaml example that I want to achieve but this doesn’t work:
apiVersion: v2
name: datasources
version: 0.1.0
description: Chart to deploy 
dependencies:
  - name: common
    version: 1.2.0
    repository: "{{ .StateValues.registry.helm }}"

Brandon Nason
Brandon Nasonover 3 years ago(edited)
I've just stumbled upon helmfile and it looks like it can really solve some of my pain points with helm and my workarounds (custom shell scripts). The main thing I need is the ability to add new manifests (with env vars). It looks like this is done by using a dependency incubator/raw which expects the manifests to be inline. so 1) Is there a way to put those manifests into their own files with requiredEnv support and 2) it appears incubator/raw is deprecated. Should I be using something different?
voron
voronover 3 years ago
I'm curious is there an option to specify helmfile environment (helmfile -e ) via OS environment variable ?
Nathanael
Nathanaelover 3 years ago(edited)
I'm try to use HELMFILE_V1MODE=true because we want to be prepared but i think our concept does break with v1 🤔

We do nested helmfiles (terraform-module-like) but we also want to 'gotemplate the sub-helmfile itself. We used helmfile.yaml for the sub-helmfile and with the HELMFILE_V1MODE=true i'm forced to change the filename to helmfile.yaml.gotmpl if i do that, the main execution of the parrent helmfile returns this error:
err: no releases found that matches specified selector() and environment(stagename), in any helmfile

(no i do not intend to use selectors so no labels, no selectors are used)
why is that? and is our entire concept borken with v1 ? 😟
Dominic Cardellino
Dominic Cardellinoover 3 years ago
I got a question and maybe it is already answered a thousand times 😄
I really love to use helmfile, but how do I handle the creation of Kubernetes Manifests(like ConfigMaps, Secrets etc.) outside of a Helm Chart.
Currently I use terraform to deploy kubernetes resources (kubernetes provider) and helm releases (helm provider), but it just feels kind of wrong at sometime to use terraform for this
yxxhero
yxxheroover 3 years ago
Aljoscha Weber
Aljoscha Weberover 3 years ago
Hey together, hopefully a small question: how does one apply a helmfile which includes sub-helmfiles?
My current unexpected result is "no releases found that match my selector() and environment(dev)
I'm trying to setup a layered helmfile and staying as DRY as i can - my use case is for example multiple mongdb-databases and they are 90% the same with only minor diffs in the values (persistence size for example):

070-my-service-mongodb.yaml.gotmpl:
bases:
  - 000-environments.yaml.gotmpl
  - 000-repositories.yaml

---

helmfiles:
  - path: _mongodb.helmfile.yaml.gotmpl
    values:
    - {{ toYaml .Values | nindent 4 }}
    - releaseName: my-service-mongodb
      releaseNamespace: {{ .Values.myMainNamespace }}

000-environments.yaml.gotmpl:
environments:
  default:
    values:
      - "../environments/dev.values.yaml"
  dev:
    values:
      - "../environments/dev.values.yaml"

---

helmDefaults:
  kubeContext: {{ .Values.kubeContext }}
  verify: false
  wait: true
  timeout: 1800
  tls: false

_mongodb.helmfile.yaml.gotmpl:
---
releases:
- name: {{ .Values.releaseName }}
  installed: true
  namespace: {{ .Values.releaseNamespace }}
  labels:
    release: "{{`{{ .Release.Name }}`}}"
    namespace: "{{`{{ .Release.Namespace }}`}}"
  chart: bitnami/mongodb
  version: {{ .Values.bitnamiMongoDbChartVersion }}
  values:
    - "../values/infrastructure/mongodb/mongodb.values.yaml.gotmpl"
  wait: true

- name: {{ .Values.releaseName }}-backup
  namespace: {{ .Values.releaseNamespace }}
  labels:
    release: "{{`{{ .Release.Name }}`}}"
    namespace: "{{`{{ .Release.Namespace }}`}}"
    type: backup
  chart: myCharts/jobs
  version: {{ .Values.jobsChartVersion }}
  values:
    - "../values/infrastructure/mongodb/mongodb-backup.values.yaml.gotmpl"
  wait: true

Output of HELMFILE_V1MODE=true helmfile --debug -i -f ~/IdeaProjects/my-helmfile/helmfile.d/070-my-service-mongodb.yaml.gotmpl -e dev apply

...
A LOT OF ENV + ENV_DEBUG
...
rendering result of "_mongodb.helmfile.yaml.gotmpl.part.0":
 0: ---
 1: releases:
 2: - name: my-service-mongodb
 3:   installed: true
 4:   namespace: my-service-dev
 5:   labels:
 6:     release: "{{ .Release.Name }}"
 7:     namespace: "{{ .Release.Namespace }}"
 8:   chart: bitnami/mongodb
 9:   version: 13.9.4
10:   values:
11:     - "../values/infrastructure/mongodb/mongodb.values.yaml.gotmpl"
12:   wait: true
13: 
14: - name: my-service-mongodb-backup
15:   namespace: my-service-dev
16:   labels:
17:     release: "{{ .Release.Name }}"
18:     namespace: "{{ .Release.Namespace }}"
19:     type: backup
20:   chart: myCharts/jobs
21:   version: 13.9.4
22:   values:
23:     - "../values/infrastructure/mongodb/mongodb-backup.values.yaml.gotmpl"
24:   wait: true
25: 

changing working directory back to "/Users/PRIVATE/IdeaProjects/my-helmfile/helmfile.d"
helm:XBjnS> v3.11.2+g912ebc1
helm:XBjnS> 
Adding repo bitnami <https://charts.bitnami.com/bitnami>
exec: helm --kube-context my-aks repo add bitnami <https://charts.bitnami.com/bitnami> --force-update
helm:MRUSy> "bitnami" has been added to your repositories
helm:MRUSy> 
"bitnami" has been added to your repositories

0 release(s) found in 070-my-service-mongodb.yaml.gotmpl:

changing working directory back to "/Users/PRIVATE/IdeaProjects/my-helmfile/helmfile.d"
err: no releases found that matches specified selector() and environment(dev), in any helmfile

In the debug i can find the 2 releases and they look as i would expect it, but then they are not found for applying?
Dominic Cardellino
Dominic Cardellinoover 3 years ago
Hey together,

Did anyone experience this message with helmfile?

failed to render [values.yaml.gotmpl], because of template: stringTemplate:113: function "toUpper" not defined

Trying to render sth like this:

templateFiles:
  {{ define "slack.title" -}}
    [{{ .Status | toUpper -}}
    {{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
    ] {{ .CommonLabels.alertname }}
  {{- end }}

  {{ define "slack.text" -}}

It is my prometheus alertmanager config which uses this functions
Elisha Bello
Elisha Belloover 3 years ago(edited)
hey guys
I'm trying to achieve path base routing in an ALB created BY AWS Load Balancer Controller upon ingress object been initialise

apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
name: {{ .Chart.Name }}-ingress-rules
annotations:
<http://alb.ingress.kubernetes.io/scheme|alb.ingress.kubernetes.io/scheme>: internet-facing
<http://alb.ingress.kubernetes.io/target-type|alb.ingress.kubernetes.io/target-type>: ip
<http://alb.ingress.kubernetes.io/group.name|alb.ingress.kubernetes.io/group.name>: {{ .Values.ingress.lbGroup }}
<http://alb.ingress.kubernetes.io/load-balancer-name|alb.ingress.kubernetes.io/load-balancer-name>: {{ .Values.ingress.lbGroup }}
<http://alb.ingress.kubernetes.io/listen-ports|alb.ingress.kubernetes.io/listen-ports>: '[{"HTTP":80},{"HTTPS":443}]'
<http://alb.ingress.kubernetes.io/ssl-redirect|alb.ingress.kubernetes.io/ssl-redirect>: "443"
<http://alb.ingress.kubernetes.io/security-groups|alb.ingress.kubernetes.io/security-groups>: {{ .Values.ingress.securityGroup }}
<http://external-dns.alpha.kubernetes.io/hostname|external-dns.alpha.kubernetes.io/hostname>: {{ .Values.ingress.host }}
<http://external-dns.alpha.kubernetes.io/alias|external-dns.alpha.kubernetes.io/alias>: "true"
spec:
ingressClassName: alb
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: {{ .Values.ingress.intercomPath }}
pathType: Prefix
backend:
service:
name: {{ .Values.ingress.intercomServiceName }}
port:
number: {{ .Values.ingress.intercomServicePort }}

- path: {{ .Values.ingress.engagePath }}
pathType: Prefix
backend:
service:
name: {{ .Values.ingress.engageServiceName }}
port:
number: {{ .Values.ingress.engageServicePort }}

- path: {{ .Values.ingress.usersPath }}
pathType: Prefix
backend:
service:
name: {{ .Values.ingress.usersServiceName }}
port:
number: {{ .Values.ingress.usersServicePort }}

- path: {{ .Values.ingress.enrichPath }}
pathType: Prefix
backend:
service:
name: {{ .Values.ingress.enrichServiceName }}
port:
number: {{ .Values.ingress.enrichServicePort }}

For some reason it seems not to work