Helmfile migration¶
Suppose we have next helmfile.yaml
helmfile.yaml
environments:
dev:
kubeContext: dev
values:
- filebeat:
enabled: true
- minio:
enabled: true
- gitlab:
enabled: false
- grafana:
enabled: true
prod:
kubeContext: prod
values:
- filebeat:
enabled: true
- minio:
enabled: false
- gitlab:
enabled: true
- grafana:
enabled: false
repositories:
- name: gitlab
url: https://charts.gitlab.io/
helmDefaults:
atomic: true
historyMax: 3
timeout: 1200
releases:
- name: gitlab
condition: gitlab.enabled
chart: gitlab/gitlab
version: 7.2.2
namespace: gitlab
values:
- ./values/{{ .Environment.Name }}/gitlab.yaml
- name: minio
condition: minio.enabled
chart: ./charts/minio
namespace: minio
values:
- ./values/{{ .Environment.Name }}/minio.gotmpl
secrets:
- ./values/{{ .Environment.Name }}/minio-secret.yaml
- name: grafana
condition: grafana.enabled
chart: ./charts/grafana
namespace: grafana
values:
- ./values/{{ .Environment.Name }}/grafana.yaml
secrets:
- ./values/{{ .Environment.Name }}/grafana-secrets.yaml
- name: filebeat
condition: filebeat.enabled
chart: ./charts/filebeat
namespace: filebeat
values:
- ./values/{{ .Environment.Name }}/filebeat.yaml
secrets:
- ./values/{{ .Environment.Name }}/filebeat-secrets.yaml
How to migrate it to helmwave.yml.tpl
?
Repository¶
repositories:
- name: gitlab
url: https://charts.gitlab.io/
repositories:
- name: gitlab
url: https://charts.gitlab.io/
Environments¶
Helmwave can use gomplate templater to resolve this problem.
export HELMWAVE_TEMPLATER=gomplate
environments:
dev:
kubeContext: dev
values:
- filebeat:
enabled: true
- minio:
enabled: true
- gitlab:
enabled: false
- grafana:
enabled: true
prod:
kubeContext: prod
values:
- filebeat:
enabled: true
- minio:
enabled: false
- gitlab:
enabled: true
- grafana:
enabled: false
-
Create
envs.yml
for storing environment settings.envs.ymlenvs: dev: kubecontext: dev releases: minio: true grafana: true filebeat: true prod: kubecontext: prod releases: gitlab: true filebeat: true
-
Add next code to helmwave.yml.tpl
helmwave.yml.tpl{{- $env := getenv "ENV" -}} {{- defineDatasource "envs" "envs.yml" -}} {{- $envs := (ds "envs").envs -}} # It'll chose env setting by $ENV {{ $e := index $envs $env }} ...
Matching release with environment¶
environments:
dev:
kubeContext: dev
values:
- gitlab:
enabled: false
...
releases:
- name: gitlab
condition: gitlab.enabled
...
helmwave.yml.tpl
...
{{ $r := $e.releases }}
releases:
{{- if (index $r "gitlab") }}
- name: gitlab
chart: gitlab/gitlab
version: 7.2.2
namespace: gitlab
tags: ["gitlab"]
values:
- ./values/{{ $env }}/gitlab.yaml
{{- end }}
...
Helm Defaults¶
Just use yaml anchors.
helmDefaults:
atomic: true
historyMax: 3
timeout: 1200
helmwave.yml.tpl
.options: &options
atomic: true
timeout: 1200
max_history: 3
releases:
- name: gitlab
<<: *options
Matching kubecontext with environment¶
environments:
dev:
kubeContext: dev
helmwave.yml.tpl
{{- $kubecontext := $e.kubecontext -}}
.options: &options
atomic: true
timeout: 1200
max_history: 3
context: {{ $kubecontext }}
releases:
- name: gitlab
<<: *options
Results¶
environments:
dev:
kubeContext: dev
values:
- filebeat:
enabled: true
- minio:
enabled: true
- gitlab:
enabled: false
- grafana:
enabled: true
prod:
kubeContext: prod
values:
- filebeat:
enabled: true
- minio:
enabled: false
- gitlab:
enabled: true
- grafana:
enabled: false
repositories:
- name: gitlab
url: https://charts.gitlab.io/
helmDefaults:
atomic: true
historyMax: 3
timeout: 1200
releases:
- name: gitlab
condition: gitlab.enabled
chart: gitlab/gitlab
version: 7.2.2
namespace: gitlab
values:
- ./values/{{ .Environment.Name }}/gitlab.yaml
- name: minio
condition: minio.enabled
chart: ./charts/minio
namespace: minio
values:
- ./values/{{ .Environment.Name }}/minio.gotmpl
secrets:
- ./values/{{ .Environment.Name }}/minio-secret.yaml
- name: grafana
condition: grafana.enabled
chart: ./charts/grafana
namespace: grafana
values:
- ./values/{{ .Environment.Name }}/grafana.yaml
secrets:
- ./values/{{ .Environment.Name }}/grafana-secrets.yaml
- name: filebeat
condition: filebeat.enabled
chart: ./charts/filebeat
namespace: filebeat
values:
- ./values/{{ .Environment.Name }}/filebeat.yaml
secrets:
- ./values/{{ .Environment.Name }}/filebeat-secrets.yaml
helmwave.yml.tpl
{{- $env := getenv "ENV" -}}
{{- defineDatasource "envs" "envs.yml" -}}
{{- $envs := (ds "envs").envs -}}
{{ $e := index $envs $env }}
{{- $kubecontext := $e.kubecontext -}}
{{ $r := $e.releases }}
repositories:
- name: gitlab
url: https://charts.gitlab.io/
.options: &options
context: {{ $kubecontext }}
atomic: true
timeout: 1200
max_history: 3
releases:
{{- if (index $r "gitlab") }}
- name: gitlab
<<: *options
chart: gitlab/gitlab
version: 7.2.2
namespace: gitlab
tags: ["gitlab"]
values:
- ./values/{{ $env }}/gitlab.yaml
{{- end }}
{{- if (index $r "minio") }}
- name: minio
chart: ./charts/minio
namespace: minio
values:
- ./values/{{ $env }}/minio.yaml
secrets:
- src: ./values/{{ $env }}/minio-secret.yaml
renderer: sops
{{- end }}
{{- if (index $r "grafana") }}
- name: grafana
chart: ./charts/grafana
namespace: grafana
values:
- src: ./values/{{ $env }}/grafana.yaml
renderer: copy
secrets:
- src: ./values/{{ $env }}/grafana-secret.yaml
renderer: sops
{{- end }}
{{- if (index $r "filebeat") }}
- name: filebeat
chart: ./charts/filebeat
namespace: filebeat
values:
- ./values/{{ $env }}/filebeat.yaml
secrets:
- src: ./values/{{ $env }}/filebeat-secret.yaml
renderer: sops
{{- end }}
envs.yml
envs:
dev:
kubecontext: dev
releases:
minio: true
grafana: true
filebeat: true
prod:
kubecontext: prod
releases:
gitlab: true
filebeat: true