Given a Helm chart directory or file, renders all templates and writes them to the specified directory
(isFile bool, mainChartPath string, opt chartutil.ReleaseOptions)
| 18 | |
| 19 | // Given a Helm chart directory or file, renders all templates and writes them to the specified directory |
| 20 | func RenderHelmChart(isFile bool, mainChartPath string, opt chartutil.ReleaseOptions) ([]sgTypes.ManifestFile, error) { |
| 21 | if isFile { // Get the directory that the Chart.yaml lives in |
| 22 | mainChartPath = filepath.Dir(mainChartPath) |
| 23 | } |
| 24 | |
| 25 | mainChart, err := loader.Load(mainChartPath) |
| 26 | if err != nil { |
| 27 | return nil, fmt.Errorf("failed to load main chart: %s", err) |
| 28 | } |
| 29 | |
| 30 | loadedCharts := make(map[string]*chart.Chart) // map of chart path to chart object |
| 31 | loadedCharts[mainChartPath] = mainChart |
| 32 | |
| 33 | // Load subcharts and dependencies |
| 34 | for _, dep := range mainChart.Metadata.Dependencies { |
| 35 | // Resolve the chart path based on the main chart's directory |
| 36 | chartPath := filepath.Join(mainChartPath, dep.Repository[len("file://"):]) |
| 37 | chartPath = filepath.Clean(chartPath) |
| 38 | |
| 39 | subChart, err := loader.Load(chartPath) |
| 40 | if err != nil { |
| 41 | return nil, fmt.Errorf("failed to load chart: %s", err) |
| 42 | } |
| 43 | loadedCharts[chartPath] = subChart |
| 44 | } |
| 45 | |
| 46 | var manifestFiles []sgTypes.ManifestFile |
| 47 | for chartPath, chart := range loadedCharts { |
| 48 | valuesPath := filepath.Join(chartPath, "values.yaml") // Enforce that values.yaml must be at same level as Chart.yaml |
| 49 | mergedValues, err := getValues(chart, valuesPath, opt, filepath.Base(mainChartPath)) |
| 50 | if err != nil { |
| 51 | return nil, fmt.Errorf("failed to load values: %s", err) |
| 52 | } |
| 53 | e := engine.Engine{Strict: true} |
| 54 | renderedFiles, err := e.Render(chart, mergedValues) |
| 55 | if err != nil { |
| 56 | return nil, fmt.Errorf("failed to render chart: %s", err) |
| 57 | } |
| 58 | |
| 59 | // Convert renderd files to []byte |
| 60 | for renderedPath, content := range renderedFiles { |
| 61 | byteContent := []byte(content) |
| 62 | manifestFiles = append(manifestFiles, sgTypes.ManifestFile{Name: filepath.Base(renderedPath), ManifestContent: byteContent}) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return manifestFiles, nil |
| 67 | } |
| 68 | |
| 69 | // Given a kustomization manifest file within kustomizationPath, RenderKustomizeManifest will return render templates |
| 70 | func RenderKustomizeManifest(kustomizationPath string) ([]sgTypes.ManifestFile, error) { |