vmware-tanzu / tanzu-cli

The Tanzu Core CLI project provides the core functionality of the Tanzu CLI. The CLI is based on a plugin architecture where CLI command functionality can be delivered through independently developed plugin binaries
Apache License 2.0
33 stars 22 forks source link

Perform a catalog initialization if needed #738

Closed marckhouzam closed 4 months ago

marckhouzam commented 5 months ago

This will need to be updated for the changes of https://github.com/vmware-tanzu/tanzu-plugin-runtime/pull/177

What this PR does / why we need it

If the last executed CLI version is < 1.3.0, we refresh some of the catalog data to make sure all the command remapping data is properly stored.

The commit also stores the last executed CLI version in the datastore to make it available for future use.

E2E tests are missing but we may need to merge this before they are done if we want this PR for v1.3.0-alpha.3

Which issue(s) this PR fixes

Related to #687 and #736

Describe testing done for PR

# Install a plugin that uses command mapping using an old CLI
$ ~/bin/tanzu.v1.2.0 plugin install appsv2
[i] Reinitialized plugin 'appsv2:v0.2.0-beta.3' with target 'kubernetes'
[ok] successfully installed 'appsv2' plugin

# Use the new CLI and notice that at the start it shows `appsv2` as a command
# Note that the help does not trigger the global initializer which will fix this
$ tz -h
Usage:
  tanzu [command]

Available command groups:

  Build
    apps                    Applications on Kubernetes
    appsv2                  Applications on Kubernetes for TAP (SaaS distribution)
[...]

# Now run pretty much any command with the new CLI
# and notice the global initializer
$ tz plugin list
Some initialization of the CLI is required.
Let's set things up for you.  This will just take a few seconds.

Refreshing plugin accelerator...
Refreshing plugin apps...
Refreshing plugin appsv2...
Refreshing plugin build-service...
Refreshing plugin external-secrets...
Refreshing plugin insight...
Refreshing plugin package...
Refreshing plugin secret...
Refreshing plugin services...
Refreshing plugin supplychain...
Refreshing plugin telemetry...

Initialization done!
==
  NAME              DESCRIPTION                                                      TARGET      INSTALLED      STATUS
  accelerator       Manage accelerators in a Kubernetes cluster                      kubernetes  v1.7.0         installed
  apps              Applications on Kubernetes                                       kubernetes  v0.13.0        installed
  appsv2            Applications on Kubernetes for TAP (SaaS distribution)           kubernetes  v0.2.0-beta.3  installed
  build-service     plugin to interact with tanzu build service (tbs) crds           kubernetes  v1.0.0         installed
  external-secrets  interacts with external-secrets.io resources                     kubernetes  v0.1.0         installed
  insight           post & query image, package, source, and vulnerability data      kubernetes  v1.7.0         installed
  package           tanzu package management                                         kubernetes  v0.32.1        installed
  secret            Tanzu secret management                                          kubernetes  v0.32.0        installed
  services          Commands for working with service instances, classes and claims  kubernetes  v0.8.0         installed
  supplychain       supplychain management                                           kubernetes  v0.1.0-beta.3  installed
  telemetry         configure cluster-wide settings for vmware tanzu telemetry       global      v1.1.0         installed

# Now try the help again and notice `appsv2` no longer shows
$ tz -h
Usage:
  tanzu [command]

Available command groups:

  Build
    app                     Applications on Kubernetes for TAP (SaaS distribution)
    build-service           plugin to interact with tanzu build service (tbs) crds
[...]

Release note

Add a global initializer to ensure the command-remapping information is properly stored in the catalog cache.

Additional information

Special notes for your reviewer