From da6f164dbb28f4ae875c52fc4ec77a4b6b37e456 Mon Sep 17 00:00:00 2001 From: Gunjan Vyas Date: Tue, 2 Nov 2021 22:56:41 +0530 Subject: [PATCH] Remove lookup-plugins flag (#1506) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roland Huß --- cmd/kn/main_test.go | 5 ----- pkg/kn/config/config.go | 15 +-------------- pkg/kn/config/types.go | 10 ++++------ test/e2e/plugins_test.go | 16 ++++------------ 4 files changed, 9 insertions(+), 37 deletions(-) diff --git a/cmd/kn/main_test.go b/cmd/kn/main_test.go index 57729f01c..2395bd7db 100644 --- a/cmd/kn/main_test.go +++ b/cmd/kn/main_test.go @@ -203,11 +203,6 @@ func TestStripFlags(t *testing.T) { []string{"test", "second"}, "", }, - { - []string{"--lookup-plugins", "bla", "test", "second"}, - []string{"bla", "test", "second"}, - "", - }, { []string{"--config-file", "bla", "test", "second"}, []string{"test", "second"}, diff --git a/pkg/kn/config/config.go b/pkg/kn/config/config.go index 68aaee33a..e1b6340ce 100644 --- a/pkg/kn/config/config.go +++ b/pkg/kn/config/config.go @@ -88,13 +88,7 @@ func (c *config) PluginsDir() string { // LookupPluginsInPath returns true if plugins should be also checked in the pat func (c *config) LookupPluginsInPath() bool { - if viper.IsSet(deprecatedKeyPluginsLookupInPath) { - return viper.GetBool(deprecatedKeyPluginsLookupInPath) - } else { - // If legacy branch is removed, switch to setting the default to viper - // See TODO comment below. - return bootstrapDefaults.lookupPluginsInPath - } + return bootstrapDefaults.lookupPluginsInPath } func (c *config) SinkMappings() []SinkMapping { @@ -131,10 +125,6 @@ func BootstrapConfig() error { if err != nil { return err } - err = viper.BindPFlag(deprecatedKeyPluginsLookupInPath, bootstrapFlagSet.Lookup(flagPluginsLookupInPath)) - if err != nil { - return err - } viper.SetConfigFile(GlobalConfig.ConfigFile()) configFile := GlobalConfig.ConfigFile() @@ -159,7 +149,6 @@ func BootstrapConfig() error { // TODO: Re-enable when legacy handling for plugin config has been removed // For now default handling is happening directly in the getter of GlobalConfig // viper.SetDefault(keyPluginsDirectory, bootstrapDefaults.pluginsDir) - // viper.SetDefault(deprecatedKeyPluginsLookupInPath, bootstrapDefaults.lookupPluginsInPath) // If a config file is found, read it in. err = viper.ReadInConfig() @@ -182,10 +171,8 @@ func BootstrapConfig() error { func AddBootstrapFlags(flags *flag.FlagSet) { flags.StringVar(&globalConfig.configFile, "config", "", fmt.Sprintf("kn configuration file (default: %s)", defaultConfigFileForUsageMessage())) flags.String(flagPluginsDir, "", "Directory holding kn plugins") - flags.Bool(flagPluginsLookupInPath, false, "Search kn plugins also in $PATH") // Let's try that and mark the flags as hidden: (as those configuration is a permanent choice of operation) - flags.MarkHidden(flagPluginsLookupInPath) flags.MarkHidden(flagPluginsDir) } diff --git a/pkg/kn/config/types.go b/pkg/kn/config/types.go index b801c58dd..2ef7dc8de 100644 --- a/pkg/kn/config/types.go +++ b/pkg/kn/config/types.go @@ -70,10 +70,9 @@ type ChannelTypeMapping struct { // config Keys for looking up in viper const ( - keyPluginsDirectory = "plugins.directory" - deprecatedKeyPluginsLookupInPath = "plugins.path-lookup" - keySinkMappings = "eventing.sink-mappings" - keyChannelTypeMappings = "eventing.channel-type-mappings" + keyPluginsDirectory = "plugins.directory" + keySinkMappings = "eventing.sink-mappings" + keyChannelTypeMappings = "eventing.channel-type-mappings" ) // legacy config keys, deprecated @@ -85,6 +84,5 @@ const ( // Global (hidden) flags // TODO: Remove me if decided that they are not needed const ( - flagPluginsDir = "plugins-dir" - flagPluginsLookupInPath = "lookup-plugins" + flagPluginsDir = "plugins-dir" ) diff --git a/test/e2e/plugins_test.go b/test/e2e/plugins_test.go index 969201f12..1b5f791d9 100644 --- a/test/e2e/plugins_test.go +++ b/test/e2e/plugins_test.go @@ -122,16 +122,13 @@ func TestPluginWithoutLookup(t *testing.T) { r := test.NewKnRunResultCollector(t, it) defer r.DumpIfFailed() - knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=false"} + knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)} t.Log("list plugin in --plugins-dir") listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{}) t.Log("execute plugin in --plugins-dir") runPlugin(r, knFlags, "helloe2e", []string{"e2e", "test"}, []string{"Hello Knative, I'm a Kn plugin", "I received arguments", "e2e"}) - - t.Log("does not list any other plugin in $PATH") - listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2}) } func TestPluginInHelpMessage(t *testing.T) { @@ -159,7 +156,7 @@ func TestPluginWithLookup(t *testing.T) { assert.NilError(t, pc.setup()) defer pc.teardown() - knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} + knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)} t.Log("list plugin in --plugins-dir") listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2}) @@ -178,7 +175,7 @@ func TestListPluginInPath(t *testing.T) { defer tearDownWithPath(pc, oldPath) t.Log("list plugin in $PATH") - knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} + knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)} listPlugin(r, knFlags, []string{pc.knPluginPath, pc.knPluginPath2}, []string{}) r.DumpIfFailed() @@ -195,7 +192,7 @@ func TestExecutePluginInPath(t *testing.T) { defer tearDownWithPath(pc, oldPath) t.Log("execute plugin in $PATH") - knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"} + knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir)} runPlugin(r, knFlags, "hello2e2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"}) } @@ -218,11 +215,6 @@ func TestExecutePluginInPathWithError(t *testing.T) { assert.NilError(t, err) assert.NilError(t, os.Setenv("PATH", fmt.Sprintf("%s%s%s", oldPath, delim, pluginsDir))) defer tearDownWithPath(pc, oldPath) - - out := test.Kn{}.Run("--lookup-plugins=true", "hello3e2e") - r.AssertError(out) - assert.Check(r.T(), util.ContainsAll(out.Stderr, "Error: exit status 1")) - assert.Check(r.T(), util.ContainsNone(out.Stderr, "Run", "kn --help", "usage")) } // Private