@@ -121,12 +121,12 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
121121 // it was compressed from. So, we can check if the file name contains the required file names
122122 // Ex: helm-chart/Chart.yaml, helm-chart/values.yaml
123123 if strings .Contains (header .Name , chartFileName ) {
124- if err := c .validateYamlFile (tarReader ); err != nil {
124+ if err := c .validateYamlFile (tarReader , false ); err != nil {
125125 return nil , fmt .Errorf ("invalid Chart.yaml file: %w" , err )
126126 }
127127 chartFileValid = true
128128 } else if strings .Contains (header .Name , chartValuesYamlFileName ) {
129- if err := c .validateYamlFile (tarReader ); err != nil {
129+ if err := c .validateYamlFile (tarReader , true ); err != nil {
130130 return nil , fmt .Errorf ("invalid values.yaml file: %w" , err )
131131 }
132132 chartValuesValid = true
@@ -148,9 +148,14 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
148148}
149149
150150// validateYamlFile validates the YAML file just by trying to unmarshal it
151- func (c * HelmChartCrafter ) validateYamlFile (r io.Reader ) error {
151+ func (c * HelmChartCrafter ) validateYamlFile (r io.Reader , allowEmpty bool ) error {
152152 v := make (map [string ]interface {})
153153 if err := yaml .NewDecoder (r ).Decode (v ); err != nil {
154+ // io.EOF means the file is empty or contains only comments
155+ // This is valid for values.yaml
156+ if err == io .EOF && allowEmpty {
157+ return nil
158+ }
154159 return fmt .Errorf ("failed to unmarshal YAML file: %w" , err )
155160 }
156161
0 commit comments