From 1d4ced98e2c5adde2a85ebbf1d60aaf1491ed6ae Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Thu, 25 Aug 2022 21:57:22 +0200 Subject: [PATCH 1/7] feat(starter): enable preserving custom Chart.yaml using --keep-metadata flag Fixes helm/helm#4745 Fixes helm/helm#4060 Fixes helm/helm#7566 Fixes helm/helm#9551 Fixes helm/helm#10057 Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 27 ++++---- pkg/chartutil/create.go | 37 +++++++++-- pkg/chartutil/create_test.go | 64 ++++++++++++++++--- pkg/chartutil/save.go | 26 ++++++-- .../frobnitz/charts/custom/Chart.yaml | 29 +++++++++ .../charts/custom/templates/deployment.yaml | 24 +++++++ .../frobnitz/charts/custom/values.yaml | 22 +++++++ 7 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 pkg/chartutil/testdata/frobnitz/charts/custom/Chart.yaml create mode 100644 pkg/chartutil/testdata/frobnitz/charts/custom/templates/deployment.yaml create mode 100644 pkg/chartutil/testdata/frobnitz/charts/custom/values.yaml diff --git a/cmd/helm/create.go b/cmd/helm/create.go index b79752efb..52acb6670 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -21,10 +21,10 @@ import ( "io" "path/filepath" + "github.com/pkg/errors" "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" ) @@ -51,9 +51,10 @@ will be overwritten, but other files will be left alone. ` type createOptions struct { - starter string // --starter - name string - starterDir string + starter string // --starter + name string + starterDir string + keepMetadata bool } func newCreateCmd(out io.Writer) *cobra.Command { @@ -73,6 +74,13 @@ func newCreateCmd(out io.Writer) *cobra.Command { // No more completions, so disable file completion return nil, cobra.ShellCompDirectiveNoFileComp }, + PreRunE: func(cmd *cobra.Command, args []string) error { + if len(o.starter) == 0 && o.keepMetadata { + return errors.New("the -k/--keep-metadata flag can only be specified when using a starter") + } + + return nil + }, RunE: func(_ *cobra.Command, args []string) error { o.name = args[0] o.starterDir = helmpath.DataPath("starters") @@ -81,6 +89,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { } cmd.Flags().StringVarP(&o.starter, "starter", "p", "", "the name or absolute path to Helm starter scaffold") + cmd.Flags().BoolVarP(&o.keepMetadata, "keep-metadata", "k", false, "if specified, does not override the starter's Chart.yaml") return cmd } @@ -88,14 +97,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 +105,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(chartname), lstarter, o.keepMetadata) } chartutil.Stderr = out diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 50212f9d5..6f1c65437 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/pkg/errors" + "k8s.io/utils/strings/slices" "sigs.k8s.io/yaml" "helm.sh/helm/v3/pkg/chart" @@ -547,13 +548,15 @@ 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(name, dest, src string, keepMetadata bool) error { schart, err := loader.Load(src) if err != nil { return errors.Wrapf(err, "could not load %s", src) } - schart.Metadata = chartfile + if err = setMetadata(schart, name, keepMetadata); err != nil { + return errors.Wrap(err, "could not set metadata") + } var updatedTemplates []*chart.File @@ -574,12 +577,12 @@ func CreateFrom(chartfile *chart.Metadata, dest, src string) error { } schart.Values = m - // SaveDir looks for the file values.yaml when saving rather than the values - // key in order to preserve the comments in the YAML. The name placeholder - // needs to be replaced on that file. + // SaveDir looks for the files values.yaml and Chart.yaml when saving rather than the values + // and metadata keys in order to preserve the comments in the YAML. The name placeholder + // needs to be replaced on these files. for _, f := range schart.Raw { - if f.Name == ValuesfileName { - f.Data = transform(string(f.Data), schart.Name()) + if slices.Contains([]string{ValuesfileName, ChartfileName}, f.Name) { + f.Data = transform(string(f.Data), name) } } @@ -721,3 +724,23 @@ func validateChartName(name string) error { } return nil } + +func setMetadata(schart *chart.Chart, name string, keepMetadata bool) error { + for _, f := range schart.Raw { + if f.Name == ChartfileName { + // Overwrite Metadata only if flag was not set by user to keep backwards compatibility. + if !keepMetadata { + f.Data = []byte(fmt.Sprintf(defaultChartfile, name)) + } + + // Deserialize Metadata and check for errors + var m chart.Metadata + if err := yaml.Unmarshal(transform(string(f.Data), name), &m); err != nil { + return errors.Wrap(err, "transforming charts file") + } + schart.Metadata = &m + } + } + + return nil +} diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index 1697c4218..22e490c91 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -20,9 +20,9 @@ import ( "bytes" "os" "path/filepath" + "strings" "testing" - "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" ) @@ -67,19 +67,15 @@ func TestCreate(t *testing.T) { func TestCreateFrom(t *testing.T) { tdir := t.TempDir() - 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, false); err != nil { t.Fatal(err) } dir := filepath.Join(tdir, "foo") - c := filepath.Join(tdir, cf.Name) + 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) @@ -109,6 +105,58 @@ func TestCreateFrom(t *testing.T) { } } +func TestCreateFromKeepMetadata(t *testing.T) { + tdir := t.TempDir() + + chartname := "foo" + srcdir := "./testdata/frobnitz/charts/custom" + srcMetadata := filepath.Join(srcdir, ChartfileName) + rawMetadata, err := ioutil.ReadFile(srcMetadata) + if err != nil { + t.Errorf("Unable to read file %s: %s", srcMetadata, err) + } + + if err := CreateFrom(chartname, tdir, srcdir, true); err != nil { + t.Fatal(err) + } + + dir := filepath.Join(tdir, chartname) + mychart, err := loader.LoadDir(dir) + if err != nil { + t.Fatalf("Failed to load newly created chart %q: %s", dir, err) + } + + if mychart.Name() != "foo" { + t.Errorf("Expected name to be 'foo', got %q", mychart.Name()) + } + + expectedMetadata := strings.ReplaceAll(string(rawMetadata), "", chartname) + for _, f := range []string{ + ChartfileName, + ValuesfileName, + filepath.Join(TemplatesDir, "deployment.yaml"), + } { + if _, err := os.Stat(filepath.Join(dir, f)); err != nil { + t.Errorf("Expected %s file: %s", f, err) + } + + // Check each file to make sure has been replaced + b, err := ioutil.ReadFile(filepath.Join(dir, f)) + if err != nil { + t.Errorf("Unable to read file %s: %s", f, err) + } + if bytes.Contains(b, []byte("")) { + t.Errorf("File %s contains ", f) + } + + if f == ChartfileName { + if string(b) != expectedMetadata { + t.Errorf("%s does not contain expected content", ChartfileName) + } + } + } +} + // TestCreate_Overwrite is a regression test for making sure that files are overwritten. func TestCreate_Overwrite(t *testing.T) { tdir := t.TempDir() diff --git a/pkg/chartutil/save.go b/pkg/chartutil/save.go index 4ee90709c..8e3753549 100644 --- a/pkg/chartutil/save.go +++ b/pkg/chartutil/save.go @@ -26,6 +26,7 @@ import ( "time" "github.com/pkg/errors" + "k8s.io/utils/strings/slices" "sigs.k8s.io/yaml" "helm.sh/helm/v3/pkg/chart" @@ -51,15 +52,28 @@ func SaveDir(c *chart.Chart, dest string) error { return err } - // Save the chart file. - if err := SaveChartfile(filepath.Join(outdir, ChartfileName), c.Metadata); err != nil { - return err + // Check if Chart has raw metadata stored + hasRawMetadata := false + for _, f := range c.Raw { + if f.Name == ChartfileName { + hasRawMetadata = true + } } - // Save values.yaml + // This ensures that the Chart always has raw metadata stored, since some tests + // call SaveDir without adding raw metadata to the Chart. + if !hasRawMetadata { + b, err := yaml.Marshal(c.Metadata) + if err != nil { + return errors.Wrap(err, "reading charts file") + } + c.Raw = append(c.Raw, &chart.File{Name: ChartfileName, Data: b}) + } + + // Save values.yaml and Chart.yaml for _, f := range c.Raw { - if f.Name == ValuesfileName { - vf := filepath.Join(outdir, ValuesfileName) + if slices.Contains([]string{ValuesfileName, ChartfileName}, f.Name) { + vf := filepath.Join(outdir, f.Name) if err := writeFile(vf, f.Data); err != nil { return err } diff --git a/pkg/chartutil/testdata/frobnitz/charts/custom/Chart.yaml b/pkg/chartutil/testdata/frobnitz/charts/custom/Chart.yaml new file mode 100644 index 000000000..8371ebefc --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz/charts/custom/Chart.yaml @@ -0,0 +1,29 @@ +apiVersion: v2 +name: +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" + +dependencies: + - name: albatross + repository: https://example.com/mariner/charts + version: "0.1.0" diff --git a/pkg/chartutil/testdata/frobnitz/charts/custom/templates/deployment.yaml b/pkg/chartutil/testdata/frobnitz/charts/custom/templates/deployment.yaml new file mode 100644 index 000000000..2de3173fe --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz/charts/custom/templates/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include ".fullname" . }} + labels: + {{- include ".labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include ".selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include ".selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP diff --git a/pkg/chartutil/testdata/frobnitz/charts/custom/values.yaml b/pkg/chartutil/testdata/frobnitz/charts/custom/values.yaml new file mode 100644 index 000000000..63975d498 --- /dev/null +++ b/pkg/chartutil/testdata/frobnitz/charts/custom/values.yaml @@ -0,0 +1,22 @@ +# Default values for . +# This is a YAML-formatted file. https://github.com/toml-lang/toml +# Declare name/value pairs to be passed into your templates. +# name: "value" + +: + test: true + +replicaCount: 1 + +image: + repository: "" + pullPolicy: IfNotPresent + tag: latest + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 From c45230d849d618c3c0f8580b9ee0f09186b7dab7 Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 9 Sep 2022 00:09:56 +0200 Subject: [PATCH 2/7] Maintain backwards compatibility by introducing chartutil.CreateFromWithMetadata Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 2 +- pkg/chartutil/create.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index 52acb6670..247049c67 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -105,7 +105,7 @@ func (o *createOptions) run(out io.Writer) error { if filepath.IsAbs(o.starter) { lstarter = o.starter } - return chartutil.CreateFrom(chartname, filepath.Dir(chartname), lstarter, o.keepMetadata) + return chartutil.CreateFromWithMetadata(chartname, filepath.Dir(chartname), lstarter, o.keepMetadata) } chartutil.Stderr = out diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 6f1c65437..f4c951ec8 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -548,7 +548,15 @@ spec: var Stderr io.Writer = os.Stderr // CreateFrom creates a new chart, but scaffolds it from the src chart. -func CreateFrom(name, dest, src string, keepMetadata bool) error { +// Deprecated: Use CreateFromWithMetadata +// TODO Helm 4: Fold CreateFromWithMetadata back into CreateFrom +func CreateFrom(chartfile *chart.Metadata, dest, src string) error { + return CreateFromWithMetadata(chartfile.Name, dest, src, false) +} + +// CreateFromWithMetadata creates a new chart, but scaffolds it from the src chart and +// provides the option to preserve custom metadata (Chart.yaml) files. +func CreateFromWithMetadata(name, dest, src string, keepMetadata bool) error { schart, err := loader.Load(src) if err != nil { return errors.Wrapf(err, "could not load %s", src) From fcf7c14039dca93b020706f5dd6b956d7242037b Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 9 Sep 2022 13:02:04 +0200 Subject: [PATCH 3/7] Rework override mechanism for helm create with starters Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 15 +++++++++++- pkg/chartutil/create.go | 47 ++++++++++++++++++++++++------------ pkg/chartutil/create_test.go | 13 +++++++--- pkg/chartutil/save.go | 1 + 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index 247049c67..a3f5fdba8 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -23,6 +23,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/pkg/chartutil" @@ -97,6 +98,18 @@ 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.keepMetadata { + cfile = nil + } if o.starter != "" { // Create from the starter @@ -105,7 +118,7 @@ func (o *createOptions) run(out io.Writer) error { if filepath.IsAbs(o.starter) { lstarter = o.starter } - return chartutil.CreateFromWithMetadata(chartname, filepath.Dir(chartname), lstarter, o.keepMetadata) + return chartutil.CreateFromWithOverride(chartname, filepath.Dir(chartname), lstarter, cfile) } chartutil.Stderr = out diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index f4c951ec8..54c6be53c 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -548,22 +548,23 @@ spec: var Stderr io.Writer = os.Stderr // CreateFrom creates a new chart, but scaffolds it from the src chart. -// Deprecated: Use CreateFromWithMetadata -// TODO Helm 4: Fold CreateFromWithMetadata back into CreateFrom +// Deprecated: Use CreateFromWithOverride +// TODO Helm 4: Fold CreateFromWithOverride back into CreateFrom func CreateFrom(chartfile *chart.Metadata, dest, src string) error { - return CreateFromWithMetadata(chartfile.Name, dest, src, false) + return CreateFromWithOverride(chartfile.Name, dest, src, chartfile) } -// CreateFromWithMetadata creates a new chart, but scaffolds it from the src chart and -// provides the option to preserve custom metadata (Chart.yaml) files. -func CreateFromWithMetadata(name, dest, src string, keepMetadata bool) error { +// CreateFromWithOverride creates a new chart, but scaffolds it from the src chart and +// provides the option to override the chart's metadata (Chart.yaml). +func CreateFromWithOverride(name, dest, src string, override *chart.Metadata) error { schart, err := loader.Load(src) if err != nil { return errors.Wrapf(err, "could not load %s", src) } - if err = setMetadata(schart, name, keepMetadata); err != nil { - return errors.Wrap(err, "could not set metadata") + // Override the chart's metadata if the user requested it + if err := setMetadata(schart, name, override); err != nil { + return errors.Wrap(err, "setting metadata") } var updatedTemplates []*chart.File @@ -733,20 +734,36 @@ func validateChartName(name string) error { return nil } -func setMetadata(schart *chart.Chart, name string, keepMetadata bool) error { - for _, f := range schart.Raw { - if f.Name == ChartfileName { - // Overwrite Metadata only if flag was not set by user to keep backwards compatibility. - if !keepMetadata { - f.Data = []byte(fmt.Sprintf(defaultChartfile, name)) +func setMetadata(schart *chart.Chart, name string, override *chart.Metadata) error { + // Override the source chart's metadata and raw chart file content + // if the user provided a chart.Metadata struct + if override != nil { + schart.Metadata = override + for _, f := range schart.Raw { + if f.Name == ChartfileName { + metadataBytes, err := yaml.Marshal(schart.Metadata) + if err != nil { + return errors.Wrap(err, "marshalling metadata override") + } + + f.Data = metadataBytes + break } + } - // Deserialize Metadata and check for errors + return nil + } + + // Unmarshal Chart.yaml from source directory while replacing + // all placeholders if no override was requested + for _, f := range schart.Raw { + if f.Name == ChartfileName { var m chart.Metadata if err := yaml.Unmarshal(transform(string(f.Data), name), &m); err != nil { return errors.Wrap(err, "transforming charts file") } schart.Metadata = &m + break } } diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index 22e490c91..76b935208 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -23,6 +23,7 @@ import ( "strings" "testing" + "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" ) @@ -67,10 +68,16 @@ func TestCreate(t *testing.T) { func TestCreateFrom(t *testing.T) { tdir := t.TempDir() + cf := &chart.Metadata{ + APIVersion: chart.APIVersionV1, + Name: "foo", + Version: "0.1.0", + } + chartname := "foo" srcdir := "./testdata/frobnitz/charts/mariner" - if err := CreateFrom(chartname, tdir, srcdir, false); err != nil { + if err := CreateFrom(cf, tdir, srcdir); err != nil { t.Fatal(err) } @@ -105,7 +112,7 @@ func TestCreateFrom(t *testing.T) { } } -func TestCreateFromKeepMetadata(t *testing.T) { +func TestCreateFromWithOverride(t *testing.T) { tdir := t.TempDir() chartname := "foo" @@ -116,7 +123,7 @@ func TestCreateFromKeepMetadata(t *testing.T) { t.Errorf("Unable to read file %s: %s", srcMetadata, err) } - if err := CreateFrom(chartname, tdir, srcdir, true); err != nil { + if err := CreateFromWithOverride(chartname, tdir, srcdir, nil); err != nil { t.Fatal(err) } diff --git a/pkg/chartutil/save.go b/pkg/chartutil/save.go index 8e3753549..13277c5eb 100644 --- a/pkg/chartutil/save.go +++ b/pkg/chartutil/save.go @@ -57,6 +57,7 @@ func SaveDir(c *chart.Chart, dest string) error { for _, f := range c.Raw { if f.Name == ChartfileName { hasRawMetadata = true + break } } From 6cd5ae5318417561b1c3468b16a0cb29656f1bc9 Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 9 Sep 2022 13:04:16 +0200 Subject: [PATCH 4/7] Rename --keep-metadata flag to --no-override Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index a3f5fdba8..e8629b867 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -52,10 +52,10 @@ will be overwritten, but other files will be left alone. ` type createOptions struct { - starter string // --starter - name string - starterDir string - keepMetadata bool + starter string // --starter + name string + starterDir string + noOverride bool } func newCreateCmd(out io.Writer) *cobra.Command { @@ -76,7 +76,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { return nil, cobra.ShellCompDirectiveNoFileComp }, PreRunE: func(cmd *cobra.Command, args []string) error { - if len(o.starter) == 0 && o.keepMetadata { + if len(o.starter) == 0 && o.noOverride { return errors.New("the -k/--keep-metadata flag can only be specified when using a starter") } @@ -90,7 +90,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { } cmd.Flags().StringVarP(&o.starter, "starter", "p", "", "the name or absolute path to Helm starter scaffold") - cmd.Flags().BoolVarP(&o.keepMetadata, "keep-metadata", "k", false, "if specified, does not override the starter's Chart.yaml") + cmd.Flags().BoolVarP(&o.noOverride, "no-override", "n", false, "if specified, does not override the starter's Chart.yaml") return cmd } @@ -107,7 +107,7 @@ func (o *createOptions) run(out io.Writer) error { APIVersion: chart.APIVersionV2, } - if o.keepMetadata { + if o.noOverride { cfile = nil } From be8c2035971abcca5ae500d3680dfced919f1a95 Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 9 Sep 2022 13:40:14 +0200 Subject: [PATCH 5/7] Fix go linting errors Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index e8629b867..2b5a2ce9f 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -23,9 +23,9 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "helm.sh/helm/v3/pkg/chart" "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" ) From f72550ee46406d729251ef7dcf492d467dc52784 Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 9 Sep 2022 13:49:58 +0200 Subject: [PATCH 6/7] Fix --no-override's shorthand clash with global --namespace flag Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index 2b5a2ce9f..683262153 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -90,7 +90,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { } cmd.Flags().StringVarP(&o.starter, "starter", "p", "", "the name or absolute path to Helm starter scaffold") - cmd.Flags().BoolVarP(&o.noOverride, "no-override", "n", false, "if specified, does not override the starter's Chart.yaml") + cmd.Flags().BoolVarP(&o.noOverride, "no-override", "o", false, "if specified, does not override the starter's Chart.yaml") return cmd } From 207b5294dbf4f6ff708dab13038a3b84ab48e9eb Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Thu, 10 Aug 2023 12:40:58 +0200 Subject: [PATCH 7/7] Fix inconsistent flag name in error Signed-off-by: Filip Krakowski --- cmd/helm/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index 683262153..3cdd92222 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -77,7 +77,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { }, PreRunE: func(cmd *cobra.Command, args []string) error { if len(o.starter) == 0 && o.noOverride { - return errors.New("the -k/--keep-metadata flag can only be specified when using a starter") + return errors.New("the -o/--no-override flag can only be specified when using a starter") } return nil