Skip to content
Permalink
Browse files
fix(helm): fix werf_secret_file not working in werf helm template com…
…mand

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Jun 6, 2022
1 parent 23d3469 commit b2cec4b20a4f929b5ed729f6bf2ba271da5d2af7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
@@ -2,8 +2,13 @@ package helpers

import (
"context"
"fmt"
"path"
"strings"
"text/template"

"github.com/werf/werf/pkg/deploy/helm/chart_extender/helpers/secrets"

Check failure on line 10 in pkg/deploy/helm/chart_extender/helpers/common_template_funcs.go

GitHub Actions / Lint

pkg/deploy/helm/chart_extender/helpers/common_template_funcs.go#L10

Expected 'l', Found 'w' at pkg/deploy/helm/chart_extender/helpers/common_template_funcs.go[line 10,col 19] (gci)

"github.com/werf/logboek"
)

@@ -26,3 +31,24 @@ func SetupWerfImageDeprecationFunc(ctx context.Context, funcMap template.FuncMap
return "", nil
}
}

func SetupWerfSecretFile(secretsRuntimeData *secrets.SecretsRuntimeData, funcMap template.FuncMap) {
funcMap["werf_secret_file"] = func(secretRelativePath string) (string, error) {
if path.IsAbs(secretRelativePath) {
return "", fmt.Errorf("expected relative secret file path, given path %v", secretRelativePath)
}

decodedData, ok := secretsRuntimeData.DecodedSecretFilesData[secretRelativePath]

if !ok {
var secretFiles []string
for key := range secretsRuntimeData.DecodedSecretFilesData {
secretFiles = append(secretFiles, key)
}

return "", fmt.Errorf("secret file %q not found, you may use one of the following: %q", secretRelativePath, strings.Join(secretFiles, "', '"))
}

return decodedData, nil
}
}
@@ -6,9 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"text/template"

"github.com/mitchellh/copystructure"
@@ -196,25 +194,7 @@ func (wc *WerfChart) MakeBundleValues(chrt *chart.Chart, inputVals map[string]in

// SetupTemplateFuncs method for the chart.Extender interface
func (wc *WerfChart) SetupTemplateFuncs(t *template.Template, funcMap template.FuncMap) {
funcMap["werf_secret_file"] = func(secretRelativePath string) (string, error) {
if path.IsAbs(secretRelativePath) {
return "", fmt.Errorf("expected relative secret file path, given path %v", secretRelativePath)
}

decodedData, ok := wc.SecretsRuntimeData.DecodedSecretFilesData[secretRelativePath]

if !ok {
var secretFiles []string
for key := range wc.SecretsRuntimeData.DecodedSecretFilesData {
secretFiles = append(secretFiles, key)
}

return "", fmt.Errorf("secret file %q not found, you may use one of the following: %q", secretRelativePath, strings.Join(secretFiles, "', '"))
}

return decodedData, nil
}

helpers.SetupWerfSecretFile(wc.SecretsRuntimeData, funcMap)
helpers.SetupIncludeWrapperFuncs(funcMap)
helpers.SetupWerfImageDeprecationFunc(wc.ChartExtenderContext, funcMap)
}
@@ -114,9 +114,7 @@ func (wc *WerfChartStub) MakeValues(inputVals map[string]interface{}) (map[strin

// SetupTemplateFuncs method for the chart.Extender interface
func (wc *WerfChartStub) SetupTemplateFuncs(t *template.Template, funcMap template.FuncMap) {
funcMap["werf_secret_file"] = func(secretRelativePath string) (string, error) {
return "stub_data", nil
}
helpers.SetupWerfSecretFile(wc.SecretsRuntimeData, funcMap)
helpers.SetupIncludeWrapperFuncs(funcMap)
helpers.SetupWerfImageDeprecationFunc(wc.ChartExtenderContext, funcMap)
}

0 comments on commit b2cec4b

Please sign in to comment.