diff --git a/pkg/v1/cli/catalog/catalog_test.go b/pkg/v1/cli/catalog/catalog_test.go index 48c0502f2d..2b2cf3b3b9 100644 --- a/pkg/v1/cli/catalog/catalog_test.go +++ b/pkg/v1/cli/catalog/catalog_test.go @@ -13,6 +13,7 @@ import ( cliv1alpha1 "github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1" "github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/common" + "github.com/vmware-tanzu/tanzu-framework/pkg/v1/config" ) func Test_ContextCatalog_With_Empty_Context(t *testing.T) { @@ -187,7 +188,7 @@ func sortarray(pds []cliv1alpha1.PluginDescriptor) { // the featuregate is configured to true by default func Test_CatalogCacheFileName(t *testing.T) { assert := assert.New(t) - if common.IsContextAwareDiscoveryEnabled { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { assert.Equal(catalogCacheFileName, "catalog.yaml") } } diff --git a/pkg/v1/cli/command/core/plugin_manager.go b/pkg/v1/cli/command/core/plugin_manager.go index 35b8bb76ad..9917d92903 100644 --- a/pkg/v1/cli/command/core/plugin_manager.go +++ b/pkg/v1/cli/command/core/plugin_manager.go @@ -56,7 +56,7 @@ var listPluginCmd = &cobra.Command{ Use: "list", Short: "List available plugins", RunE: func(cmd *cobra.Command, args []string) error { - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { server, err := config.GetCurrentServer() if err != nil { return err @@ -175,7 +175,7 @@ var describePluginCmd = &cobra.Command{ } name := args[0] - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { server, err := config.GetCurrentServer() if err != nil { return err @@ -224,7 +224,7 @@ var installPluginCmd = &cobra.Command{ } name := args[0] - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { server, err := config.GetCurrentServer() if err != nil { return err @@ -267,7 +267,7 @@ var upgradePluginCmd = &cobra.Command{ } name := args[0] - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { return errors.New("context-aware discovery is enabled but function is not yet implemented") } @@ -297,7 +297,7 @@ var deletePluginCmd = &cobra.Command{ } name := args[0] - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { return errors.New("context-aware discovery is enabled but function is not yet implemented") } @@ -311,7 +311,7 @@ var cleanPluginCmd = &cobra.Command{ Use: "clean", Short: "Clean the plugins", RunE: func(cmd *cobra.Command, args []string) (err error) { - if config.IsContextAwareDiscoveryEnabled() { + if config.IsFeatureActivated(config.FeatureContextAwareDiscovery) { return errors.New("context-aware discovery is enabled but function is not yet implemented") } diff --git a/pkg/v1/config/clientconfig.go b/pkg/v1/config/clientconfig.go index dde24a8aa6..c7a65f68cb 100644 --- a/pkg/v1/config/clientconfig.go +++ b/pkg/v1/config/clientconfig.go @@ -15,7 +15,14 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer/json" configv1alpha1 "github.com/vmware-tanzu/tanzu-framework/apis/config/v1alpha1" - "github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/common" +) + +// This block is for global feature constants, to allow them to be used more broadly +const ( + // FeatureContextAwareDiscovery determines whether to use legacy way of discovering plugins or + // to use the new context-aware Plugin API based plugin discovery mechanism + // Users can set this featureflag so that we can have context-aware plugin discovery be opt-in for now. + FeatureContextAwareDiscovery = "features.global.context-aware-discovery" ) // DefaultCliFeatureFlags is used to populate an initially empty config file with default values for feature flags. @@ -25,8 +32,8 @@ import ( // will fail. Note that "global" is a special value for to be used for CLI-wide features. var ( DefaultCliFeatureFlags = map[string]bool{ + FeatureContextAwareDiscovery: false, "features.management-cluster.import": false, - "features.global.use-context-aware-discovery": common.IsContextAwareDiscoveryEnabled, "features.management-cluster.export-from-config": true, } ) @@ -472,17 +479,14 @@ func EndpointFromServer(s *configv1alpha1.Server) (endpoint string, err error) { } } -// IsContextAwareDiscoveryEnabled returns true if context-aware discovery is enabled -// User can set this CLI feature flag using `tanzu config set features.global.use-context-aware-discovery true` -// This determines whether to use legacy way of discovering plugins or -// to use the new context-aware Plugin API based plugin discovery mechanism -// Users can set this featureflag so that we can have context-aware plugin discovery be opt-in for now. -func IsContextAwareDiscoveryEnabled() bool { +// IsFeatureActivated returns true if the given feature is activated +// User can set this CLI feature flag using `tanzu config set features.global. true` +func IsFeatureActivated(feature string) bool { cfg, err := GetClientConfig() if err != nil { return false } - status, err := cfg.IsConfigFeatureActivated("features.global.use-context-aware-discovery") + status, err := cfg.IsConfigFeatureActivated(feature) if err != nil { return false }