roboll / helmfile

Deploy Kubernetes Helm Charts
MIT License
4.04k stars 566 forks source link

Question: Possible to use release tags in a templated helmfile? #1593

Open jrowinski3d opened 3 years ago

jrowinski3d commented 3 years ago

Hi there,

Fairly new to helmfile but seems like it can solve a lot of my problems and get me moving towards my end goal. I'm playing around with the templating my helmfile to manage releases and environments.

My issue:

I noticed that when I run a sync for app-a for a specific enviornment it creates a release in helm as app-a . My desired state would be that it would be called demo-app-a.

My helmfile.yaml

environments:
  demo:
  develop:
  qa:
  staging:
  production:

helmDefaults:
  atomic: true
  cleanupOnFail: true
  createNamespace: false

templates:
  default: &default
    chart: charts/{{`{{ .Release.Name }}`}}
    values:
    - charts/{{`{{ .Release.Name }}`}}/values-{{ .Environment.Name }}.yaml
    missingFileHandler: Warn

releases:
- name: dbmigrator
  <<: *default
  labels:
    name: dbmigrator

My desired state would be something along these lines so it can appropriately find the chart/values.yaml

  demo:
  develop:
  qa:
  staging:
  production:

helmDefaults:
  atomic: true
  cleanupOnFail: true
  createNamespace: false

templates:
  default: &default
    chart: charts/{{`{{ .Release.Labels.tag "name" }}`}}
    values:
    - charts/{{`{{ .Release.Labels.tag "name" }}`}}/values-{{ .Environment.Name }}.yaml
    missingFileHandler: Warn

releases:
- name: {{ .Environment.Name }}-dbmigrator
  <<: *default
  labels:
    name: dbmigrator

Is there some built in function/method in helmfile that can manage this or am I going about this the wrong way? I know I can specify the values/charts per release. But adding more and more releases it might add too much repetitive code in the helmfile.

Thanks!

jrowinski3d commented 3 years ago

Seems I have solved my own question, for anyone that comes this way. I believe the name label is some reserved name for releases. I switched it to tier , I guess it can be whatever you like.

Helmfile now:

environments:
  demo1:
  develop1:
  qa:
  staging:
  production:

helmDefaults:
  atomic: true
  cleanupOnFail: true
  createNamespace: false

templates:
  default: &default
    chart: charts/{{`{{ .Release.Labels.tier }}`}}
    values:
      - charts/{{`{{ .Release.Labels.tier }}`}}/values-{{ .Environment.Name }}.yaml
    missingFileHandler: Warn

releases:
- name: dbmigrator-{{ .Environment.Name }}
  <<: *default
  labels:
    tier: dbmigrator

Results:

 helm ls
NAME                                    NAMESPACE               REVISION        UPDATED                                 STATUS          CHART                                   APP VERSION
dbmigrator-demo1      xxxx       1               2020-11-18 14:04:53.957727688 -0800 PST deployed        dbmigrator-0.1.0      0.1.0

Pods:

NAME                                                              READY   STATUS      RESTARTS   AGE
dbmigrator-demo1-1-q5wc8                                            0/2     Completed   0          2m35s