diff --git a/go.mod b/go.mod index 5bea55445..73801aa87 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/lithammer/dedent v1.1.0 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/onsi/ginkgo/v2 v2.9.2 - github.com/onsi/gomega v1.27.4 + github.com/onsi/gomega v1.27.6 github.com/otiai10/copy v1.4.2 github.com/pkg/errors v0.9.1 github.com/sigstore/cosign v1.13.1 @@ -32,7 +32,7 @@ require ( github.com/vmware-tanzu/carvel-imgpkg v0.36.1 github.com/vmware-tanzu/carvel-ytt v0.40.0 github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230415084831-9331f55d2999 - github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0 + github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0.0.20230425191535-014e58e69078 go.pinniped.dev v0.20.0 go.uber.org/multierr v1.8.0 golang.org/x/mod v0.9.0 diff --git a/go.sum b/go.sum index bcf1a91bb..00c4a9634 100644 --- a/go.sum +++ b/go.sum @@ -1004,8 +1004,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= -github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= +github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= +github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -1287,8 +1287,8 @@ github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20221207131309-7323ca04b github.com/vmware-tanzu/tanzu-framework/apis/run v0.0.0-20221207131309-7323ca04b86c/go.mod h1:ukZpKQ0hf5bjWdJLjn2M6qXP+9giZWQPxt8nOfrCR+o= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230415084831-9331f55d2999 h1:WITDH+wpdl/clw1hwy+2jtq4Pt//i/Mq9lQXGwg3q4c= github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230415084831-9331f55d2999/go.mod h1:umFZBUfJ8VI3p0VO/xocuE+4fO9s9QbytEiOqFcH/Tw= -github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0 h1:7HOxIB70moCj8b39/kezbJbzF2XqoCihGS7bIPhqTAA= -github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0/go.mod h1:y70TLdev7MX8K6CkAA7h92qVUDyjbX8y9/J5q4UmhRs= +github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0.0.20230425191535-014e58e69078 h1:FnqG7kCmltbUgnGJiDcokvQT1Bbvs38IrmVIUFj4P34= +github.com/vmware-tanzu/tanzu-plugin-runtime v0.90.0-alpha.0.0.20230425191535-014e58e69078/go.mod h1:FlvOcF26rX4EA+ADjYTJdFh6WVur6O4jh25FDP9Lp7E= github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xanzy/go-gitlab v0.73.1 h1:UMagqUZLJdjss1SovIC+kJCH4k2AZWXl58gJd38Y/hI= github.com/xanzy/go-gitlab v0.73.1/go.mod h1:d/a0vswScO7Agg1CZNz15Ic6SSvBG9vfw8egL99t4kA= diff --git a/hack/central-repo/README.md b/hack/central-repo/README.md index af208bb3a..87e9f2e54 100644 --- a/hack/central-repo/README.md +++ b/hack/central-repo/README.md @@ -24,7 +24,7 @@ For the `sandbox2:small` image, the `v22.22.22` of the plugins can be installed. The steps to follow to use the test central repo are: 1. Start the test repo with `make start-test-central-repo`. -1. Configure the plugin source for the test central repo: `tz config set env.TANZU_CLI_PRE_RELEASE_REPO_IMAGE localhost:9876/tanzu-cli/plugins/central:small` +1. Configure the plugin source for the test central repo: `tz plugin source update default -u localhost:9876/tanzu-cli/plugins/central:small` Here are the exact commands: @@ -33,7 +33,7 @@ cd tanzu-cli make build make start-test-central-repo alias tz=$(pwd)/bin/tanzu -tz config set env.TANZU_CLI_PRE_RELEASE_REPO_IMAGE localhost:9876/tanzu-cli/plugins/central:small +tz plugin source update default -u localhost:9876/tanzu-cli/plugins/central:small tz plugin search tz plugin install cluster --target tmc @@ -52,7 +52,7 @@ TMC context (`v0.0.1`), but will install them from the test Central Repository. To use the large test central repo instead: ```bash -tz config set env.TANZU_CLI_PRE_RELEASE_REPO_IMAGE localhost:9876/tanzu-cli/plugins/central:large +tz plugin source update default -u localhost:9876/tanzu-cli/plugins/central:large ``` To stop the central repos: `make stop-test-central-repo`. diff --git a/pkg/command/discovery_source.go b/pkg/command/discovery_source.go index 22d57aa6a..aa675b1f1 100644 --- a/pkg/command/discovery_source.go +++ b/pkg/command/discovery_source.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/vmware-tanzu/tanzu-cli/pkg/cli" + "github.com/vmware-tanzu/tanzu-cli/pkg/config" "github.com/vmware-tanzu/tanzu-cli/pkg/constants" "github.com/pkg/errors" @@ -27,40 +28,47 @@ var ( func newDiscoverySourceCmd() *cobra.Command { var discoverySourceCmd = &cobra.Command{ - Use: "source", - // TODO(khouzam): not to be used for the alpha.0 release, but will be re-added after - Hidden: true, - Short: "Manage plugin discovery sources", - Long: "Manage plugin discovery sources. Discovery source provides metadata about the list of available plugins, their supported versions and how to download them.", + Use: "source", + Short: "Manage plugin discovery sources", + Long: "Manage plugin discovery sources. Discovery source provides metadata about the list of available plugins, their supported versions and how to download them.", } discoverySourceCmd.SetUsageFunc(cli.SubCmdUsageFunc) listDiscoverySourceCmd := newListDiscoverySourceCmd() - addDiscoverySourceCmd := newAddDiscoverySourceCmd() updateDiscoverySourceCmd := newUpdateDiscoverySourceCmd() deleteDiscoverySourceCmd := newDeleteDiscoverySourceCmd() - addDiscoverySourceCmd.Flags().StringVarP(&discoverySourceName, "name", "n", "", "name of discovery source") - addDiscoverySourceCmd.Flags().StringVarP(&discoverySourceType, "type", "t", "", "type of discovery source") - addDiscoverySourceCmd.Flags().StringVarP(&uri, "uri", "u", "", "URI for discovery source. URI format might be different based on the type of discovery source") - - // Not handling errors below because cobra handles the error when flag user doesn't provide these required flags - _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "name") - _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "type") - _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "uri") - - updateDiscoverySourceCmd.Flags().StringVarP(&discoverySourceType, "type", "t", "", "type of discovery source") - updateDiscoverySourceCmd.Flags().StringVarP(&uri, "uri", "u", "", "URI for discovery source. URI format might be different based on the type of discovery source") - listDiscoverySourceCmd.Flags().StringVarP(&outputFormat, "output", "o", "", "Output format (yaml|json|table)") discoverySourceCmd.AddCommand( listDiscoverySourceCmd, - addDiscoverySourceCmd, updateDiscoverySourceCmd, deleteDiscoverySourceCmd, ) + if !configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { + discoverySourceCmd.AddCommand(newInitDiscoverySourceCmd()) + updateDiscoverySourceCmd.Flags().StringVarP(&uri, "uri", "u", "", "URI for discovery source. The URI must be of an OCI image") + } else { + updateDiscoverySourceCmd.Flags().StringVarP(&discoverySourceType, "type", "t", "", "type of discovery source") + updateDiscoverySourceCmd.Flags().StringVarP(&uri, "uri", "u", "", "URI for discovery source. The URI format might be different based on the type of discovery source") + + // The "add" and "delete" plugin source commands are not needed for the central repo + addDiscoverySourceCmd := newAddDiscoverySourceCmd() + + addDiscoverySourceCmd.Flags().StringVarP(&discoverySourceName, "name", "n", "", "name of discovery source") + addDiscoverySourceCmd.Flags().StringVarP(&discoverySourceType, "type", "t", "", "type of discovery source") + addDiscoverySourceCmd.Flags().StringVarP(&uri, "uri", "u", "", "URI for discovery source. The URI format might be different based on the type of discovery source") + + // Not handling errors below because cobra handles the error when flag user doesn't provide these required flags + _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "name") + _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "type") + _ = cobra.MarkFlagRequired(addDiscoverySourceCmd.Flags(), "uri") + + discoverySourceCmd.AddCommand( + addDiscoverySourceCmd, + ) + } return discoverySourceCmd } @@ -69,6 +77,19 @@ func newListDiscoverySourceCmd() *cobra.Command { Use: "list", Short: "List available discovery sources", RunE: func(cmd *cobra.Command, args []string) error { + if !configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { + output := component.NewOutputWriter(cmd.OutOrStdout(), outputFormat, "name", "image") + discoverySources, _ := configlib.GetCLIDiscoverySources() + for _, ds := range discoverySources { + if ds.OCI != nil { + output.AddRow(ds.OCI.Name, ds.OCI.Image) + } + } + + output.Render() + return nil + } + output := component.NewOutputWriter(cmd.OutOrStdout(), outputFormat, "name", "type", "scope") // List standalone scoped discoveries @@ -143,23 +164,18 @@ func newUpdateDiscoverySourceCmd() *cobra.Command { Use: "update [name]", Short: "Update a discovery source configuration", Args: cobra.ExactArgs(1), - Example: ` - # Update a local discovery source. If URI is relative path, - # $HOME/.config/tanzu-plugins will be considered base path - tanzu plugin source update standalone-local --type local --uri new/path/to/local/discovery - - # Update an OCI discovery source. URI should be an OCI image. - tanzu plugin source update standalone-oci --type oci --uri projects.registry.vmware.com/tkg/tanzu-plugins/standalone:v1.0`, - RunE: func(cmd *cobra.Command, args []string) error { discoveryName := args[0] - discoveryNoExistError := fmt.Errorf("discovery %q does not exist", discoveryName) discoverySource, _ := configlib.GetCLIDiscoverySource(discoveryName) if discoverySource == nil { - return discoveryNoExistError + return fmt.Errorf("discovery %q does not exist", discoveryName) } + if !configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { + // With the central discovery, there is no more --type flag + discoverySourceType = common.DiscoveryTypeOCI + } newDiscoverySource, err := createDiscoverySource(discoverySourceType, discoveryName, uri) if err != nil { return err @@ -174,6 +190,21 @@ func newUpdateDiscoverySourceCmd() *cobra.Command { return nil }, } + + if !configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { + updateDiscoverySourceCmd.Example = ` + # Update the discovery source for an air-gapped scenario. The URI must be an OCI image. + tanzu plugin source update default --uri registry.example.com/tanzu/plugin-inventory:latest` + } else { + updateDiscoverySourceCmd.Example = ` + # Update a local discovery source. If URI is relative path, + # $HOME/.config/tanzu-plugins will be considered base path + tanzu plugin source update standalone-local --type local --uri new/path/to/local/discovery + + # Update an OCI discovery source. URI should be an OCI image. + tanzu plugin source update standalone-oci --type oci --uri projects.registry.vmware.com/tkg/tanzu-plugins/standalone:v1.0` + } + return updateDiscoverySourceCmd } @@ -184,10 +215,15 @@ func newDeleteDiscoverySourceCmd() *cobra.Command { Args: cobra.ExactArgs(1), Example: ` # Delete a discovery source - tanzu plugin discovery delete standalone-oci`, + tanzu plugin discovery delete default`, RunE: func(cmd *cobra.Command, args []string) (err error) { discoveryName := args[0] + discoverySource, _ := configlib.GetCLIDiscoverySource(discoveryName) + if discoverySource == nil { + return fmt.Errorf("discovery %q does not exist", discoveryName) + } + err = configlib.DeleteCLIDiscoverySource(discoveryName) if err != nil { return err @@ -198,6 +234,25 @@ func newDeleteDiscoverySourceCmd() *cobra.Command { } return deleteDiscoverySourceCmd } + +func newInitDiscoverySourceCmd() *cobra.Command { + var initDiscoverySourceCmd = &cobra.Command{ + Use: "init", + Short: "Initialize the discovery source to its default value", + Args: cobra.MaximumNArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + err := config.PopulateDefaultCentralDiscovery(true) + if err != nil { + return err + } + + log.Successf("successfully initialized discovery source") + return nil + }, + } + return initDiscoverySourceCmd +} + func createDiscoverySource(dsType, dsName, uri string) (configtypes.PluginDiscovery, error) { pluginDiscoverySource := configtypes.PluginDiscovery{} if dsType == "" { diff --git a/pkg/command/plugin_search_test.go b/pkg/command/plugin_search_test.go index 3bf9c7bc5..360bf27ae 100644 --- a/pkg/command/plugin_search_test.go +++ b/pkg/command/plugin_search_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/vmware-tanzu/tanzu-cli/pkg/constants" - "github.com/vmware-tanzu/tanzu-cli/pkg/pluginmanager" "github.com/vmware-tanzu/tanzu-plugin-runtime/config" ) @@ -68,10 +67,6 @@ func TestPluginSearch(t *testing.T) { os.Setenv("TANZU_CONFIG_NEXT_GEN", configFileNG.Name()) os.Setenv("TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER", "No") - // Bypass the environment variable for testing - err = os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, pluginmanager.PreReleasePluginRepoImageBypass) - assert.Nil(err) - featureArray := strings.Split(constants.FeatureContextCommand, ".") err = config.SetFeature(featureArray[1], featureArray[2], "true") assert.Nil(err) diff --git a/pkg/command/plugin_test.go b/pkg/command/plugin_test.go index 8a8cdef87..0cb6e5177 100644 --- a/pkg/command/plugin_test.go +++ b/pkg/command/plugin_test.go @@ -18,7 +18,6 @@ import ( "github.com/vmware-tanzu/tanzu-cli/pkg/cli" "github.com/vmware-tanzu/tanzu-cli/pkg/common" "github.com/vmware-tanzu/tanzu-cli/pkg/constants" - "github.com/vmware-tanzu/tanzu-cli/pkg/pluginmanager" "github.com/vmware-tanzu/tanzu-plugin-runtime/config" configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" "github.com/vmware-tanzu/tanzu-plugin-runtime/plugin" @@ -360,10 +359,6 @@ func TestInstallPlugin(t *testing.T) { os.Setenv("TANZU_CONFIG_NEXT_GEN", tkgConfigFileNG.Name()) os.Setenv("TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER", "No") - // Bypass the environment variable for testing - err = os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, pluginmanager.PreReleasePluginRepoImageBypass) - assert.Nil(err) - featureArray := strings.Split(constants.FeatureContextCommand, ".") err = config.SetFeature(featureArray[1], featureArray[2], "true") assert.Nil(err) diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index 8c99f25f0..09398dae5 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -126,13 +126,6 @@ func GetTrustedRegistries() []string { trustedRegistries = append(trustedRegistries, customImageRepo) } - // If the pre-release plugin repo variable is set, add its host to the list of trusted registries - if preReleaseRepoImage := os.Getenv(constants.ConfigVariablePreReleasePluginRepoImage); preReleaseRepoImage != "" { - if u, err := url.ParseRequestURI("https://" + preReleaseRepoImage); err == nil { - trustedRegistries = append(trustedRegistries, u.Hostname()) - } - } - // Add default central plugin discovery image to the trusted registries if u, err := url.ParseRequestURI("https://" + constants.TanzuCLIDefaultCentralPluginDiscoveryImage); err == nil { trustedRegistries = append(trustedRegistries, u.Hostname()) diff --git a/pkg/config/defaults_test.go b/pkg/config/defaults_test.go index efcc5a9f5..778927b26 100644 --- a/pkg/config/defaults_test.go +++ b/pkg/config/defaults_test.go @@ -25,19 +25,6 @@ var _ = Describe("defaults test cases", func() { Expect(trustedRegis).NotTo(BeNil()) DefaultAllowedPluginRepositories = "" }) - It("trusted registries should include hostname of env var", func() { - testHost := "example.com" - oldValue := os.Getenv(constants.ConfigVariablePreReleasePluginRepoImage) - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, testHost+"/test/path") - Expect(err).To(BeNil()) - - trustedRegis := GetTrustedRegistries() - Expect(trustedRegis).NotTo(BeNil()) - Expect(trustedRegis).Should(ContainElement(testHost)) - - err = os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, oldValue) - Expect(err).To(BeNil()) - }) It("trusted registries should include hostname of additional discoveries", func() { testHost1 := "registry1.vmware.com" testHost2 := "registry2.vmware.com" @@ -51,7 +38,7 @@ var _ = Describe("defaults test cases", func() { Expect(trustedRegis).Should(ContainElement(testHost1)) Expect(trustedRegis).Should(ContainElement(testHost2)) - err = os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, oldValue) + err = os.Setenv(constants.ConfigVariableAdditionalDiscoveryForTesting, oldValue) Expect(err).To(BeNil()) }) It("trusted registries should include hostname of default central discovery", func() { diff --git a/pkg/config/discovery.go b/pkg/config/discovery.go index 8150a6cdb..b224fd817 100644 --- a/pkg/config/discovery.go +++ b/pkg/config/discovery.go @@ -4,81 +4,28 @@ package config import ( + configlib "github.com/vmware-tanzu/tanzu-plugin-runtime/config" configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" - "github.com/vmware-tanzu/tanzu-cli/pkg/common" - "github.com/vmware-tanzu/tanzu-cli/pkg/discovery" - "github.com/vmware-tanzu/tanzu-plugin-runtime/log" + "github.com/vmware-tanzu/tanzu-cli/pkg/constants" ) -func populateDefaultStandaloneDiscovery(c *configtypes.ClientConfig) bool { - if c.ClientOptions == nil { - c.ClientOptions = &configtypes.ClientOptions{} - } - if c.ClientOptions.CLI == nil { - c.ClientOptions.CLI = &configtypes.CLIOptions{} - } - if c.ClientOptions.CLI.DiscoverySources == nil { - c.ClientOptions.CLI.DiscoverySources = make([]configtypes.PluginDiscovery, 0) - } - - defaultDiscovery := getDefaultStandaloneDiscoverySource(GetDefaultStandaloneDiscoveryType()) - if defaultDiscovery == nil { - return false - } - - matchIdx := findDiscoverySourceIndex(c.ClientOptions.CLI.DiscoverySources, func(pd configtypes.PluginDiscovery) bool { - return discovery.CheckDiscoveryName(pd, DefaultStandaloneDiscoveryName) || - discovery.CheckDiscoveryName(pd, DefaultStandaloneDiscoveryNameLocal) - }) - - if matchIdx >= 0 { - if discovery.CompareDiscoverySource(c.ClientOptions.CLI.DiscoverySources[matchIdx], *defaultDiscovery, GetDefaultStandaloneDiscoveryType()) { - return false +func PopulateDefaultCentralDiscovery(force bool) error { + discoverySources, _ := configlib.GetCLIDiscoverySources() + + // Add the default central plugin discovery if it is not there. + // If len(discoverySources)==0, we don't add the central discovery; + // this allows a user to delete the default central discovery and not + // have the CLI add it again. A user can then use "plugin source init" + // to add the default discovery again. + if force || discoverySources == nil { + defaultDiscovery := configtypes.PluginDiscovery{ + OCI: &configtypes.OCIDiscovery{ + Name: DefaultStandaloneDiscoveryName, + Image: constants.TanzuCLIDefaultCentralPluginDiscoveryImage, + }, } - c.ClientOptions.CLI.DiscoverySources[matchIdx] = *defaultDiscovery - return true + return configlib.SetCLIDiscoverySource(defaultDiscovery) } - - // Prepend default discovery to available discovery sources - c.ClientOptions.CLI.DiscoverySources = append([]configtypes.PluginDiscovery{*defaultDiscovery}, c.ClientOptions.CLI.DiscoverySources...) - return true -} - -func findDiscoverySourceIndex(discoverySources []configtypes.PluginDiscovery, matcherFunc func(pd configtypes.PluginDiscovery) bool) int { - for i := range discoverySources { - if matcherFunc(discoverySources[i]) { - return i - } - } - return -1 // haven't found a match -} - -func getDefaultStandaloneDiscoverySource(dsType string) *configtypes.PluginDiscovery { - switch dsType { - case common.DiscoveryTypeLocal: - return getDefaultStandaloneDiscoverySourceLocal() - case common.DiscoveryTypeOCI: - return getDefaultStandaloneDiscoverySourceOCI() - } - log.Warning("unsupported default standalone discovery configuration") return nil } - -func getDefaultStandaloneDiscoverySourceOCI() *configtypes.PluginDiscovery { - return &configtypes.PluginDiscovery{ - OCI: &configtypes.OCIDiscovery{ - Name: DefaultStandaloneDiscoveryName, - Image: GetDefaultStandaloneDiscoveryImage(), - }, - } -} - -func getDefaultStandaloneDiscoverySourceLocal() *configtypes.PluginDiscovery { - return &configtypes.PluginDiscovery{ - Local: &configtypes.LocalDiscovery{ - Name: DefaultStandaloneDiscoveryNameLocal, - Path: GetDefaultStandaloneDiscoveryLocalPath(), - }, - } -} diff --git a/pkg/config/discovery_test.go b/pkg/config/discovery_test.go index 303d0a25e..f2b6a0a51 100644 --- a/pkg/config/discovery_test.go +++ b/pkg/config/discovery_test.go @@ -5,146 +5,167 @@ package config import ( "os" - "testing" + "strings" - "github.com/tj/assert" - - configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "github.com/vmware-tanzu/tanzu-cli/pkg/constants" + configlib "github.com/vmware-tanzu/tanzu-plugin-runtime/config" + "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" ) -func TestConfigPopulateDefaultStandaloneDiscovery(t *testing.T) { - cfg := &configtypes.ClientConfig{ - ClientOptions: &configtypes.ClientOptions{ - CLI: &configtypes.CLIOptions{ - DiscoverySources: []configtypes.PluginDiscovery{}, - }, - }, - } - configureTestDefaultStandaloneDiscoveryOCI() - - assert := assert.New(t) - - added := populateDefaultStandaloneDiscovery(cfg) - assert.Equal(true, added) - assert.Equal(len(cfg.ClientOptions.CLI.DiscoverySources), 1) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Name, DefaultStandaloneDiscoveryName) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Image, "fake.image.repo/package/standalone-plugins:v1.0.0") -} - -func TestConfigPopulateDefaultStandaloneDiscoveryWhenDefaultDiscoveryExistsAndIsSame(t *testing.T) { - cfg := &configtypes.ClientConfig{ - ClientOptions: &configtypes.ClientOptions{ - CLI: &configtypes.CLIOptions{ - DiscoverySources: []configtypes.PluginDiscovery{ - configtypes.PluginDiscovery{ - OCI: &configtypes.OCIDiscovery{ - Name: DefaultStandaloneDiscoveryName, - Image: "fake.image.repo/package/standalone-plugins:v1.0.0", - }, - }, - }, - }, - }, - } - configureTestDefaultStandaloneDiscoveryOCI() - - assert := assert.New(t) - - added := populateDefaultStandaloneDiscovery(cfg) - assert.Equal(false, added) - assert.Equal(len(cfg.ClientOptions.CLI.DiscoverySources), 1) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Name, DefaultStandaloneDiscoveryName) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Image, "fake.image.repo/package/standalone-plugins:v1.0.0") -} - -func TestConfigPopulateDefaultStandaloneDiscoveryWhenDefaultDiscoveryExistsAndIsNotSame(t *testing.T) { - cfg := &configtypes.ClientConfig{ - ClientOptions: &configtypes.ClientOptions{ - CLI: &configtypes.CLIOptions{ - DiscoverySources: []configtypes.PluginDiscovery{ - configtypes.PluginDiscovery{ - OCI: &configtypes.OCIDiscovery{ - Name: DefaultStandaloneDiscoveryName, - Image: "fake.image/path:v2.0.0", - }, - }, - configtypes.PluginDiscovery{ - OCI: &configtypes.OCIDiscovery{ - Name: "additional-discovery", - Image: "additional-discovery/path:v1.0.0", - }, - }, +var _ = Describe("Populate default central discovery", func() { + var ( + configFile *os.File + configFileNG *os.File + err error + ) + BeforeEach(func() { + configFile, err = os.CreateTemp("", "config") + Expect(err).To(BeNil()) + os.Setenv("TANZU_CONFIG", configFile.Name()) + + configFileNG, err = os.CreateTemp("", "config_ng") + Expect(err).To(BeNil()) + os.Setenv("TANZU_CONFIG_NEXT_GEN", configFileNG.Name()) + os.Setenv("TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER", "No") + + featureArray := strings.Split(constants.FeatureContextCommand, ".") + err = configlib.SetFeature(featureArray[1], featureArray[2], "true") + Expect(err).To(BeNil()) + }) + AfterEach(func() { + os.Unsetenv("TANZU_CONFIG") + os.Unsetenv("TANZU_CONFIG_NEXT_GEN") + os.Unsetenv("TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER") + os.RemoveAll(configFile.Name()) + os.RemoveAll(configFileNG.Name()) + }) + Context("when no discovery exists", func() { + It("should create the default central discovery when 'force==false'", func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + It("should create the default central discovery when 'force==true'", func() { + err = PopulateDefaultCentralDiscovery(true) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + }) + Context("when the default discovery already exists", func() { + BeforeEach(func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + }) + It("should keep the default central discovery when 'force==false'", func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + It("should keep the default central discovery when 'force==true'", func() { + err = PopulateDefaultCentralDiscovery(true) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + }) + Context("when a different discovery already exists", func() { + const imageName = "different/image" + BeforeEach(func() { + err := configlib.SetCLIDiscoverySource(types.PluginDiscovery{ + OCI: &types.OCIDiscovery{ + Name: DefaultStandaloneDiscoveryName, + Image: imageName, }, - }, - }, - } - configureTestDefaultStandaloneDiscoveryOCI() - - assert := assert.New(t) - - added := populateDefaultStandaloneDiscovery(cfg) - assert.Equal(true, added) - assert.Equal(len(cfg.ClientOptions.CLI.DiscoverySources), 2) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Name, DefaultStandaloneDiscoveryName) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Image, "fake.image.repo/package/standalone-plugins:v1.0.0") - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[1].OCI.Name, "additional-discovery") - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[1].OCI.Image, "additional-discovery/path:v1.0.0") -} - -func TestConfigPopulateDefaultStandaloneDiscoveryLocal(t *testing.T) { - cfg := &configtypes.ClientConfig{ - ClientOptions: &configtypes.ClientOptions{ - CLI: &configtypes.CLIOptions{ - DiscoverySources: []configtypes.PluginDiscovery{}, - }, - }, - } - - configureTestDefaultStandaloneDiscoveryLocal() - - assert := assert.New(t) - - added := populateDefaultStandaloneDiscovery(cfg) - assert.Equal(true, added) - assert.Equal(len(cfg.ClientOptions.CLI.DiscoverySources), 1) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].Local.Name, DefaultStandaloneDiscoveryNameLocal) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].Local.Path, "local/path") -} - -func TestConfigPopulateDefaultStandaloneDiscoveryEnvVariables(t *testing.T) { - cfg := &configtypes.ClientConfig{ - ClientOptions: &configtypes.ClientOptions{ - CLI: &configtypes.CLIOptions{ - DiscoverySources: []configtypes.PluginDiscovery{}, - }, - }, - } - - configureTestDefaultStandaloneDiscoveryOCI() - - os.Setenv(constants.ConfigVariableCustomImageRepository, "env.fake.image.repo") - os.Setenv(constants.ConfigVariableDefaultStandaloneDiscoveryImagePath, "package/env/standalone-plugins") - os.Setenv(constants.ConfigVariableDefaultStandaloneDiscoveryImageTag, "v2.0.0") - - assert := assert.New(t) - - added := populateDefaultStandaloneDiscovery(cfg) - assert.Equal(true, added) - assert.Equal(len(cfg.ClientOptions.CLI.DiscoverySources), 1) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Name, DefaultStandaloneDiscoveryName) - assert.Equal(cfg.ClientOptions.CLI.DiscoverySources[0].OCI.Image, "env.fake.image.repo/package/env/standalone-plugins:v2.0.0") -} - -func configureTestDefaultStandaloneDiscoveryOCI() { - DefaultStandaloneDiscoveryType = "oci" - DefaultStandaloneDiscoveryRepository = "fake.image.repo" - DefaultStandaloneDiscoveryImagePath = "package/standalone-plugins" - DefaultStandaloneDiscoveryImageTag = "v1.0.0" -} - -func configureTestDefaultStandaloneDiscoveryLocal() { - DefaultStandaloneDiscoveryType = "local" - DefaultStandaloneDiscoveryLocalPath = "local/path" -} + }) + Expect(err).To(BeNil()) + }) + It("should keep the existing discovery when 'force==false'", func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(imageName)) + }) + It("should replace the existing discovery when 'force==true'", func() { + err = PopulateDefaultCentralDiscovery(true) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + }) + Context("when a the default central discovery was deleted by the user", func() { + BeforeEach(func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + + err := configlib.DeleteCLIDiscoverySource(DefaultStandaloneDiscoveryName) + Expect(err).To(BeNil()) + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(discoverySources).ToNot(BeNil()) + Expect(len(discoverySources)).To(Equal(0)) + }) + It("should not add the default discovery when 'force==false'", func() { + err = PopulateDefaultCentralDiscovery(false) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(discoverySources).ToNot(BeNil()) + Expect(len(discoverySources)).To(Equal(0)) + }) + It("should add the default discovery when 'force==true'", func() { + err = PopulateDefaultCentralDiscovery(true) + Expect(err).To(BeNil()) + + discoverySources, err := configlib.GetCLIDiscoverySources() + Expect(err).To(BeNil()) + Expect(len(discoverySources)).To(Equal(1)) + // It should be an OCI discovery with a specific name and image + Expect(discoverySources[0].OCI).ToNot(BeNil()) + Expect(discoverySources[0].OCI.Name).To(Equal(DefaultStandaloneDiscoveryName)) + Expect(discoverySources[0].OCI.Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + }) +}) diff --git a/pkg/config/init.go b/pkg/config/init.go index 08a23f371..75cb98a08 100644 --- a/pkg/config/init.go +++ b/pkg/config/init.go @@ -13,16 +13,11 @@ import ( func init() { // Acquire tanzu config lock config.AcquireTanzuConfigLock() - defer config.ReleaseTanzuConfigLock() c, err := config.GetClientConfigNoLock() if err != nil { log.Warningf("unable to get client config: %v", err) } - // Note: Commenting the below line since CLI wouldn't support any default discovery going forward. - // Users have to add the discovery sources by using `tanzu plugin source add` command - // TODO: update/delete the below line after CLI make changes related to centralized repository - // addedDefaultDiscovery := populateDefaultStandaloneDiscovery(c) addedFeatureFlags := AddDefaultFeatureFlagsIfMissing(c, constants.DefaultCliFeatureFlags) addedEdition := addDefaultEditionIfMissing(c) addedBomRepo := AddBomRepoIfMissing(c) @@ -33,4 +28,15 @@ func init() { if addedFeatureFlags || addedEdition || addedCompatabilityFile || addedBomRepo || addedContexts { _ = config.StoreClientConfig(c) } + + // We need to release the config lock before call ing PopulateDefaultCentralDiscovery() because + // PopulateDefaultCentralDiscovery() handles the locking of the config file itself by + // using the config file higher-level APIs + config.ReleaseTanzuConfigLock() + + // Can only check for config.IsFeatureActivated() once the feature flags are setup + // by the above calls. + if !config.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { + _ = PopulateDefaultCentralDiscovery(false) + } } diff --git a/pkg/constants/env_variables.go b/pkg/constants/env_variables.go index ba05f0fab..9e936a5d0 100644 --- a/pkg/constants/env_variables.go +++ b/pkg/constants/env_variables.go @@ -10,7 +10,6 @@ const ( const ( AllowedRegistries = "ALLOWED_REGISTRY" - ConfigVariablePreReleasePluginRepoImage = "TANZU_CLI_PRE_RELEASE_REPO_IMAGE" ConfigVariableAdditionalDiscoveryForTesting = "TANZU_CLI_ADDITIONAL_PLUGIN_DISCOVERY_IMAGES_TEST_ONLY" // PluginDiscoveryImageSignatureVerificationSkipList is a comma separated list of discovery image urls PluginDiscoveryImageSignatureVerificationSkipList = "TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST" diff --git a/pkg/pluginmanager/manager.go b/pkg/pluginmanager/manager.go index 292ab7278..1fda78bc2 100644 --- a/pkg/pluginmanager/manager.go +++ b/pkg/pluginmanager/manager.go @@ -49,8 +49,6 @@ const ( PluginManifestFileName = "plugin_manifest.yaml" // PluginFileName is the file name for the plugin info. PluginFileName = "plugin.yaml" - - PreReleasePluginRepoImageBypass = "TEST_BYPASS" ) var execCommand = exec.Command @@ -199,31 +197,6 @@ func DiscoverPluginGroups() ([]*discovery.DiscoveredPluginGroups, error) { return discoverPluginGroups(discoveries) } -// getPreReleasePluginDiscovery -// For pre-releases CLI points to a default staging central plugin discovery image -// from where the CLI will discover plugins. -// For pre-releases, CLI also allows default discovery image to be overridden by using -// an environment variable and pointing to the different repository of plugins. -// -// This is because the configuration cfg.ClientOptions.CLI.DiscoverySources -// is read by older CLIs so we don't want to modify it. -// TODO(khouzam): remove before 1.0 -func getPreReleasePluginDiscovery() ([]configtypes.PluginDiscovery, error) { - centralRepoTestImage := os.Getenv(constants.ConfigVariablePreReleasePluginRepoImage) - if centralRepoTestImage == "" { - centralRepoTestImage = constants.TanzuCLIDefaultCentralPluginDiscoveryImage - } else if centralRepoTestImage == PreReleasePluginRepoImageBypass { - return nil, nil - } - return []configtypes.PluginDiscovery{ - { - OCI: &configtypes.OCIDiscovery{ - Name: "default", - Image: centralRepoTestImage, - }, - }}, nil -} - // getAdditionalTestPluginDiscoveries returns an array of plugin discoveries that // are meant to be used for testing new plugin version. The comma-separated list of // such discoveries can be specified through the environment variable @@ -1505,28 +1478,12 @@ func getPluginDiscoveries() ([]configtypes.PluginDiscovery, error) { if !configlib.IsFeatureActivated(constants.FeatureDisableCentralRepositoryForTesting) { // Look for testing discoveries. Those should be stored and searched AFTER the central repo. testDiscoveries = getAdditionalTestPluginDiscoveries() - - // Look for the pre-release Central Repository discovery - pd, err := getPreReleasePluginDiscovery() - if err != nil { - return testDiscoveries, err - } - // If pd is nil without an error, we bypass the prerelease discovery - // and fallback to the normal plugin source configuration. - if pd != nil { - // The central repository discovery MUST be searched first - // so we insert before the test discoveries - return append(pd, testDiscoveries...), nil - } } - discoverySources, _ := configlib.GetCLIDiscoverySources() - if discoverySources == nil { - return testDiscoveries, nil - } // The configured discoveries should be searched BEFORE the test discoveries. // For example, if the staging central repo is added as a test discovery, it // may contain older versions of a plugin that is now published to the production // central repo; we therefore need to search the test discoveries last. + discoverySources, _ := configlib.GetCLIDiscoverySources() return append(discoverySources, testDiscoveries...), nil } diff --git a/pkg/pluginmanager/manager_helper_test.go b/pkg/pluginmanager/manager_helper_test.go index c458e7cdd..85a4aa3bf 100644 --- a/pkg/pluginmanager/manager_helper_test.go +++ b/pkg/pluginmanager/manager_helper_test.go @@ -57,10 +57,10 @@ func setupLocalDistroForTesting() func() { common.DefaultLocalPluginDistroDir = filepath.Join(tmpDir, "distro") common.DefaultCacheDir = filepath.Join(tmpDir, "cache") - tkgConfigFile := filepath.Join(tmpDir, "tanzu_config.yaml") - tkgConfigNextGenFile := filepath.Join(tmpDir, "tanzu_config_ng.yaml") - os.Setenv("TANZU_CONFIG", tkgConfigFile) - os.Setenv("TANZU_CONFIG_NEXT_GEN", tkgConfigNextGenFile) + configFile := filepath.Join(tmpDir, "tanzu_config.yaml") + configNextGenFile := filepath.Join(tmpDir, "tanzu_config_ng.yaml") + os.Setenv("TANZU_CONFIG", configFile) + os.Setenv("TANZU_CONFIG_NEXT_GEN", configNextGenFile) os.Setenv("HOME", tmpHomeDir) err = copy.Copy(filepath.Join("test", "local"), common.DefaultLocalPluginDistroDir) @@ -68,12 +68,12 @@ func setupLocalDistroForTesting() func() { log.Fatal(err, "Error while setting local distro for testing") } - err = copy.Copy(filepath.Join("test", "config.yaml"), tkgConfigFile) + err = copy.Copy(filepath.Join("test", "config.yaml"), configFile) if err != nil { log.Fatal(err, "Error while coping tanzu config file for testing") } - err = copy.Copy(filepath.Join("test", "config-ng.yaml"), tkgConfigNextGenFile) + err = copy.Copy(filepath.Join("test", "config-ng.yaml"), configNextGenFile) if err != nil { log.Fatal(err, "Error while coping tanzu config next gen file for testing") } diff --git a/pkg/pluginmanager/manager_test.go b/pkg/pluginmanager/manager_test.go index b48a0172b..7fc64809d 100644 --- a/pkg/pluginmanager/manager_test.go +++ b/pkg/pluginmanager/manager_test.go @@ -91,8 +91,6 @@ func Test_DiscoverPlugins(t *testing.T) { assertions := assert.New(t) defer setupLocalDistroForTesting()() - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) serverPlugins, standalonePlugins := DiscoverPlugins() assertions.Equal(len(expectedDiscoveredContextPlugins), len(serverPlugins)) @@ -109,7 +107,7 @@ func Test_DiscoverPlugins(t *testing.T) { assertions.Equal(expectedDiscoveredPlugins[i].Target, p.Target) } - err = configlib.SetFeature("global", "context-target-v2", "false") + err := configlib.SetFeature("global", "context-target-v2", "false") assertions.Nil(err) serverPlugins, standalonePlugins = DiscoverPlugins() @@ -227,16 +225,12 @@ func Test_InstallPlugin_InstalledPlugins_No_Central_Repo(t *testing.T) { func Test_InstallPlugin_InstalledPlugins_Central_Repo(t *testing.T) { assertions := assert.New(t) - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) - defer setupLocalDistroForTesting()() execCommand = fakeInfoExecCommand defer func() { execCommand = exec.Command }() // Try installing nonexistent plugin - err = InstallStandalonePlugin("not-exists", "v0.2.0", configtypes.TargetUnknown) + err := InstallStandalonePlugin("not-exists", "v0.2.0", configtypes.TargetUnknown) assertions.NotNil(err) assertions.Contains(err.Error(), "unable to find plugin 'not-exists'") @@ -321,10 +315,6 @@ func Test_InstallPlugin_InstalledPlugins_Central_Repo(t *testing.T) { func Test_InstallPluginFromGroup(t *testing.T) { assertions := assert.New(t) - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) - defer setupLocalDistroForTesting()() execCommand = fakeInfoExecCommand defer func() { execCommand = exec.Command }() @@ -332,7 +322,7 @@ func Test_InstallPluginFromGroup(t *testing.T) { // A local discovery currently does not support groups, but we can // at least do negative testing groupID := "vmware-tkg/v2.1.0" - err = InstallPluginsFromGroup("cluster", groupID) + err := InstallPluginsFromGroup("cluster", groupID) assertions.NotNil(err) assertions.Contains(err.Error(), fmt.Sprintf("could not find group '%s'", groupID)) } @@ -340,10 +330,6 @@ func Test_InstallPluginFromGroup(t *testing.T) { func Test_DiscoverPluginGroups(t *testing.T) { assertions := assert.New(t) - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) - defer setupLocalDistroForTesting()() execCommand = fakeInfoExecCommand defer func() { execCommand = exec.Command }() @@ -359,9 +345,6 @@ func Test_AvailablePlugins(t *testing.T) { assertions := assert.New(t) defer setupLocalDistroForTesting()() - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) expectedDiscoveredPlugins := append(expectedDiscoveredContextPlugins, expectedDiscoveredStandalonePlugins...) discoveredPlugins, err := AvailablePlugins() @@ -463,9 +446,6 @@ func Test_AvailablePlugins_With_K8s_None_Target_Plugin_Name_Conflict_With_One_In assertions := assert.New(t) defer setupLocalDistroForTesting()() - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) expectedDiscoveredPlugins := append(expectedDiscoveredContextPlugins, expectedDiscoveredStandalonePlugins...) discoveredPlugins, err := AvailablePlugins() @@ -519,9 +499,6 @@ func Test_AvailablePlugins_With_K8s_None_Target_Plugin_Name_Conflict_With_Plugin assertions := assert.New(t) defer setupLocalDistroForTesting()() - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) expectedDiscoveredPlugins := append(expectedDiscoveredContextPlugins, expectedDiscoveredStandalonePlugins...) discoveredPlugins, err := AvailablePlugins() @@ -689,12 +666,9 @@ func Test_DescribePlugin(t *testing.T) { assertions := assert.New(t) defer setupLocalDistroForTesting()() - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) // Try to describe plugin when plugin is not installed - _, err = DescribePlugin("login", configtypes.TargetUnknown) + _, err := DescribePlugin("login", configtypes.TargetUnknown) assertions.NotNil(err) assertions.Contains(err.Error(), "unable to find plugin 'login'") @@ -733,12 +707,9 @@ func Test_DeletePlugin(t *testing.T) { assertions := assert.New(t) defer setupLocalDistroForTesting()() - // Bypass the environment variable for testing - err := os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, PreReleasePluginRepoImageBypass) - assertions.Nil(err) // Try to delete plugin when plugin is not installed - err = DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: configtypes.TargetTMC, ForceDelete: true}) + err := DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: configtypes.TargetTMC, ForceDelete: true}) assertions.NotNil(err) assertions.Contains(err.Error(), "unable to find plugin 'cluster'") @@ -1366,11 +1337,6 @@ func TestGetPluginDiscoveries(t *testing.T) { err := os.Setenv(constants.ConfigVariableAdditionalDiscoveryForTesting, "") assertions.Nil(err) - // Bypass the temporary pre-release variable - err = os.Setenv(constants.ConfigVariablePreReleasePluginRepoImage, - PreReleasePluginRepoImageBypass) - assertions.Nil(err) - discoveries, err := getPluginDiscoveries() assertions.Nil(err) assertions.Equal(2, len(discoveries)) diff --git a/pkg/pluginmanager/test/config-ng.yaml b/pkg/pluginmanager/test/config-ng.yaml index 8a588836f..9f597f2cf 100644 --- a/pkg/pluginmanager/test/config-ng.yaml +++ b/pkg/pluginmanager/test/config-ng.yaml @@ -1,3 +1,11 @@ +cli: + discoverySources: + - local: + name: default-local + path: default + - local: + name: fake + path: standalone currentContext: kubernetes: mgmt mission-control: tmc-fake diff --git a/pkg/pluginmanager/test/config.yaml b/pkg/pluginmanager/test/config.yaml index 8874a0d42..c2ecbd624 100644 --- a/pkg/pluginmanager/test/config.yaml +++ b/pkg/pluginmanager/test/config.yaml @@ -1,14 +1,4 @@ apiVersion: config.tanzu.vmware.com/v1alpha1 -clientOptions: - cli: - discoverySources: - - local: - name: default-local - path: default - - local: - name: fake - path: standalone - useContextAwareDiscovery: true current: mgmt currentContext: kubernetes: mgmt diff --git a/test/e2e/Makefile b/test/e2e/Makefile index 07f4fd2a4..076a655ef 100644 --- a/test/e2e/Makefile +++ b/test/e2e/Makefile @@ -42,9 +42,10 @@ e2e-cli-plugin-compatibility-test: @if [ "${TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL}" = "" ]; then \ echo "***Skipping Plugin Compatibility test cases because environment variables TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL is not set***" ; \ else \ - export TANZU_CLI_PRE_RELEASE_REPO_IMAGE=$(TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL) ; \ + export TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL=$(TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL) ; \ export TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST=$(TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL) ; \ export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="Yes" ; \ + export ALLOWED_REGISTRY=$$(echo ${TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL} | cut -f1 -d/ | cut -f1 -d:) ; \ ${GO} test ${ROOT_DIR}/test/e2e/plugins_compatibility -timeout ${E2E_TEST_TIMEOUT} -race -coverprofile ${E2E_TEST_OUTPUT} ${GOTEST_VERBOSE} ; \ fi @@ -54,9 +55,9 @@ e2e-cli-plugin-lifecycle-sync-test: echo "***Skipping Plugin life cycle test cases because environment variables TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL is not set***" ; \ else \ export TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) ; \ - export TANZU_CLI_PRE_RELEASE_REPO_IMAGE=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) ; \ export TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST=$(TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) ; \ export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="Yes" ; \ + export ALLOWED_REGISTRY=$$(echo ${TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL} | cut -f1 -d/ | cut -f1 -d:) ; \ ${GO} test ${ROOT_DIR}/test/e2e/plugin_lifecycle -timeout ${E2E_TEST_TIMEOUT} -race -coverprofile ${E2E_TEST_OUTPUT} ${GOTEST_VERBOSE} ; \ ${GO} test ${ROOT_DIR}/test/e2e/plugin_sync -timeout ${E2E_TEST_TIMEOUT} -race -coverprofile ${E2E_TEST_OUTPUT} ${GOTEST_VERBOSE} ; \ fi diff --git a/test/e2e/README.md b/test/e2e/README.md index 7d8af303c..aec1c9acf 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -109,9 +109,6 @@ type PluginBasicOps interface { } // PluginSourceOps helps 'plugin source' commands type PluginSourceOps interface { - // AddPluginDiscoverySource adds plugin discovery source, and returns stdOut and error info - AddPluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error) - // UpdatePluginDiscoverySource updates plugin discovery source, and returns stdOut and error info UpdatePluginDiscoverySource(discoveryOpts *DiscoveryOptions) (string, error) @@ -120,6 +117,9 @@ type PluginSourceOps interface { // ListPluginSources returns all available plugin discovery sources ListPluginSources() ([]*PluginSourceInfo, error) + + // InitPluginDiscoverySource initializes the plugin source to its default value, and returns stdOut and error info + InitPluginDiscoverySource(opts ...E2EOption) (string, error) } type PluginGroupOps interface { // SearchPluginGroups performs plugin group search diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 253680bcd..06f3162d2 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -28,10 +28,10 @@ const ( ConfigServerDelete = "%s config server delete %s -y" // Plugin commands - AddPluginSource = "%s plugin source add --name %s --type %s --uri %s" - UpdatePluginSource = "%s plugin source update %s --type %s --uri %s" + UpdatePluginSource = "%s plugin source update %s --uri %s" ListPluginSourcesWithJSONOutputFlag = "%s plugin source list -o json" DeletePluginSource = "%s plugin source delete %s" + InitPluginDiscoverySource = "%s plugin source init" ListPluginsCmdWithJSONOutputFlag = "%s plugin list -o json" SearchPluginsCmd = "%s plugin search" SearchPluginGroupsCmd = "%s plugin group search" @@ -48,7 +48,6 @@ const ( PluginKey = "%s_%s_%s" // Plugins - Name_Target_Versions // Central repository - CentralRepositoryPreReleaseRepoImage = "TANZU_CLI_PRE_RELEASE_REPO_IMAGE" TanzuCliE2ETestCentralRepositoryURL = "TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL" TanzuCliE2ETestLocalCentralRepositoryURL = "TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL" @@ -102,8 +101,7 @@ const ( UnableToFindPlugin = "unable to find plugin '%s'" InvalidTargetSpecified = "invalid target specified. Please specify correct value of `--target` or `-t` flag from 'global/kubernetes/k8s/mission-control/tmc'" InvalidTargetGlobal = "invalid target for plugin: global" - UnknownDiscoverySourceType = "unknown discovery source type" - DiscoverySourceNotFound = "cli discovery source not found" + DiscoverySourceNotFound = "discovery %q does not exist" ErrorLogForCommandWithErrStdErrAndStdOut = "error while executing command:'%s', error:'%s' stdErr:'%s' stdOut: '%s'" FailedToConstructJSONNodeFromOutputAndErrInfo = "failed to construct json node from output:'%s' error:'%s' " FailedToConstructJSONNodeFromOutput = "failed to construct json node from output:'%s'" diff --git a/test/e2e/framework/output_handling.go b/test/e2e/framework/output_handling.go index 79a348d25..84e3498fd 100644 --- a/test/e2e/framework/output_handling.go +++ b/test/e2e/framework/output_handling.go @@ -27,8 +27,7 @@ type PluginGroup struct { type PluginSourceInfo struct { Name string `json:"name"` - Scope string `json:"scope"` - Type string `json:"type"` + Image string `json:"image"` } type ContextListInfo struct { diff --git a/test/e2e/framework/plugin_lifecycle_operations.go b/test/e2e/framework/plugin_lifecycle_operations.go index 519107fc0..c73bf7eaa 100644 --- a/test/e2e/framework/plugin_lifecycle_operations.go +++ b/test/e2e/framework/plugin_lifecycle_operations.go @@ -40,9 +40,6 @@ type PluginBasicOps interface { // PluginSourceOps helps 'plugin source' commands type PluginSourceOps interface { - // AddPluginDiscoverySource adds plugin discovery source, and returns stdOut and error info - AddPluginDiscoverySource(discoveryOpts *DiscoveryOptions, opts ...E2EOption) (string, error) - // UpdatePluginDiscoverySource updates plugin discovery source, and returns stdOut and error info UpdatePluginDiscoverySource(discoveryOpts *DiscoveryOptions, opts ...E2EOption) (string, error) @@ -51,6 +48,9 @@ type PluginSourceOps interface { // ListPluginSources returns all available plugin discovery sources ListPluginSources(opts ...E2EOption) ([]*PluginSourceInfo, error) + + // InitPluginDiscoverySource initializes the plugin source to its default value, and returns stdOut and error info + InitPluginDiscoverySource(opts ...E2EOption) (string, error) } type PluginGroupOps interface { @@ -86,15 +86,9 @@ func NewPluginLifecycleOps() PluginCmdOps { } } -func (po *pluginCmdOps) AddPluginDiscoverySource(discoveryOpts *DiscoveryOptions, opts ...E2EOption) (string, error) { - addCmd := fmt.Sprintf(AddPluginSource, "%s", discoveryOpts.Name, discoveryOpts.SourceType, discoveryOpts.URI) - out, _, err := po.cmdExe.TanzuCmdExec(addCmd, opts...) - return out.String(), err -} - func (po *pluginCmdOps) UpdatePluginDiscoverySource(discoveryOpts *DiscoveryOptions, opts ...E2EOption) (string, error) { - addCmd := fmt.Sprintf(UpdatePluginSource, "%s", discoveryOpts.Name, discoveryOpts.SourceType, discoveryOpts.URI) - out, _, err := po.cmdExe.TanzuCmdExec(addCmd, opts...) + updateCmd := fmt.Sprintf(UpdatePluginSource, "%s", discoveryOpts.Name, discoveryOpts.URI) + out, _, err := po.cmdExe.TanzuCmdExec(updateCmd, opts...) return out.String(), err } @@ -111,6 +105,15 @@ func (po *pluginCmdOps) DeletePluginDiscoverySource(pluginSourceName string, opt return out.String(), err } +func (po *pluginCmdOps) InitPluginDiscoverySource(opts ...E2EOption) (string, error) { + initCmd := fmt.Sprintf(InitPluginDiscoverySource, "%s") + out, stdErr, err := po.cmdExe.TanzuCmdExec(initCmd, opts...) + if err != nil { + log.Errorf(ErrorLogForCommandWithErrStdErrAndStdOut, initCmd, err.Error(), stdErr.String(), out.String()) + } + return out.String(), err +} + func (po *pluginCmdOps) ListPlugins(opts ...E2EOption) ([]*PluginInfo, error) { return ExecuteCmdAndBuildJSONOutput[PluginInfo](po.cmdExe, ListPluginsCmdWithJSONOutputFlag, opts...) } diff --git a/test/e2e/plugin_lifecycle/plugin_lifecycle_suite_test.go b/test/e2e/plugin_lifecycle/plugin_lifecycle_suite_test.go index eefc85de9..2a58eb0c9 100644 --- a/test/e2e/plugin_lifecycle/plugin_lifecycle_suite_test.go +++ b/test/e2e/plugin_lifecycle/plugin_lifecycle_suite_test.go @@ -26,7 +26,6 @@ var ( pluginsSearchList []*framework.PluginInfo pluginGroups []*framework.PluginGroup pluginGroupToPluginListMap map[string][]*framework.PluginInfo - pluginSourceName string ) // BeforeSuite initializes and set up the environment to execute the plugin life cycle and plugin group life cycle end-to-end test cases @@ -35,8 +34,10 @@ var _ = BeforeSuite(func() { // check E2E test central repo URL (TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) e2eTestLocalCentralRepoURL = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryURL) Expect(e2eTestLocalCentralRepoURL).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository URL", framework.TanzuCliE2ETestLocalCentralRepositoryURL)) - // set E2E test central repo URL to TANZU_CLI_PRE_RELEASE_REPO_IMAGE - os.Setenv(framework.CentralRepositoryPreReleaseRepoImage, e2eTestLocalCentralRepoURL) + + // setup the test central repo + _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: "default", SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) + Expect(err).To(BeNil(), "should not get any error for plugin source update") // search plugin groups and make sure there plugin groups available pluginGroups = SearchAllPluginGroups(tf) diff --git a/test/e2e/plugin_lifecycle/plugin_lifecycle_test.go b/test/e2e/plugin_lifecycle/plugin_lifecycle_test.go index c8ef82bdc..bf1925aac 100644 --- a/test/e2e/plugin_lifecycle/plugin_lifecycle_test.go +++ b/test/e2e/plugin_lifecycle/plugin_lifecycle_test.go @@ -10,6 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/vmware-tanzu/tanzu-cli/pkg/constants" "github.com/vmware-tanzu/tanzu-cli/test/e2e/framework" ) @@ -23,40 +24,36 @@ import ( // 1. plugin search, install, delete, describe, list (with negative use cases) // 2. plugin source add/update/list/delete (with negative use cases) var _ = framework.CLICoreDescribe("[Tests:E2E][Feature:Plugin-lifecycle]", func() { - // use case: tanzu plugin source add, list, update, delete - // add plugin source + // use case: tanzu plugin source list, update, delete, init // a. list plugin sources and validate plugin source created in previous step // b. update plugin source URL - // c. (negative test) update plugin source URL with incorrect type (--type) - // d. (negative test) delete plugin source which is not exists - // e. delete plugin source which was created in previous test case - Context("plugin source use cases: tanzu plugin source add, list, update, delete", func() { - // Test case: add plugin source - It("add plugin source", func() { - pluginSourceName = framework.RandomString(5) - _, err := tf.PluginCmd.AddPluginDiscoverySource(&framework.DiscoveryOptions{Name: pluginSourceName, SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) - Expect(err).To(BeNil(), "should not get any error for plugin source add") - }) + // c. (negative test) delete plugin source which is not exists + // d. delete plugin source which was created in previous test case + // e. initialize the default plugin source + Context("plugin source use cases: tanzu plugin source list, update, delete, init", func() { + const pluginSourceName = "default" // Test case: list plugin sources and validate plugin source created in previous step It("list plugin source and validate previously created plugin source available", func() { list, err := tf.PluginCmd.ListPluginSources() Expect(err).To(BeNil(), "should not get any error for plugin source list") Expect(framework.IsPluginSourceExists(list, pluginSourceName)).To(BeTrue()) + Expect(list[0].Image).To(Equal(e2eTestLocalCentralRepoURL)) }) // Test case: update plugin source URL It("update previously created plugin source URL", func() { - _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: pluginSourceName, SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) + newImage := framework.RandomString(5) + _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: pluginSourceName, SourceType: framework.SourceType, URI: newImage}) Expect(err).To(BeNil(), "should not get any error for plugin source update") - }) - // Test case: (negative test) update plugin source URL with incorrect type (--type) - It("update previously created plugin source with incorrect type", func() { - _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: pluginSourceName, SourceType: framework.SourceType + framework.RandomString(3), URI: e2eTestLocalCentralRepoURL}) - Expect(err.Error()).To(ContainSubstring(framework.UnknownDiscoverySourceType)) + list, err := tf.PluginCmd.ListPluginSources() + Expect(err).To(BeNil(), "should not get any error for plugin source list") + Expect(framework.IsPluginSourceExists(list, pluginSourceName)).To(BeTrue()) + Expect(list[0].Image).To(Equal(newImage)) }) // Test case: (negative test) delete plugin source which is not exists It("negative test case: delete plugin source which is not exists", func() { - _, err := tf.PluginCmd.DeletePluginDiscoverySource(framework.RandomString(5)) - Expect(err.Error()).To(ContainSubstring(framework.DiscoverySourceNotFound)) + wrongName := framework.RandomString(5) + _, err := tf.PluginCmd.DeletePluginDiscoverySource(wrongName) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(framework.DiscoverySourceNotFound, wrongName))) }) // Test case: delete plugin source which was created in previous test case It("delete previously created plugin source and validate with plugin source list", func() { @@ -66,6 +63,19 @@ var _ = framework.CLICoreDescribe("[Tests:E2E][Feature:Plugin-lifecycle]", func( Expect(err).To(BeNil(), "should not get any error for plugin source list") Expect(framework.IsPluginSourceExists(list, pluginSourceName)).To(BeFalse()) }) + // Test case: delete plugin source which was created in previous test case + It("initialize the default plugin source and validate with plugin source list", func() { + _, err := tf.PluginCmd.InitPluginDiscoverySource() + Expect(err).To(BeNil(), "should not get any error for plugin source init") + list, err := tf.PluginCmd.ListPluginSources() + Expect(err).To(BeNil(), "should not get any error for plugin source list") + Expect(framework.IsPluginSourceExists(list, pluginSourceName)).To(BeTrue()) + Expect(list[0].Image).To(Equal(constants.TanzuCLIDefaultCentralPluginDiscoveryImage)) + }) + It("put back the E2E plugin repository", func() { + _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: pluginSourceName, SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) + Expect(err).To(BeNil(), "should not get any error for plugin source update") + }) }) // use case: tanzu plugin clean, install and describe, list, delete // a. clean plugins if any installed already diff --git a/test/e2e/plugin_sync/plugin_sync_lifecycle_suite_test.go b/test/e2e/plugin_sync/plugin_sync_lifecycle_suite_test.go index fa1d47785..e1a04b447 100644 --- a/test/e2e/plugin_sync/plugin_sync_lifecycle_suite_test.go +++ b/test/e2e/plugin_sync/plugin_sync_lifecycle_suite_test.go @@ -36,11 +36,14 @@ const numberOfPluginsToInstall = 3 // BeforeSuite initializes and set up the environment to execute the plugin life cycle and plugin group life cycle end-to-end test cases var _ = BeforeSuite(func() { tf = framework.NewFramework() + // check E2E test central repo URL (TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) e2eTestLocalCentralRepoURL = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryURL) Expect(e2eTestLocalCentralRepoURL).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository URL", framework.TanzuCliE2ETestLocalCentralRepositoryURL)) - // set E2E test central repo URL to TANZU_CLI_PRE_RELEASE_REPO_IMAGE - os.Setenv(framework.CentralRepositoryPreReleaseRepoImage, e2eTestLocalCentralRepoURL) + + // setup the test central repo + _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: "default", SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) + Expect(err).To(BeNil(), "should not get any error for plugin source update") // search plugin groups and make sure there plugin groups available pluginGroups = helper.SearchAllPluginGroups(tf) diff --git a/test/e2e/plugins_compatibility/plugins_compatibility_suite_test.go b/test/e2e/plugins_compatibility/plugins_compatibility_suite_test.go index d594e7fe1..c703478b4 100644 --- a/test/e2e/plugins_compatibility/plugins_compatibility_suite_test.go +++ b/test/e2e/plugins_compatibility/plugins_compatibility_suite_test.go @@ -30,7 +30,13 @@ var ( // In the BeforeSuite search for the test-plugin-'s from the TANZU_CLI_E2E_TEST_CENTRAL_REPO_URL test central repository var _ = BeforeSuite(func() { tf = framework.NewFramework() + + // setup the test central repo + centralURI := os.Getenv(framework.TanzuCliE2ETestCentralRepositoryURL) + _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: "default", SourceType: framework.SourceType, URI: centralURI}) + Expect(err).To(BeNil(), "should not get any error for plugin source update") + // get all plugins with name prefix "test-plugin-" plugins = plugincompatibility.PluginsForCompatibilityTesting(tf) - Expect(len(plugins)).NotTo(BeZero(), fmt.Sprintf("there are no test-plugin-'s in test central repo:%s , make sure its valid test central repo with test-plugins", os.Getenv(framework.TanzuCliE2ETestCentralRepositoryURL))) + Expect(len(plugins)).NotTo(BeZero(), fmt.Sprintf("there are no test-plugin-'s in test central repo:%s , make sure its valid test central repo with test-plugins", centralURI)) })