From bf6060d35370bf729189a00e0b0e0b698cf31c4b Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sat, 29 Mar 2025 04:50:16 +0400 Subject: [PATCH] fix: make initialization a standalone process to account for concurrent calls --- k8-operator/packages/template/template.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/k8-operator/packages/template/template.go b/k8-operator/packages/template/template.go index e4e24ac2a..d56b3da5d 100644 --- a/k8-operator/packages/template/template.go +++ b/k8-operator/packages/template/template.go @@ -6,8 +6,6 @@ import ( "github.com/Masterminds/sprig/v3" ) -var initialized = false - var customInfisicalSecretTemplateFunctions = tpl.FuncMap{ "pkcs12key": pkcs12key, "pkcs12keyPass": pkcs12keyPass, @@ -45,12 +43,7 @@ const ( pemTypeKey = "PRIVATE KEY" ) -func GetTemplateFunctions() tpl.FuncMap { - // we don't want to run this whole function every time because it's expensive, so we cache the result after the first run - if initialized { - return customInfisicalSecretTemplateFunctions - } - +func InitializeTemplateFunctions() { templates := customInfisicalSecretTemplateFunctions sprigFuncs := sprig.TxtFuncMap() @@ -67,7 +60,8 @@ func GetTemplateFunctions() tpl.FuncMap { } customInfisicalSecretTemplateFunctions = templates - initialized = true +} - return templates +func GetTemplateFunctions() tpl.FuncMap { + return customInfisicalSecretTemplateFunctions }