Merge --include-file and --include-dir flags to --include-path

Signed-off-by: itaispiegel <itai.spiegel@gmail.com>
pull/10077/head
itaispiegel 4 years ago
parent 5c6c660ac5
commit 7bceab3fc7

@ -29,7 +29,6 @@ import (
"k8s.io/klog/v2" "k8s.io/klog/v2"
"helm.sh/helm/v3/pkg/action" "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/output"
"helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/helmpath" "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") f.BoolVar(&c.PassCredentialsAll, "pass-credentials", false, "pass credentials to all domains")
} }
func addExternalFilesFlags(f *pflag.FlagSet, v *files.ExternalFiles) { func addExternalPathsFlags(f *pflag.FlagSet, v *[]string) {
f.StringArrayVar(&v.Files, "include-file", []string{}, "paths to local files to add during chart installation") f.StringArrayVar(v, "include-path", []string{}, "paths or globs to local files and directories to add during chart installation")
f.StringArrayVar(&v.Globs, "include-dir", []string{}, "paths or globs to local dirs to add during chart installation")
} }
// bindOutputFlag will add the output flag to the given command and bind the // bindOutputFlag will add the output flag to the given command and bind the

@ -36,7 +36,6 @@ import (
"helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader" "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/output"
"helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/downloader" "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") f.BoolVar(&client.SubNotes, "render-subchart-notes", false, "if set, render subchart notes along with the parent")
addValueOptionsFlags(f, valueOpts) addValueOptionsFlags(f, valueOpts)
addChartPathOptionsFlags(f, &client.ChartPathOptions) 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) { err := cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
requiredArgs := 2 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 { if err != nil {
return nil, err return nil, err
} }
@ -298,14 +297,10 @@ func checkIfInstallable(ch *chart.Chart) error {
return errors.Errorf("%s charts are not installable", ch.Metadata.Type) 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 errs []string
var fs []string
fs = append(fs, exFiles.Files...) for _, path := range externalPaths {
fs = append(fs, exFiles.Globs...)
for _, path := range fs {
allPaths, err := loader.ExpandFilePath(path) allPaths, err := loader.ExpandFilePath(path)
debug(fmt.Sprintf("%s expanded to: %v", path, allPaths)) debug(fmt.Sprintf("%s expanded to: %v", path, allPaths))
if err != nil { if err != nil {
@ -324,7 +319,7 @@ func loadExternalFiles(ch *chart.Chart, exFiles files.ExternalFiles) error {
} }
if len(errs) > 0 { 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 return nil
} }

@ -77,22 +77,22 @@ func TestInstall(t *testing.T) {
cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml", cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml",
golden: "output/install-with-values-file.txt", golden: "output/install-with-values-file.txt",
}, },
// Install, external file // Install, external files
{ {
name: "install with 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", golden: "output/install-with-external-files.txt",
}, },
// Install, external dir // Install, external dir
{ {
name: "install with 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", golden: "output/install-with-external-files.txt",
}, },
// Install, external glob files // Install, external glob files
{ {
name: "install with external globbed 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", golden: "output/install-with-external-files.txt",
}, },
// Install, no hooks // Install, no hooks

@ -133,17 +133,17 @@ func TestTemplateCmd(t *testing.T) {
}, },
{ {
name: "chart with template with external file", 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", golden: "output/template-with-external-file.txt",
}, },
{ {
name: "chart with template with external dir", 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", golden: "output/template-with-external-dir.txt",
}, },
{ {
name: "chart with template with external globbed files", 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", golden: "output/template-with-external-glob.txt",
}, },
} }

@ -116,7 +116,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.PostRenderer = client.PostRenderer instClient.PostRenderer = client.PostRenderer
instClient.DisableOpenAPIValidation = client.DisableOpenAPIValidation instClient.DisableOpenAPIValidation = client.DisableOpenAPIValidation
instClient.SubNotes = client.SubNotes instClient.SubNotes = client.SubNotes
instClient.ExternalFiles = client.ExternalFiles instClient.ExternalPaths = client.ExternalPaths
instClient.Description = client.Description instClient.Description = client.Description
instClient.DependencyUpdate = client.DependencyUpdate instClient.DependencyUpdate = client.DependencyUpdate
@ -182,7 +182,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
warning("This chart is deprecated") warning("This chart is deprecated")
} }
err = loadExternalFiles(ch, client.ExternalFiles) err = loadExternalPaths(ch, client.ExternalPaths)
if err != nil { if err != nil {
return err return err
} }
@ -241,7 +241,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
addValueOptionsFlags(f, valueOpts) addValueOptionsFlags(f, valueOpts)
bindOutputFlag(cmd, &outfmt) bindOutputFlag(cmd, &outfmt)
bindPostRenderFlag(cmd, &client.PostRenderer) 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) { err := cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 2 { if len(args) != 2 {

@ -41,7 +41,6 @@ import (
"helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/cli/files"
"helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/kube" "helm.sh/helm/v3/pkg/kube"
@ -101,7 +100,7 @@ type Install struct {
// OutputDir/<ReleaseName> // OutputDir/<ReleaseName>
UseReleaseName bool UseReleaseName bool
PostRenderer postrender.PostRenderer PostRenderer postrender.PostRenderer
ExternalFiles files.ExternalFiles ExternalPaths []string
// Lock to control raceconditions when the process receives a SIGTERM // Lock to control raceconditions when the process receives a SIGTERM
Lock sync.Mutex Lock sync.Mutex
} }

@ -30,7 +30,6 @@ import (
"helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli/files"
"helm.sh/helm/v3/pkg/kube" "helm.sh/helm/v3/pkg/kube"
"helm.sh/helm/v3/pkg/postrender" "helm.sh/helm/v3/pkg/postrender"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
@ -102,7 +101,7 @@ type Upgrade struct {
DisableOpenAPIValidation bool DisableOpenAPIValidation bool
// Get missing dependencies // Get missing dependencies
DependencyUpdate bool DependencyUpdate bool
ExternalFiles files.ExternalFiles ExternalPaths []string
// Lock to control raceconditions when the process receives a SIGTERM // Lock to control raceconditions when the process receives a SIGTERM
Lock sync.Mutex Lock sync.Mutex
} }

@ -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
}
Loading…
Cancel
Save