diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index e1ce1ad28..bd8e2e5b4 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -22,11 +22,10 @@ import ( "log" "os" "strings" - "sync" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/klog" // Import to initialize client auth plugins. @@ -43,11 +42,7 @@ import ( // FeatureGateOCI is the feature gate for checking if `helm chart` and `helm registry` commands should work const FeatureGateOCI = gates.Gate("HELM_EXPERIMENTAL_OCI") -var ( - settings = cli.New() - config genericclioptions.RESTClientGetter - configOnce sync.Once -) +var settings = cli.New() func init() { log.SetFlags(log.Lshortfile) @@ -74,9 +69,6 @@ func main() { actionConfig := new(action.Configuration) cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) - // Initialize the rest of the actionConfig - initActionConfig(actionConfig, false) - if err := cmd.Execute(); err != nil { debug("%+v", err) switch e := err.(type) { @@ -88,60 +80,52 @@ func main() { } } -func initActionConfig(actionConfig *action.Configuration, allNamespaces bool) { - kc := kube.New(kubeConfig()) - kc.Log = debug - - clientset, err := kc.Factory.KubernetesClientSet() - if err != nil { - // TODO return error - log.Fatal(err) +func initActionConfig(ac *action.Configuration, allNamespaces bool) error { + if ac.Log == nil { + ac.Log = debug } - var namespace string - if !allNamespaces { - namespace = getNamespace() + if ac.RESTClientGetter == nil { + ac.RESTClientGetter = settings.KubeConfig } - var store *storage.Storage - switch os.Getenv("HELM_DRIVER") { - case "secret", "secrets", "": - d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace)) - d.Log = debug - store = storage.Init(d) - case "configmap", "configmaps": - d := driver.NewConfigMaps(clientset.CoreV1().ConfigMaps(namespace)) - d.Log = debug - store = storage.Init(d) - case "memory": - d := driver.NewMemory() - store = storage.Init(d) - default: - // Not sure what to do here. - panic("Unknown driver in HELM_DRIVER: " + os.Getenv("HELM_DRIVER")) + if ac.KubeClient == nil { + kc := kube.New(ac.RESTClientGetter) + kc.Log = debug + ac.KubeClient = kc } - actionConfig.RESTClientGetter = kubeConfig() - actionConfig.KubeClient = kc - actionConfig.Releases = store - actionConfig.Log = debug -} - -func kubeConfig() genericclioptions.RESTClientGetter { - configOnce.Do(func() { - config = kube.GetConfig(settings.KubeConfig, settings.KubeContext, settings.Namespace) - }) - return config -} - -func getNamespace() string { - if settings.Namespace != "" { - return settings.Namespace - } + if ac.Releases == nil { + kc := kube.New(ac.RESTClientGetter) + kc.Log = debug + ac.KubeClient = kc + clientset, err := kc.Factory.KubernetesClientSet() + if err != nil { + return err + } + var namespace string + if !allNamespaces { + namespace = settings.Namespace() + } - if ns, _, err := kubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil { - return ns + var store *storage.Storage + switch os.Getenv("HELM_DRIVER") { + case "secret", "secrets", "": + d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace)) + d.Log = debug + store = storage.Init(d) + case "configmap", "configmaps": + d := driver.NewConfigMaps(clientset.CoreV1().ConfigMaps(namespace)) + d.Log = debug + store = storage.Init(d) + case "memory": + d := driver.NewMemory() + store = storage.Init(d) + default: + return errors.New("Unknown driver in HELM_DRIVER: " + os.Getenv("HELM_DRIVER")) + } + ac.Releases = store } - return "default" + return nil } // wordSepNormalizeFunc changes all flags that contain "_" separators diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 4c36766ea..83371abba 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -210,7 +210,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options } } - client.Namespace = getNamespace() + client.Namespace = settings.Namespace() return client.Run(chartRequested, vals) } diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 8b18d3261..85d9d3bdc 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -51,7 +51,7 @@ func newLintCmd(out io.Writer) *cobra.Command { if len(args) > 0 { paths = args } - client.Namespace = getNamespace() + client.Namespace = settings.Namespace() vals, err := valueOpts.MergeValues(getter.All(settings)) if err != nil { return err diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 7ee7565f2..20d4d78a7 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -65,6 +65,13 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { Long: listHelp, Aliases: []string{"ls"}, Args: require.NoArgs, + PreRunE: func(cmd *cobra.Command, args []string) error { + if err := initActionConfig(cfg, client.AllNamespaces); err != nil { + return err + } + client.SetStateMask() + return nil + }, RunE: func(cmd *cobra.Command, args []string) error { // validate the output format first so we don't waste time running a // request that we'll throw away @@ -72,12 +79,6 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - - if client.AllNamespaces { - initActionConfig(cfg, true) - } - client.SetStateMask() - results, err := client.Run() if client.Short { diff --git a/cmd/helm/load_plugins.go b/cmd/helm/load_plugins.go index b74bc22ea..c5631a3d7 100644 --- a/cmd/helm/load_plugins.go +++ b/cmd/helm/load_plugins.go @@ -82,8 +82,8 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) { // Call setupEnv before PrepareCommand because // PrepareCommand uses os.ExpandEnv and expects the // setupEnv vars. - plugin.SetupPluginEnv(settings, md.Name, plug.Dir) - main, argv, prepCmdErr := plug.PrepareCommand(u) + penv := plugin.SetupPluginEnv(settings, md.Name, plug.Dir) + main, argv, prepCmdErr := plug.PrepareCommand(u, penv) if prepCmdErr != nil { os.Stderr.WriteString(prepCmdErr.Error()) return errors.Errorf("plugin %q exited with error", md.Name) @@ -96,9 +96,7 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) { prog := exec.Command(main, argv...) prog.Env = env - prog.Stdin = os.Stdin - prog.Stdout = out - prog.Stderr = os.Stderr + prog.Stdin, prog.Stdout, prog.Stderr = os.Stdin, out, os.Stderr if err := prog.Run(); err != nil { if eerr, ok := err.(*exec.ExitError); ok { os.Stderr.Write(eerr.Stderr) diff --git a/cmd/helm/root.go b/cmd/helm/root.go index b7b9cbe3b..c4ffc24b6 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -204,6 +204,10 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string SilenceUsage: true, Args: require.NoArgs, BashCompletionFunction: bashCompletionFunc, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + // Initialize the rest of the actionConfig + return initActionConfig(actionConfig, false) + }, } flags := cmd.PersistentFlags() diff --git a/cmd/helm/testdata/output/args.txt b/cmd/helm/testdata/output/args.txt new file mode 100644 index 000000000..d1a62aa08 --- /dev/null +++ b/cmd/helm/testdata/output/args.txt @@ -0,0 +1 @@ +-a -b -c diff --git a/cmd/helm/testdata/output/echo.txt b/cmd/helm/testdata/output/echo.txt new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cmd/helm/testdata/output/echo.txt @@ -0,0 +1 @@ +hello diff --git a/cmd/helm/testdata/output/env.txt b/cmd/helm/testdata/output/env.txt new file mode 100644 index 000000000..0a764a4de --- /dev/null +++ b/cmd/helm/testdata/output/env.txt @@ -0,0 +1 @@ +env diff --git a/cmd/helm/testdata/output/fullenv.txt b/cmd/helm/testdata/output/fullenv.txt new file mode 100644 index 000000000..4b613af55 --- /dev/null +++ b/cmd/helm/testdata/output/fullenv.txt @@ -0,0 +1,6 @@ +fullenv +testdata/helmhome/helm/plugins/fullenv +testdata/helmhome/helm/plugins +testdata/helmhome/helm/repositories.yaml +testdata/helmhome/helm/repository +/var/folders/sr/3jkq42_d5fgbvdfwh05rrnlw0000gp/T/go-build387531407/b001/helm.test diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index d9cd997de..24af6b0ae 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -75,8 +75,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - - client.Namespace = getNamespace() + client.Namespace = settings.Namespace() if client.Version == "" && client.Devel { debug("setting version to >0.0.0-0") diff --git a/pkg/action/action.go b/pkg/action/action.go index f5ba24ba7..de0a01698 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -22,10 +22,9 @@ import ( "time" "github.com/pkg/errors" - "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/discovery" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" "helm.sh/helm/internal/experimental/registry" "helm.sh/helm/pkg/chartutil" @@ -65,7 +64,7 @@ var ValidName = regexp.MustCompile("^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])+ // Configuration injects the dependencies that all actions share. type Configuration struct { // RESTClientGetter is an interface that loads Kuberbetes clients. - RESTClientGetter RESTClientGetter + RESTClientGetter genericclioptions.RESTClientGetter // Releases stores records of releases. Releases *storage.Storage @@ -196,9 +195,3 @@ func (c *Configuration) recordRelease(r *release.Release) { c.Log("warning: Failed to update release %s: %s", r.Name, err) } } - -type RESTClientGetter interface { - ToRESTConfig() (*rest.Config, error) - ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) - ToRESTMapper() (meta.RESTMapper, error) -} diff --git a/pkg/action/pull.go b/pkg/action/pull.go index 8a1dc535e..5382e3224 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -56,11 +56,12 @@ func NewPull() *Pull { func (p *Pull) Run(chartRef string) (string, error) { var out strings.Builder + getters := getter.All(p.Settings) c := downloader.ChartDownloader{ Out: &out, Keyring: p.Keyring, Verify: downloader.VerifyNever, - Getters: getter.All(p.Settings), + Getters: getters, Options: []getter.Option{ getter.WithBasicAuth(p.Username, p.Password), }, @@ -87,7 +88,7 @@ func (p *Pull) Run(chartRef string) (string, error) { } if p.RepoURL != "" { - chartURL, err := repo.FindChartInAuthRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, getter.All(p.Settings)) + chartURL, err := repo.FindChartInAuthRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, getters) if err != nil { return out.String(), err } diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index f2483dd19..6d60ef6be 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -28,21 +28,15 @@ import ( "strconv" "github.com/spf13/pflag" + "k8s.io/cli-runtime/pkg/genericclioptions" "helm.sh/helm/pkg/helmpath" ) // EnvSettings describes all of the environment settings. type EnvSettings struct { - // Namespace is the namespace scope. - Namespace string - // KubeConfig is the path to the kubeconfig file. - KubeConfig string - // KubeContext is the name of the kubeconfig context. - KubeContext string // Debug indicates whether or not Helm is running in Debug mode. Debug bool - // RegistryConfig is the path to the registry config file. RegistryConfig string // RepositoryConfig is the path to the repositories file. @@ -51,29 +45,29 @@ type EnvSettings struct { RepositoryCache string // PluginsDirectory is the path to the plugins directory. PluginsDirectory string + + KubeConfig *genericclioptions.ConfigFlags } func New() *EnvSettings { - env := EnvSettings{ - Namespace: os.Getenv("HELM_NAMESPACE"), + return &EnvSettings{ + // Namespace: os.Getenv("HELM_NAMESPACE"), + Debug: envBool("HELM_DEBUG"), PluginsDirectory: envOr("HELM_PLUGINS", helmpath.DataPath("plugins")), RegistryConfig: envOr("HELM_REGISTRY_CONFIG", helmpath.ConfigPath("registry.json")), RepositoryConfig: envOr("HELM_REPOSITORY_CONFIG", helmpath.ConfigPath("repositories.yaml")), RepositoryCache: envOr("HELM_REPOSITORY_CACHE", helmpath.CachePath("repository")), + KubeConfig: genericclioptions.NewConfigFlags(true), } - env.Debug, _ = strconv.ParseBool(os.Getenv("HELM_DEBUG")) - return &env } // AddFlags binds flags to the given flagset. func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) { - fs.StringVarP(&s.Namespace, "namespace", "n", s.Namespace, "namespace scope for this request") - fs.StringVar(&s.KubeConfig, "kubeconfig", "", "path to the kubeconfig file") - fs.StringVar(&s.KubeContext, "kube-context", "", "name of the kubeconfig context to use") fs.BoolVar(&s.Debug, "debug", s.Debug, "enable verbose output") fs.StringVar(&s.RegistryConfig, "registry-config", s.RegistryConfig, "path to the registry config file") fs.StringVar(&s.RepositoryConfig, "repository-config", s.RepositoryConfig, "path to the file containing repository names and URLs") fs.StringVar(&s.RepositoryCache, "repository-cache", s.RepositoryCache, "path to the file containing cached repository indexes") + s.KubeConfig.AddFlags(fs) } func envOr(name, def string) string { @@ -83,6 +77,22 @@ func envOr(name, def string) string { return def } +func envBool(name string) bool { + var v bool + v, _ = strconv.ParseBool(os.Getenv(name)) + return v +} + +func (s *EnvSettings) Namespace() string { + if ns := os.Getenv("HELM_NAMESPACE"); ns != "" { + return ns + } + if ns, _, err := s.KubeConfig.ToRawKubeConfigLoader().Namespace(); err == nil { + return ns + } + return "default" +} + func (s *EnvSettings) EnvVars() map[string]string { return map[string]string{ "HELM_BIN": os.Args[0], @@ -91,5 +101,6 @@ func (s *EnvSettings) EnvVars() map[string]string { "HELM_REGISTRY_CONFIG": s.RegistryConfig, "HELM_REPOSITORY_CACHE": s.RepositoryCache, "HELM_REPOSITORY_CONFIG": s.RepositoryConfig, + "HELM_NAMESPACE": s.Namespace(), } } diff --git a/pkg/cli/environment_test.go b/pkg/cli/environment_test.go index 58cf1c7f4..67483e8d6 100644 --- a/pkg/cli/environment_test.go +++ b/pkg/cli/environment_test.go @@ -78,12 +78,6 @@ func TestEnvSettings(t *testing.T) { if settings.Debug != tt.debug { t.Errorf("expected debug %t, got %t", tt.debug, settings.Debug) } - if settings.Namespace != tt.ns { - t.Errorf("expected namespace %q, got %q", tt.ns, settings.Namespace) - } - if settings.KubeContext != tt.kcontext { - t.Errorf("expected kube-context %q, got %q", tt.kcontext, settings.KubeContext) - } }) } } diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index 26d19343f..a8984e2a1 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -33,6 +33,13 @@ const ( repoCache = "testdata/repository" ) +func testGetters() getter.Providers { + env := cli.New() + env.RepositoryConfig = repoConfig + env.RepositoryCache = repoCache + return getter.All(env) +} + func TestResolveChartRef(t *testing.T) { tests := []struct { name, ref, expect, version string @@ -59,10 +66,7 @@ func TestResolveChartRef(t *testing.T) { Out: os.Stderr, RepositoryConfig: repoConfig, RepositoryCache: repoCache, - Getters: getter.All(&cli.EnvSettings{ - RepositoryConfig: repoConfig, - RepositoryCache: repoCache, - }), + Getters: testGetters(), } for _, tt := range tests { @@ -138,10 +142,7 @@ func TestDownloadTo(t *testing.T) { Keyring: "testdata/helm-test-key.pub", RepositoryConfig: repoConfig, RepositoryCache: repoCache, - Getters: getter.All(&cli.EnvSettings{ - RepositoryConfig: repoConfig, - RepositoryCache: repoCache, - }), + Getters: testGetters(), Options: []getter.Option{ getter.WithBasicAuth("username", "password"), }, @@ -186,10 +187,7 @@ func TestDownloadTo_VerifyLater(t *testing.T) { Verify: VerifyLater, RepositoryConfig: repoConfig, RepositoryCache: repoCache, - Getters: getter.All(&cli.EnvSettings{ - RepositoryConfig: repoConfig, - RepositoryCache: repoCache, - }), + Getters: testGetters(), } cname := "/signtest-0.1.0.tgz" where, _, err := c.DownloadTo(srv.URL()+cname, "", dest) @@ -215,10 +213,7 @@ func TestScanReposForURL(t *testing.T) { Verify: VerifyLater, RepositoryConfig: repoConfig, RepositoryCache: repoCache, - Getters: getter.All(&cli.EnvSettings{ - RepositoryConfig: repoConfig, - RepositoryCache: repoCache, - }), + Getters: testGetters(), } u := "http://example.com/alpine-0.2.0.tgz" diff --git a/pkg/getter/getter_test.go b/pkg/getter/getter_test.go index 9b55f86ce..0a8e47735 100644 --- a/pkg/getter/getter_test.go +++ b/pkg/getter/getter_test.go @@ -23,6 +23,12 @@ import ( const pluginDir = "testdata/plugins" +func testEnv() *cli.EnvSettings { + env := cli.New() + env.PluginsDirectory = pluginDir + return env +} + func TestProvider(t *testing.T) { p := Provider{ []string{"one", "three"}, @@ -53,9 +59,7 @@ func TestProviders(t *testing.T) { } func TestAll(t *testing.T) { - all := All(&cli.EnvSettings{ - PluginsDirectory: pluginDir, - }) + all := All(testEnv()) if len(all) != 3 { t.Errorf("expected 3 providers (default plus two plugins), got %d", len(all)) } @@ -66,9 +70,7 @@ func TestAll(t *testing.T) { } func TestByScheme(t *testing.T) { - g := All(&cli.EnvSettings{ - PluginsDirectory: pluginDir, - }) + g := All(testEnv()) if _, err := g.ByScheme("test"); err != nil { t.Error(err) } diff --git a/pkg/getter/httpgetter_test.go b/pkg/getter/httpgetter_test.go index 3801aa89f..213fe1dbb 100644 --- a/pkg/getter/httpgetter_test.go +++ b/pkg/getter/httpgetter_test.go @@ -104,7 +104,7 @@ func TestDownload(t *testing.T) { })) defer srv.Close() - g, err := All(new(cli.EnvSettings)).ByScheme("http") + g, err := All(cli.New()).ByScheme("http") if err != nil { t.Fatal(err) } diff --git a/pkg/getter/plugingetter_test.go b/pkg/getter/plugingetter_test.go index ed09babb0..8cba1d7aa 100644 --- a/pkg/getter/plugingetter_test.go +++ b/pkg/getter/plugingetter_test.go @@ -19,15 +19,10 @@ import ( "runtime" "strings" "testing" - - "helm.sh/helm/pkg/cli" ) func TestCollectPlugins(t *testing.T) { - env := &cli.EnvSettings{ - PluginsDirectory: pluginDir, - } - p, err := collectPlugins(env) + p, err := collectPlugins(testEnv()) if err != nil { t.Fatal(err) } @@ -54,10 +49,7 @@ func TestPluginGetter(t *testing.T) { t.Skip("TODO: refactor this test to work on windows") } - env := &cli.EnvSettings{ - PluginsDirectory: pluginDir, - } - pg := NewPluginGetter("echo", env, "test", ".") + pg := NewPluginGetter("echo", testEnv(), "test", ".") g, err := pg() if err != nil { t.Fatal(err) @@ -80,10 +72,7 @@ func TestPluginSubCommands(t *testing.T) { t.Skip("TODO: refactor this test to work on windows") } - env := &cli.EnvSettings{ - PluginsDirectory: pluginDir, - } - pg := NewPluginGetter("echo -n", env, "test", ".") + pg := NewPluginGetter("echo -n", testEnv(), "test", ".") g, err := pg() if err != nil { t.Fatal(err) diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index cfa665d21..c618911e3 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -108,15 +108,22 @@ type Plugin struct { // - If both OS and Arch match the current platform, search will stop and the command will be prepared for execution // - If OS matches and there is no more specific match, the command will be prepared for execution // - If no OS/Arch match is found, return nil -func getPlatformCommand(cmds []PlatformCommand) []string { +func getPlatformCommand(cmds []PlatformCommand, env map[string]string) []string { + getenv := func(name string) string { + if v, ok := env[name]; ok { + return v + } + return os.Getenv(name) + } + var command []string eq := strings.EqualFold for _, c := range cmds { if eq(c.OperatingSystem, runtime.GOOS) { - command = strings.Split(os.ExpandEnv(c.Command), " ") + command = strings.Split(os.Expand(c.Command, getenv), " ") } if eq(c.OperatingSystem, runtime.GOOS) && eq(c.Architecture, runtime.GOARCH) { - return strings.Split(os.ExpandEnv(c.Command), " ") + return strings.Split(os.Expand(c.Command, getenv), " ") } } return command @@ -133,11 +140,11 @@ func getPlatformCommand(cmds []PlatformCommand) []string { // returns the name of the command and an args array. // // The result is suitable to pass to exec.Command. -func (p *Plugin) PrepareCommand(extraArgs []string) (string, []string, error) { +func (p *Plugin) PrepareCommand(extraArgs []string, env map[string]string) (string, []string, error) { var parts []string platCmdLen := len(p.Metadata.PlatformCommand) if platCmdLen > 0 { - parts = getPlatformCommand(p.Metadata.PlatformCommand) + parts = getPlatformCommand(p.Metadata.PlatformCommand, env) } if platCmdLen == 0 || parts == nil { parts = strings.Split(os.ExpandEnv(p.Metadata.Command), " ") @@ -215,11 +222,12 @@ func FindPlugins(plugdirs string) ([]*Plugin, error) { // SetupPluginEnv prepares os.Env for plugins. It operates on os.Env because // the plugin subsystem itself needs access to the environment variables // created here. -func SetupPluginEnv(settings *cli.EnvSettings, name, base string) { +func SetupPluginEnv(settings *cli.EnvSettings, name, base string) map[string]string { env := settings.EnvVars() env["HELM_PLUGIN_NAME"] = name env["HELM_PLUGIN_DIR"] = base for key, val := range env { os.Setenv(key, val) } + return env } diff --git a/pkg/plugin/plugin_test.go b/pkg/plugin/plugin_test.go index dfe607cd6..acd07bfc2 100644 --- a/pkg/plugin/plugin_test.go +++ b/pkg/plugin/plugin_test.go @@ -26,7 +26,7 @@ import ( ) func checkCommand(p *Plugin, extraArgs []string, osStrCmp string, t *testing.T) { - cmd, args, err := p.PrepareCommand(extraArgs) + cmd, args, err := p.PrepareCommand(extraArgs, map[string]string{}) if err != nil { t.Errorf(err.Error()) } @@ -47,7 +47,7 @@ func checkCommand(p *Plugin, extraArgs []string, osStrCmp string, t *testing.T) // Test with IgnoreFlags. This should omit --debug, --foo, bar p.Metadata.IgnoreFlags = true - cmd, args, err = p.PrepareCommand(extraArgs) + cmd, args, err = p.PrepareCommand(extraArgs, map[string]string{}) if err != nil { t.Errorf(err.Error()) } @@ -144,7 +144,7 @@ func TestNoPrepareCommand(t *testing.T) { } argv := []string{"--debug", "--foo", "bar"} - _, _, err := p.PrepareCommand(argv) + _, _, err := p.PrepareCommand(argv, map[string]string{}) if err == nil { t.Errorf("Expected error to be returned") } @@ -162,7 +162,7 @@ func TestNoMatchPrepareCommand(t *testing.T) { } argv := []string{"--debug", "--foo", "bar"} - if _, _, err := p.PrepareCommand(argv); err == nil { + if _, _, err := p.PrepareCommand(argv, map[string]string{}); err == nil { t.Errorf("Expected error to be returned") } } @@ -259,11 +259,10 @@ func TestSetupEnv(t *testing.T) { name := "pequod" base := filepath.Join("testdata/helmhome/helm/plugins", name) - s := &cli.EnvSettings{ - PluginsDirectory: "testdata/helmhome/helm/plugins", - } + env := cli.New() + env.PluginsDirectory = "testdata/helmhome/helm/plugins" - SetupPluginEnv(s, name, base) + SetupPluginEnv(env, name, base) for _, tt := range []struct { name, expect string }{ diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index d840f963f..68ffa8efd 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -45,7 +45,7 @@ func TestLoadChartRepository(t *testing.T) { r, err := NewChartRepository(&Entry{ Name: testRepository, URL: testURL, - }, getter.All(&cli.EnvSettings{})) + }, getter.All(cli.New())) if err != nil { t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) } @@ -78,7 +78,7 @@ func TestIndex(t *testing.T) { r, err := NewChartRepository(&Entry{ Name: testRepository, URL: testURL, - }, getter.All(&cli.EnvSettings{})) + }, getter.All(cli.New())) if err != nil { t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) } @@ -283,7 +283,7 @@ func TestFindChartInRepoURL(t *testing.T) { } defer srv.Close() - chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})) + chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(cli.New())) if err != nil { t.Fatalf("%v", err) } @@ -291,7 +291,7 @@ func TestFindChartInRepoURL(t *testing.T) { t.Errorf("%s is not the valid URL", chartURL) } - chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})) + chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(cli.New())) if err != nil { t.Errorf("%s", err) } @@ -302,9 +302,9 @@ func TestFindChartInRepoURL(t *testing.T) { func TestErrorFindChartInRepoURL(t *testing.T) { - g := getter.All(&cli.EnvSettings{ - RepositoryCache: ensure.TempDir(t), - }) + env := cli.New() + env.RepositoryCache = ensure.TempDir(t) + g := getter.All(env) if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", g); err == nil { t.Errorf("Expected error for bad chart URL, but did not get any errors") diff --git a/pkg/repo/index_test.go b/pkg/repo/index_test.go index c33f257ea..9d22ca387 100644 --- a/pkg/repo/index_test.go +++ b/pkg/repo/index_test.go @@ -137,7 +137,7 @@ func TestDownloadIndexFile(t *testing.T) { r, err := NewChartRepository(&Entry{ Name: testRepo, URL: srv.URL, - }, getter.All(&cli.EnvSettings{})) + }, getter.All(cli.New())) if err != nil { t.Errorf("Problem creating chart repository from %s: %v", testRepo, err) }