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)
| 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. |
| 5168 | func (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 | |
| 5198 | func (st *HelmState) GenerateOutputFilePath(release *ReleaseSpec, outputFileTemplate string) (string, error) { |
| 5199 | // get absolute path of state file to generate a hash |