Skip to content

Commit

Permalink
fix(controller): Performance improvement for Sprig. Fixes #6135 (#6140)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jun 14, 2021
1 parent 868868e commit 8059932
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions util/expr/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import (
"encoding/json"

"github.com/Masterminds/sprig"

exprpkg "github.com/argoproj/pkg/expr"
"github.com/doublerebel/bellows"
)

var sprigFuncMap = sprig.GenericFuncMap() // a singleton for better performance

func init() {
delete(sprigFuncMap, "env")
delete(sprigFuncMap, "expandenv")
}

func GetFuncMap(m map[string]interface{}) map[string]interface{} {
env := bellows.Expand(m)
for k, v := range exprpkg.GetExprEnvFunctionMap() {
env[k] = v
}
delete(env, "env")
delete(env, "expandenv")
env["toJson"] = toJson
env["sprig"] = sprig.GenericFuncMap()
env["sprig"] = sprigFuncMap
return env
}

Expand Down

0 comments on commit 8059932

Please sign in to comment.