From 0bbab7cbb9aefe8e01eb0697acef4cf02a2179d4 Mon Sep 17 00:00:00 2001 From: "robert.holosynskyi" Date: Tue, 24 Aug 2021 12:42:33 +0200 Subject: [PATCH] Respect original Chart.yaml when 'helm create -p' Signed-off-by: robert.holosynskyi --- cmd/helm/create.go | 11 +---------- pkg/chartutil/create.go | 5 ++--- pkg/chartutil/create_test.go | 15 +++++---------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index fe5cc540a..0d6e9f100 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -24,7 +24,6 @@ import ( "github.com/spf13/cobra" "helm.sh/helm/v3/cmd/helm/require" - "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/helmpath" ) @@ -88,14 +87,6 @@ func (o *createOptions) run(out io.Writer) error { fmt.Fprintf(out, "Creating %s\n", o.name) chartname := filepath.Base(o.name) - cfile := &chart.Metadata{ - Name: chartname, - Description: "A Helm chart for Kubernetes", - Type: "application", - Version: "0.1.0", - AppVersion: "0.1.0", - APIVersion: chart.APIVersionV2, - } if o.starter != "" { // Create from the starter @@ -104,7 +95,7 @@ func (o *createOptions) run(out io.Writer) error { if filepath.IsAbs(o.starter) { lstarter = o.starter } - return chartutil.CreateFrom(cfile, filepath.Dir(o.name), lstarter) + return chartutil.CreateFrom(chartname, filepath.Dir(o.name), lstarter) } chartutil.Stderr = out diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index ca79e7ab2..ce6724348 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -511,13 +511,12 @@ spec: var Stderr io.Writer = os.Stderr // CreateFrom creates a new chart, but scaffolds it from the src chart. -func CreateFrom(chartfile *chart.Metadata, dest, src string) error { +func CreateFrom(chartname, dest, src string) error { schart, err := loader.Load(src) if err != nil { return errors.Wrapf(err, "could not load %s", src) } - - schart.Metadata = chartfile + schart.Metadata.Name = chartname var updatedTemplates []*chart.File diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index 9a473fc59..e2edd1a56 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -23,7 +23,6 @@ import ( "path/filepath" "testing" - "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" ) @@ -76,25 +75,21 @@ func TestCreateFrom(t *testing.T) { } defer os.RemoveAll(tdir) - cf := &chart.Metadata{ - APIVersion: chart.APIVersionV1, - Name: "foo", - Version: "0.1.0", - } + chartname := "foo" srcdir := "./testdata/frobnitz/charts/mariner" - if err := CreateFrom(cf, tdir, srcdir); err != nil { + if err := CreateFrom(chartname, tdir, srcdir); err != nil { t.Fatal(err) } - dir := filepath.Join(tdir, "foo") - c := filepath.Join(tdir, cf.Name) + dir := filepath.Join(tdir, chartname) + c := filepath.Join(tdir, chartname) mychart, err := loader.LoadDir(c) if err != nil { t.Fatalf("Failed to load newly created chart %q: %s", c, err) } - if mychart.Name() != "foo" { + if mychart.Name() != chartname { t.Errorf("Expected name to be 'foo', got %q", mychart.Name()) }