@@ -19,6 +19,7 @@ import (
1919 "archive/tar"
2020 "compress/gzip"
2121 "context"
22+ "errors"
2223 "fmt"
2324 "io"
2425 "os"
@@ -121,12 +122,12 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
121122 // it was compressed from. So, we can check if the file name contains the required file names
122123 // Ex: helm-chart/Chart.yaml, helm-chart/values.yaml
123124 if strings .Contains (header .Name , chartFileName ) {
124- if err := c .validateYamlFile (tarReader ); err != nil {
125+ if err := c .validateYamlFile (tarReader , false ); err != nil {
125126 return nil , fmt .Errorf ("invalid Chart.yaml file: %w" , err )
126127 }
127128 chartFileValid = true
128129 } else if strings .Contains (header .Name , chartValuesYamlFileName ) {
129- if err := c .validateYamlFile (tarReader ); err != nil {
130+ if err := c .validateYamlFile (tarReader , true ); err != nil {
130131 return nil , fmt .Errorf ("invalid values.yaml file: %w" , err )
131132 }
132133 chartValuesValid = true
@@ -148,9 +149,14 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
148149}
149150
150151// validateYamlFile validates the YAML file just by trying to unmarshal it
151- func (c * HelmChartCrafter ) validateYamlFile (r io.Reader ) error {
152+ func (c * HelmChartCrafter ) validateYamlFile (r io.Reader , allowEmpty bool ) error {
152153 v := make (map [string ]interface {})
153154 if err := yaml .NewDecoder (r ).Decode (v ); err != nil {
155+ // io.EOF means the file is empty or contains only comments
156+ // This is valid for values.yaml
157+ if errors .Is (err , io .EOF ) && allowEmpty {
158+ return nil
159+ }
154160 return fmt .Errorf ("failed to unmarshal YAML file: %w" , err )
155161 }
156162
0 commit comments