-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make my helmfile DRY? #860
Comments
Hey! Basically, it depends. That's because everyone has different goal even though the word is "DRY". In this specific case, you have a single helmfile.yaml, a conventional naming rule for If so, I'd suggest extracting the common structure into a reusable go template:
|
OK thank you @mumoshu, helpful as always 😃 You can close this issue if you wish. |
This example should be in the readme. |
@mumoshu FYI you are missing Can we loop over a list of apps instead of having a line for |
@max-rocket-internet Thanks for the correction! Re: looping, it should look like:
|
@mumoshu is there a way I could define multiple |
@max-rocket-internet It isn't possible at the moment, unfortunately. A workaround exists though - try |
OK here's what I've done after this help from @mumoshu... For context, we have around 400 releases, spread across 8 clusters and around 20 helmfiles. Our (simplified) directory structure now looks like this: helmfiles
├── infra-cluster1.yaml
├── main.yaml
├── prd.yaml
├── stg.yaml
└── templates
├── app.yaml
├── infra-charts.yaml
helmfiles:
- prd.yaml
- stg.yaml
- infra-cluster1.yaml
{{ $apps := list "app1" "app2" "app3" }}
releases:
{{ range $_, $app := $apps }}
{{ tpl (readFile "templates/app.yaml") (dict "App" $app "Env" "prd01" ) }}
{{ tpl (readFile "templates/app.yaml") (dict "App" $app "Env" "prd02" ) }}
{{ tpl (readFile "templates/app.yaml") (dict "App" $app "Env" "prd03" ) }}
{{ end }}
{{ $apps := list "app3" "app4" }}
releases:
{{ range $_, $app := $apps }}
{{ tpl (readFile "templates/app.yaml") (dict "App" $app "Env" "stg01" ) }}
{{ tpl (readFile "templates/app.yaml") (dict "App" $app "Env" "qa02" ) }}
{{ end }}
- name: {{.Env}}-{{.App}}
chart: ../charts/apps/{{.App}}
kubeContext: {{.kubeContext}}
labels:
app: {{.App}}
env: {{.Env}}
values:
- ../charts/apps/{{.App}}/values/{{.Env}}/values.yaml
secrets:
- ../charts/apps/{{.App}}/values/{{.Env}}/secrets.yaml
{{ $cluster_name := "cluster1" }}
releases:
{{ tpl (readFile "templates/infra-charts.yaml") (dict "Cluster" $cluster_name "cluster_autoscaler_version" "3.2.0" "datadog_version" "1.32.1" "external_dns_version" "1.7.5" "ingress_version" "1.17.1" "metrics_server_version" "2.8.4" ) }}
- name: cluster-autoscaler
chart: stable/cluster-autoscaler
kubeContext: {{.Cluster}}
namespace: kube-system
version: {{.cluster_autoscaler_version}}
labels:
app: cluster-autoscaler
cluster: {{.Cluster}}
values:
- ../cluster-config/helm-value-files/cluster-autoscaler/{{.Cluster}}/values.yaml
- name: datadog
chart: stable/datadog
kubeContext: {{.Cluster}}
namespace: kube-system
version: {{.datadog_version}}
labels:
app: datadog
cluster: {{.Cluster}}
values:
- ../cluster-config/helm-value-files/datadog/{{.Cluster}}/values.yaml
secrets:
- ../cluster-config/helm-value-files/datadog/{{.Cluster}}/secrets.yaml
- name: external-dns
chart: stable/external-dns
kubeContext: {{.Cluster}}
namespace: kube-system
version: {{.external_dns_version}}
labels:
app: external-dns
cluster: {{.Cluster}}
values:
- ../cluster-config/helm-value-files/external-dns/{{.Cluster}}/values.yaml
- name: ingress01
chart: stable/nginx-ingress
kubeContext: {{.Cluster}}
version: {{.ingress_version}}
labels:
app: nginx-ingress-private
cluster: {{.Cluster}}
values:
- ../cluster-config/helm-value-files/nginx-ingress/{{.Cluster}}/values-private.yaml
... This enabled us to go from around 4000 lines of YAML in helmfiles to around 300. Hopefully this can help someone else 😃 |
@mumoshu do you know of a way to test if a Helm chart values file exists, then include it if so? i.e a condition that evaluates the existence of a file. I tried |
@max-rocket-internet I believe
|
Hi, I have a similar use case which I'm trying to work out.
I would like to template each of the releases when loading them. Any suggestions? Thanks |
Hi, @mumoshu , could you please clarify if there is a possibility to reference a value from values file in this kind of templates? {{ define "app" }}
- name: {{ .Name }}
namespace: {{ .Namespace }}
chart: chartrepo/{{ .Name }}
version: {{ .Version }}
labels:
app: {{ .Name }}
level: apps
values:
- {{ .Name }}/values.gotmpl
{{ end }}
releases:
{{ template "app" (dict "Name" "app1" "Namespace" `{{ .Values.Namespace }}` "Version" "1.0.7" )}}
{{ template "app" (dict "Name" "app2" "Namespace" `{{ .Values.Namespace }}` "Version" "1.0.3" )}}
{{ template "app" (dict "Name" "app3" "Namespace" `{{ .Values.Namespace }}` "Version" "1.0.4" )}} the above code gives me
what's the correct syntax here?
|
@sigurdblueface Sorry I can't get what you're trying. What should |
Anyway, using bare "`" within go template seems impossible by its nature. |
@mumoshu my goal is to have ability to specify a release namespace via values file Project structure is:
'parent' helmfile:
'child' helmfile could be seen in my previous comment well, let's say the default.yaml file is:
so I'd like the code below
to result in:
|
@sigurdblueface To me, it seems like you'd want to write:
|
hey, sorry to bother you, but how you would do something like the person above, but I need to use range because I have 10+ apps:
the above works if I hardcode
update for anyone wondering:
|
I've read writing-helmfile.md but honestly still don't understand how it's supposed to work 😅
Here's my helmfile:
How imagine I have 30 apps, app1-30, how can I make this helmfile nice and DRY? Can I loop over a list somewhere?
The text was updated successfully, but these errors were encountered: