MCPcopy
hub / github.com/helmfile/helmfile / generateChartPath

Method generateChartPath

pkg/state/state.go:5168–5196  ·  view source on GitHub ↗

generateChartPath generates the path of the output directory for chart downloads (e.g., fetch, pull, OCI chart downloads). It uses a go template with data from the chart name, output directory, release spec, and environment. If no template was provided (via the `--output-dir-template` flag) it uses

(chartName string, outputDir string, release *ReleaseSpec, outputDirTemplate string)

Source from the content-addressed store, hash-verified

5166// It uses a go template with data from the chart name, output directory, release spec, and environment.
5167// If no template was provided (via the `--output-dir-template` flag) it uses the DefaultFetchOutputDirTemplate.
5168func (st *HelmState) generateChartPath(chartName string, outputDir string, release *ReleaseSpec, outputDirTemplate string) (string, error) {
5169 if outputDirTemplate == "" {
5170 outputDirTemplate = DefaultFetchOutputDirTemplate
5171 }
5172
5173 t, err := template.New("output-dir-template").Parse(outputDirTemplate)
5174 if err != nil {
5175 return "", fmt.Errorf("parsing output-dir-template template %q: %w", outputDirTemplate, err)
5176 }
5177
5178 buf := &bytes.Buffer{}
5179 // Template data for output-dir-template. Environment provides .Name, .KubeContext, and .Values fields.
5180 data := struct {
5181 ChartName string
5182 OutputDir string
5183 Release ReleaseSpec
5184 Environment environment.Environment
5185 }{
5186 ChartName: chartName,
5187 OutputDir: outputDir,
5188 Release: *release,
5189 Environment: st.Env,
5190 }
5191 if err := t.Execute(buf, data); err != nil {
5192 return "", fmt.Errorf("executing output-dir-template template: %w", err)
5193 }
5194
5195 return buf.String(), nil
5196}
5197
5198func (st *HelmState) GenerateOutputFilePath(release *ReleaseSpec, outputFileTemplate string) (string, error) {
5199 // get absolute path of state file to generate a hash

Callers 4

processLocalChartMethod · 0.95
forcedDownloadChartMethod · 0.95
getOCIChartPathMethod · 0.95
TestGenerateChartPathFunction · 0.95

Calls 3

ParseMethod · 0.80
StringMethod · 0.80
ExecuteMethod · 0.65

Tested by 1

TestGenerateChartPathFunction · 0.76