Skip to content

Commit

Permalink
Cleanup pluginmanager of unused feature flag code (#484)
Browse files Browse the repository at this point in the history
This commit removes all the unused code around feature flags from the
`manager.go` file.  Those changes are:
1. Remove `ValidatePlugin()` which was never used.  There is a
   separate copy of this function in the tanzu-plugin-runtime repository.
2. Remove `discoverPlugins()` and directly use `discoverSpecificPlugins()`
3. Remove `discoverServerPluginsBasedOnCurrentServer` which is no longer
   used.
4. Include the logic of `discoverServerPluginsBasedOnAllCurrentContexts()`
   directly into `DiscoverServerPlugins()` which had become a one-liner.
5. Remove the following functions that were no longer used:
      - `AvailablePlugins()`
      - `AvailablePluginsFromLocalSource()`
      - `availablePlugins()`
      - `combineDuplicatePlugins()`
      - `getInstalledButNotDiscoveredStandalonePlugins()`
      - `DiscoveredFromPlugininfo()`
      - `availablePluginsFromStandaloneAndServerPlugins()`
      - `pluginIndexForName()`
      - `legacyPluginInstall()`
      - `GetRecommendedVersionOfPlugin()`

Completely remove the feature flag constant:
  FeatureDisableCentralRepositoryForTesting

* Update the unit tests for the plugin manager.

This commit improves our ability to test the pluginmanager.
It does this using two techniques:

1. Creating a test plugin inventory DB in the cache and requesting the
   inventory code to always use the cache (without checking the digest).
   To force the use of the cache the commit introduces a test variable
   `TEST_TANZU_CLI_USE_DB_CACHE_ONLY`.
   This approach allows to discover plugins and groups without needing
   a real OCI registry.

2. Creating "fake" plugin binaries in the plugin binary cache.  This
   allows installation of plugins to find the binaries in the cache and
   therefore never have to go to an OCI registry to download them.

With these two techniques, the unit tests can discovery and install
plugins, and can also do so using groups.  The plugin sync can also be
tested with this.

Note: the unit tests would still benefit from some tests moving to this
approach of testing, but this will need to come in a future effort.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam authored Sep 20, 2023
1 parent 7796f79 commit c0e6210
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
github.com/vmware-tanzu/tanzu-framework/capabilities/client v0.0.0-20230523145612-1c6fbba34686
github.com/vmware-tanzu/tanzu-plugin-runtime v1.0.0
go.pinniped.dev v0.20.0
go.uber.org/multierr v1.11.0
golang.org/x/mod v0.10.0
golang.org/x/oauth2 v0.8.0
golang.org/x/sync v0.2.0
Expand Down Expand Up @@ -212,6 +211,7 @@ require (
go.opentelemetry.io/otel v1.15.0 // indirect
go.opentelemetry.io/otel/trace v1.15.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
Expand Down
2 changes: 0 additions & 2 deletions pkg/constants/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package constants
const (
// FeatureContextCommand determines whether to surface the context command. This is disabled by default.
FeatureContextCommand = "features.global.context-target-v2"
// FeatureDisableCentralRepositoryForTesting determines if the CLI uses the Central Repository of plugins.
FeatureDisableCentralRepositoryForTesting = "features.global.no-central-repo-test-only"
)

// DefaultCliFeatureFlags is used to populate an initially empty config file with default values for feature flags.
Expand Down
10 changes: 10 additions & 0 deletions pkg/discovery/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package discovery

import (
"os"
"path"
"path/filepath"
"strconv"

"github.com/vmware-tanzu/tanzu-cli/pkg/common"
"github.com/vmware-tanzu/tanzu-cli/pkg/plugininventory"
Expand All @@ -22,6 +24,10 @@ func NewOCIDiscovery(name, image string, options ...DiscoveryOptions) Discovery
discovery := newDBBackedOCIDiscovery(name, image)
discovery.pluginCriteria = opts.PluginDiscoveryCriteria
discovery.useLocalCacheOnly = opts.UseLocalCacheOnly
// NOTE: the use of TEST_TANZU_CLI_USE_DB_CACHE_ONLY is for testing only
if useCacheOnlyForTesting, _ := strconv.ParseBool(os.Getenv("TEST_TANZU_CLI_USE_DB_CACHE_ONLY")); useCacheOnlyForTesting {
discovery.useLocalCacheOnly = true
}
return discovery
}

Expand All @@ -36,6 +42,10 @@ func NewOCIGroupDiscovery(name, image string, options ...DiscoveryOptions) Group
discovery := newDBBackedOCIDiscovery(name, image)
discovery.groupCriteria = opts.GroupDiscoveryCriteria
discovery.useLocalCacheOnly = opts.UseLocalCacheOnly
// NOTE: the use of TEST_TANZU_CLI_USE_DB_CACHE_ONLY is for testing only
if useCacheOnlyForTesting, _ := strconv.ParseBool(os.Getenv("TEST_TANZU_CLI_USE_DB_CACHE_ONLY")); useCacheOnlyForTesting {
discovery.useLocalCacheOnly = true
}

return discovery
}
Expand Down
Loading

0 comments on commit c0e6210

Please sign in to comment.