in pkg/safeguards/preprocessing/preprocessing.go [20:67]
func RenderHelmChart(isFile bool, mainChartPath string, opt chartutil.ReleaseOptions) ([]sgTypes.ManifestFile, error) {
if isFile { // Get the directory that the Chart.yaml lives in
mainChartPath = filepath.Dir(mainChartPath)
}
mainChart, err := loader.Load(mainChartPath)
if err != nil {
return nil, fmt.Errorf("failed to load main chart: %s", err)
}
loadedCharts := make(map[string]*chart.Chart) // map of chart path to chart object
loadedCharts[mainChartPath] = mainChart
// Load subcharts and dependencies
for _, dep := range mainChart.Metadata.Dependencies {
// Resolve the chart path based on the main chart's directory
chartPath := filepath.Join(mainChartPath, dep.Repository[len("file://"):])
chartPath = filepath.Clean(chartPath)
subChart, err := loader.Load(chartPath)
if err != nil {
return nil, fmt.Errorf("failed to load chart: %s", err)
}
loadedCharts[chartPath] = subChart
}
var manifestFiles []sgTypes.ManifestFile
for chartPath, chart := range loadedCharts {
valuesPath := filepath.Join(chartPath, "values.yaml") // Enforce that values.yaml must be at same level as Chart.yaml
mergedValues, err := getValues(chart, valuesPath, opt, filepath.Base(mainChartPath))
if err != nil {
return nil, fmt.Errorf("failed to load values: %s", err)
}
e := engine.Engine{Strict: true}
renderedFiles, err := e.Render(chart, mergedValues)
if err != nil {
return nil, fmt.Errorf("failed to render chart: %s", err)
}
// Convert renderd files to []byte
for renderedPath, content := range renderedFiles {
byteContent := []byte(content)
manifestFiles = append(manifestFiles, sgTypes.ManifestFile{Name: filepath.Base(renderedPath), ManifestContent: byteContent})
}
}
return manifestFiles, nil
}