The notes at https://github.com/roboll/helmfile/blob/master/README.md#L903 say that you can parse input to the exec function and it will get passed to the stdin of the command running in the exec function. However I can't seem to get this to work at all, the result always seems to come back as "null".
Example as follows
a.sh is a shell script that simply echos what is parsed to stdin
$ cat a.sh
#!/bin/bash
read var
echo $var
$ echo 'asdf' | ./a.sh
asdf
I use it in the following helmfile
$ cat helmfile.yaml
---
repositories:
# Kubernetes incubator repo of helm charts
- name: "kubernetes-incubator"
url: "https://kubernetes-charts-incubator.storage.googleapis.com"
releases:
- name: test
chart: "kubernetes-incubator/raw"
namespace: default
version: "0.2.3"
installed: true
values:
- resources:
- apiVersion: v1
kind: Secret
metadata:
name: test
stringData:
test: {{ "asdf" | (exec "./a.sh" (list "")) }}
And it produces the following
$ helmfile template
Adding repo kubernetes-incubator https://kubernetes-charts-incubator.storage.googleapis.com
"kubernetes-incubator" has been added to your repositories
Updating repo
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "kubernetes-incubator" chart repository
...Successfully got an update from the "cloudposse-incubator" chart repository
...Successfully got an update from the "gitlab" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete.
Fetching kubernetes-incubator/raw
Templating release=test, chart=/tmp/122827334/test/0.2.3/kubernetes-incubator/raw/raw
---
# Source: raw/templates/resources.yaml
---
apiVersion: v1
kind: Secret
metadata:
labels:
app: raw
chart: raw-0.2.3
heritage: Tiller
release: test
name: test
stringData:
test: null
I would expect the test value under stringData to be "asdf"
Doing some debugging and testing I think I have successfully narrowed down some interaction with closing the writeErrs chan and when it's closed. If I comment out this line https://github.com/roboll/helmfile/blob/master/pkg/tmpl/context_funcs.go#L72 then everything works as expected.
I'm no expert but I think what might be happening is nil is being read from writeErrs channel, trigiring the select statement to return it instead of bytes. If I change the code at line 105 to
for {
select {
case bytes := <-cmdOuts:
return string(bytes), nil
case err, isErr := <-cmdErrs:
if isErr {
return "", err
}
case err, isErr := <-writeErrs:
if isErr {
return "", err
}
}
}
It seems to work as expected
@ggillies Thanks for reporting! You're absolutely correct - this is a bug.
Fortunately, as I'm seemingly a better Go programmer than me who wrote this a year ago, I've managed to fix it in #1151.
Would you mind giving it a shot once the new Helmfille release with the fix is published?
v0.102.1 has been released with the fix
@mumoshu thanks so much for looking at this! Just tested and v0.102.1 has fixed this for me!
Most helpful comment
@mumoshu thanks so much for looking at this! Just tested and v0.102.1 has fixed this for me!