Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Tweaks ContextAwareDiscovery to allow more generic feature flags to u…
Browse files Browse the repository at this point in the history
…se methods (#951)
  • Loading branch information
swalner-vmware authored Oct 22, 2021
1 parent 5fa351d commit b519163
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pkg/v1/cli/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
}
12 changes: 6 additions & 6 deletions pkg/v1/cli/command/core/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand Down
22 changes: 13 additions & 9 deletions pkg/v1/config/clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,8 +32,8 @@ import (
// will fail. Note that "global" is a special value for <plugin> 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,
}
)
Expand Down Expand Up @@ -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.<feature> 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
}
Expand Down

0 comments on commit b519163

Please sign in to comment.