Open l-rossetti opened 4 years ago
Sorry, but you can't refer to chart values from helmfile template. Helmfile's {{.Values}}` is for helmfile state values, which is a completely different concept than chart values.
and what about .Release.Values
?
Or what's the suggested approach for sharing a value between multiple files?
What's .Release.Values
?
Anyway, you'd just add the same values.yaml
under values
of every release. Or just generate release/chart values from helmfile state values:
values:
- foo:
bar: 1
releases:
- name: yourapp
values:
- {{ .Values | toYaml | nindent 4 }}
or
values:
- foo:
bar: 1
releases:
- name: yourapp
values:
foobar: "{{ .Values.foo.bar }}"
Thank you for answering.
About .Release.Values
I found it in issue https://github.com/roboll/helmfile/issues/978 and I blindly tried it.
About your proposal I'm not sure it can be applied to my context. Let me explain.
I have a docker image version 2.7.1-test and I would like this version to be re-used in multiple places avoiding misalignment :
Something like:
releases:
- name: myapp
chart: myrepo/myapp
version: 1.1.0
values:
- values/myapp.default.values.yaml
- image:
tag: 2.7.1-test <----------------- here
hooks:
- events: [ "presync" ]
showlogs: true
command: "skopeo"
args: [
"copy",
"docker://src.com/path/myapp:{{`{{ .Values.image.tag }}`}}", <--- here
"docker://dest.com/path/myapp:{{`{{ .Values.image.tag }}`}}" <--- here
]
@l-rossetti Thanks. What you're trying to do is actually impossible. You'd need to lift it to use state values. I'd suggest something like the below:
values:
- myapp:
image:
tag: 2.7.1-test
releases:
- name: myapp
chart: myrepo/myapp
version: 1.1.0
values:
- values/myapp.default.values.yaml
- image:
tag: {{ .Values.myapp.image.tag }} <----------------- here
hooks:
- events: [ "presync" ]
showlogs: true
command: "skopeo"
args: [
"copy",
"docker://src.com/path/myapp:{{`{{ .Values.myapp.image.tag }}`}}", <--- here
"docker://dest.com/path/myapp:{{`{{ .Values.myapp.image.tag }}`}}" <--- here
]
@mumoshu I've tried your idea, but I got 2 issues:
the utilization of .Values in hook causes:
in ./helmfile.yaml: failed processing release myapp: hook[scripts/copy-docker-image.sh]: template: stringTemplate:1:10: executing "stringTemplate" at <.Values.myapp.image.tag>: map has no entry for key "Values"
the utilization in release values cause:
in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1: yaml: invalid map key: map[interface {}]interface {}{".Values.myapp.image.tag":interface {}(nil)}
tried with helmfile 0.116.0 and 0.109.0 + helm 2.16.1
@l-rossetti Gotcha! What if you tried this? Please note that there's ---
which ensures that the values
are loaded and parsed before rendering the latter part of your helmfile.yaml
values:
- myapp:
image:
tag: 2.7.1-test
---
releases:
- name: myapp
chart: myrepo/myapp
version: 1.1.0
values:
- values/myapp.default.values.yaml
- image:
tag: {{ .Values.myapp.image.tag }} <----------------- here
hooks:
- events: [ "presync" ]
showlogs: true
command: "skopeo"
args: [
"copy",
"docker://src.com/path/myapp:{{`{{ .Values.myapp.image.tag }}`}}", <--- here
"docker://dest.com/path/myapp:{{`{{ .Values.myapp.image.tag }}`}}" <--- here
]
@mumoshu this works like a charm! Thanks for your prompt help! (and sorry for the little delay)
I also want to highlight that values in hook args can be referenced simply by {{ .Values.myapp.image.tag }}
without using the {{` backtick notation.
I have the following
values/myapp.dev.values.yaml
:And
helmfile.yaml
:I face two issues. First In the hook, which is copying docker images from a registry to another one, I would like to make use of the
image.tag
value coming frommyapp.dev.values.yaml
, i tried:{{`{{ .Values.image.tag }}`}}
, but I get:in ./helmfile.yaml: failed processing release myapp: hook[skopeo]: template: stringTemplate:1:78: executing "stringTemplate" at <.Values.image.tag>: map has no entry for key "Values"
{{`{{ .Release.Values.image.tag }}`}}
, but I get:in ./helmfile.yaml: failed processing release myapp: hook[skopeo]: template: stringTemplate:1:79: executing "stringTemplate" at <.Release.Values.image.tag>: can't evaluate field image in type []interface {}
Second How can I make the
repository
value invalues/myapp.dev.values.yaml
parametric with respect to values defined indev
environment ? Or there's maybe a better way by making use of what is defined inrepositories
?