From 7f2d0063bc4454111eaade9025e927ec2652adcc Mon Sep 17 00:00:00 2001 From: Yusuke KUOKA Date: Wed, 3 Jul 2019 12:35:43 +0900 Subject: [PATCH] fix "concurrent map read/write" panics Fixes #737 --- pkg/state/state.go | 4 ++++ pkg/state/state_exec_tmpl.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/state/state.go b/pkg/state/state.go index 3518d0fc..d949fcd0 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -10,6 +10,7 @@ import ( "sort" "strconv" "strings" + "sync" "github.com/roboll/helmfile/pkg/environment" "github.com/roboll/helmfile/pkg/event" @@ -58,6 +59,9 @@ type HelmState struct { tempDir func(string, string) (string, error) runner helmexec.Runner + + vals map[string]interface{} + valsMutex sync.Mutex } // SubHelmfileSpec defines the subhelmfile path and options diff --git a/pkg/state/state_exec_tmpl.go b/pkg/state/state_exec_tmpl.go index 34a3573c..6ad4925f 100644 --- a/pkg/state/state_exec_tmpl.go +++ b/pkg/state/state_exec_tmpl.go @@ -8,6 +8,12 @@ import ( ) func (st *HelmState) Values() (map[string]interface{}, error) { + st.valsMutex.Lock() + defer st.valsMutex.Unlock() + if st.vals != nil { + return st.vals, nil + } + vals := map[string]interface{}{} if err := mergo.Merge(&vals, st.Env.Defaults, mergo.WithOverride); err != nil { @@ -22,6 +28,8 @@ func (st *HelmState) Values() (map[string]interface{}, error) { return nil, err } + st.vals = vals + return vals, nil }