From 7bceab3fc764548e5292157d3c0c879463052f90 Mon Sep 17 00:00:00 2001 From: itaispiegel Date: Mon, 23 Aug 2021 14:27:54 +0300 Subject: [PATCH] Merge --include-file and --include-dir flags to --include-path Signed-off-by: itaispiegel --- cmd/helm/flags.go | 6 ++---- cmd/helm/install.go | 15 +++++---------- cmd/helm/install_test.go | 8 ++++---- cmd/helm/template_test.go | 6 +++--- cmd/helm/upgrade.go | 6 +++--- pkg/action/install.go | 3 +-- pkg/action/upgrade.go | 3 +-- pkg/cli/files/files.go | 20 -------------------- 8 files changed, 19 insertions(+), 48 deletions(-) delete mode 100644 pkg/cli/files/files.go diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go index 6453e523d..378730f32 100644 --- a/cmd/helm/flags.go +++ b/cmd/helm/flags.go @@ -29,7 +29,6 @@ import ( "k8s.io/klog/v2" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/cli/files" "helm.sh/helm/v3/pkg/cli/output" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/helmpath" @@ -65,9 +64,8 @@ func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) { f.BoolVar(&c.PassCredentialsAll, "pass-credentials", false, "pass credentials to all domains") } -func addExternalFilesFlags(f *pflag.FlagSet, v *files.ExternalFiles) { - f.StringArrayVar(&v.Files, "include-file", []string{}, "paths to local files to add during chart installation") - f.StringArrayVar(&v.Globs, "include-dir", []string{}, "paths or globs to local dirs to add during chart installation") +func addExternalPathsFlags(f *pflag.FlagSet, v *[]string) { + f.StringArrayVar(v, "include-path", []string{}, "paths or globs to local files and directories to add during chart installation") } // bindOutputFlag will add the output flag to the given command and bind the diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 17d11c099..b287b1f72 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -36,7 +36,6 @@ import ( "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" - "helm.sh/helm/v3/pkg/cli/files" "helm.sh/helm/v3/pkg/cli/output" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/downloader" @@ -174,7 +173,7 @@ func addInstallFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Instal f.BoolVar(&client.SubNotes, "render-subchart-notes", false, "if set, render subchart notes along with the parent") addValueOptionsFlags(f, valueOpts) addChartPathOptionsFlags(f, &client.ChartPathOptions) - addExternalFilesFlags(f, &client.ExternalFiles) + addExternalPathsFlags(f, &client.ExternalPaths) err := cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { requiredArgs := 2 @@ -262,7 +261,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options } } - err = loadExternalFiles(chartRequested, client.ExternalFiles) + err = loadExternalPaths(chartRequested, client.ExternalPaths) if err != nil { return nil, err } @@ -298,14 +297,10 @@ func checkIfInstallable(ch *chart.Chart) error { return errors.Errorf("%s charts are not installable", ch.Metadata.Type) } -func loadExternalFiles(ch *chart.Chart, exFiles files.ExternalFiles) error { +func loadExternalPaths(ch *chart.Chart, externalPaths []string) error { var errs []string - var fs []string - fs = append(fs, exFiles.Files...) - fs = append(fs, exFiles.Globs...) - - for _, path := range fs { + for _, path := range externalPaths { allPaths, err := loader.ExpandFilePath(path) debug(fmt.Sprintf("%s expanded to: %v", path, allPaths)) if err != nil { @@ -324,7 +319,7 @@ func loadExternalFiles(ch *chart.Chart, exFiles files.ExternalFiles) error { } if len(errs) > 0 { - return errors.New(fmt.Sprint("Failed to load external files: ", strings.Join(errs, "; "))) + return errors.New(fmt.Sprint("Failed to load external paths: ", strings.Join(errs, "; "))) } return nil } diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index d7e13dfc7..54079d17d 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -77,22 +77,22 @@ func TestInstall(t *testing.T) { cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml", golden: "output/install-with-values-file.txt", }, - // Install, external file + // Install, external files { name: "install with external files", - cmd: "install virgil testdata/testcharts/external --include-file testdata/files/external.txt --set external=testdata/files/external.txt", + cmd: "install virgil testdata/testcharts/external --include-path testdata/files/external.txt --set external=testdata/files/external.txt", golden: "output/install-with-external-files.txt", }, // Install, external dir { name: "install with external dir", - cmd: "install virgil testdata/testcharts/external --set glob.enabled=true --include-dir testdata/files/", + cmd: "install virgil testdata/testcharts/external --set glob.enabled=true --include-path testdata/files/", golden: "output/install-with-external-files.txt", }, // Install, external glob files { name: "install with external globbed files", - cmd: "install virgil testdata/testcharts/external --set glob.enabled=true --include-dir testdata/files/external.*.conf", + cmd: "install virgil testdata/testcharts/external --set glob.enabled=true --include-path testdata/files/external.*.conf", golden: "output/install-with-external-files.txt", }, // Install, no hooks diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 5ffdd8bc8..25bf05c4c 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -133,17 +133,17 @@ func TestTemplateCmd(t *testing.T) { }, { name: "chart with template with external file", - cmd: fmt.Sprintf("template '%s' --set external=testdata/files/external.txt --include-file testdata/files/external.txt", "testdata/testcharts/external"), + cmd: fmt.Sprintf("template '%s' --set external=testdata/files/external.txt --include-path testdata/files/external.txt", "testdata/testcharts/external"), golden: "output/template-with-external-file.txt", }, { name: "chart with template with external dir", - cmd: fmt.Sprintf("template '%s' --set glob.enabled=true --include-dir testdata/files/", "testdata/testcharts/external"), + cmd: fmt.Sprintf("template '%s' --set glob.enabled=true --include-path testdata/files/", "testdata/testcharts/external"), golden: "output/template-with-external-dir.txt", }, { name: "chart with template with external globbed files", - cmd: fmt.Sprintf("template '%s' --set glob.enabled=true --include-dir testdata/files/external.*.conf", "testdata/testcharts/external"), + cmd: fmt.Sprintf("template '%s' --set glob.enabled=true --include-path testdata/files/external.*.conf", "testdata/testcharts/external"), golden: "output/template-with-external-glob.txt", }, } diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 45a35c679..d1ce7624e 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -116,7 +116,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { instClient.PostRenderer = client.PostRenderer instClient.DisableOpenAPIValidation = client.DisableOpenAPIValidation instClient.SubNotes = client.SubNotes - instClient.ExternalFiles = client.ExternalFiles + instClient.ExternalPaths = client.ExternalPaths instClient.Description = client.Description instClient.DependencyUpdate = client.DependencyUpdate @@ -182,7 +182,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { warning("This chart is deprecated") } - err = loadExternalFiles(ch, client.ExternalFiles) + err = loadExternalPaths(ch, client.ExternalPaths) if err != nil { return err } @@ -241,7 +241,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { addValueOptionsFlags(f, valueOpts) bindOutputFlag(cmd, &outfmt) bindPostRenderFlag(cmd, &client.PostRenderer) - addExternalFilesFlags(f, &client.ExternalFiles) + addExternalPathsFlags(f, &client.ExternalPaths) err := cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 2 { diff --git a/pkg/action/install.go b/pkg/action/install.go index 92e14ce9e..e16e69aeb 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -41,7 +41,6 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/cli" - "helm.sh/helm/v3/pkg/cli/files" "helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/kube" @@ -101,7 +100,7 @@ type Install struct { // OutputDir/ UseReleaseName bool PostRenderer postrender.PostRenderer - ExternalFiles files.ExternalFiles + ExternalPaths []string // Lock to control raceconditions when the process receives a SIGTERM Lock sync.Mutex } diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index e2befe2a1..2826076d2 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -30,7 +30,6 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" - "helm.sh/helm/v3/pkg/cli/files" "helm.sh/helm/v3/pkg/kube" "helm.sh/helm/v3/pkg/postrender" "helm.sh/helm/v3/pkg/release" @@ -102,7 +101,7 @@ type Upgrade struct { DisableOpenAPIValidation bool // Get missing dependencies DependencyUpdate bool - ExternalFiles files.ExternalFiles + ExternalPaths []string // Lock to control raceconditions when the process receives a SIGTERM Lock sync.Mutex } diff --git a/pkg/cli/files/files.go b/pkg/cli/files/files.go deleted file mode 100644 index f8f781742..000000000 --- a/pkg/cli/files/files.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright The Helm Authors. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package files - -// ExternalFiles holds the list of external files or globs -type ExternalFiles struct { - Files []string - Globs []string -}