Fix values file override

`io.Read` was used incorrectly to read from the override file provided
by the user.
This is now replaced with `ioutil.ReadFile` for better handling and
error reporting.

Fixes #263

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
This commit is contained in:
Aurel Canciu 2021-01-21 13:21:14 +02:00
parent 00d9d1d209
commit f1b5768200
No known key found for this signature in database
GPG Key ID: AB25339971E6F81E
1 changed files with 2 additions and 9 deletions

View File

@ -504,19 +504,12 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
err = fmt.Errorf("invalid values file path: %s", chart.Spec.ValuesFile)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}
src, err := os.Open(srcPath)
if err != nil {
err = fmt.Errorf("failed to open values file '%s': %w", chart.Spec.ValuesFile, err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}
defer src.Close()
var valuesData []byte
if _, err := src.Read(valuesData); err != nil {
valuesData, err := ioutil.ReadFile(srcPath)
if err != nil {
err = fmt.Errorf("failed to read from values file '%s': %w", chart.Spec.ValuesFile, err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}
isValuesFileOverriden, err = helm.OverwriteChartDefaultValues(helmChart, valuesData)
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPackageFailedReason, err.Error()), err