From 5367c6c296847ad2fc3645df0e3f189c10907c26 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Tue, 14 May 2019 11:00:20 -0700 Subject: [PATCH] fix(loader): assume apiVersion is v1 when loading charts In Helm 2, no chart validation was performed on v1 charts, so there are a few charts out there that never added an apiVersion to the Chart.yaml. To ensure those charts continue to work for Helm 3, we should assume that charts loaded without an apiVersion set should be assumed as v1. Signed-off-by: Matthew Fisher --- pkg/chart/loader/load.go | 6 ++++++ pkg/chart/loader/testdata/albatross/Chart.yaml | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index cd886d8c7..2642d87b6 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -79,6 +79,12 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil { return c, errors.Wrap(err, "cannot load Chart.yaml") } + // NOTE(bacongobbler): while the chart specification says that APIVersion must be set, + // Helm 2 accepted charts that did not provide an APIVersion in their chart metadata. + // Because of that, if APIVersion is unset, we should assume we're loading a v1 chart. + if c.Metadata.APIVersion == "" { + c.Metadata.APIVersion = chart.APIVersionV1 + } case f.Name == "Chart.lock": c.Lock = new(chart.Lock) if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil { diff --git a/pkg/chart/loader/testdata/albatross/Chart.yaml b/pkg/chart/loader/testdata/albatross/Chart.yaml index b5188fde0..eeef737ff 100644 --- a/pkg/chart/loader/testdata/albatross/Chart.yaml +++ b/pkg/chart/loader/testdata/albatross/Chart.yaml @@ -1,4 +1,3 @@ -apiVersion: v1 name: albatross description: A Helm chart for Kubernetes version: 0.1.0