Skip to content

Commit f4fdb87

Browse files
committed
fix(helm-chart): allow empty values
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent b3dc82d commit f4fdb87

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

pkg/attestation/crafter/materials/helmchart.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

pkg/attestation/crafter/materials/helmchart_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func TestHelmChartCraft(t *testing.T) {
102102
wantDigest: "sha256:08a46a850789938ede61d6a53552f48cb8ba74c4e17dcf30c9c50e5783ca6a13",
103103
wantFilename: "valid-chart.tgz",
104104
},
105+
{
106+
name: "chart with empty values.yaml",
107+
filePath: "./testdata/empty-values.tgz",
108+
wantDigest: "sha256:6c5bc910da7ecb00aa1c7be70e51db237d129e3f41ff6ada1d11ea402ff7082e",
109+
wantFilename: "empty-values.tgz",
110+
},
105111
}
106112

107113
assert := assert.New(t)
273 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)