From 0482ba3b6f9c7b7a56ecc73b68735640094ac154 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 8 Sep 2020 11:23:36 +0900 Subject: [PATCH] Fix `index out of range [1] with length 1` error on env2map (#1463) This happened only when helmfile is run in an environment that any environment variable definition does not include `=` and the right side. --- pkg/helmexec/runner.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/helmexec/runner.go b/pkg/helmexec/runner.go index c798f48e..d7604078 100644 --- a/pkg/helmexec/runner.go +++ b/pkg/helmexec/runner.go @@ -107,7 +107,16 @@ func env2map(env []string) map[string]string { wanted := map[string]string{} for _, cur := range env { pair := strings.SplitN(cur, "=", 2) - wanted[pair[0]] = pair[1] + + var v string + + // An environment can completely miss `=` and the right side. + // If we didn't deal with that, this may fail due to an index-out-of-range error + if len(pair) > 1 { + v = pair[1] + } + + wanted[pair[0]] = v } return wanted }